Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch SyntaxError in JSON.parse() and add port option #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,16 @@ Added test option for WakeOnWLAN:
}
]
```

Some TVs seem to have Jointspace on port 1926. For this TVs the port can be specified in the config.json like below (optional):
```
"accessories": [
{
"accessory": "PhilipsTV",
"name": "My Philips TV",
"ip_address": "10.0.1.23",
"poll_status_interval": "60",
"port": "1926"
}
]
```
18 changes: 13 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function HttpStatusAccessory(log, config)

// config
this.ip_address = config["ip_address"];
this.port = config["port"] || "1925";
this.name = config["name"];
this.poll_status_interval = config["poll_status_interval"] || "0";
this.model_year = config["model_year"] || "2014";
Expand All @@ -34,12 +35,12 @@ function HttpStatusAccessory(log, config)

this.state = false;
this.interval = parseInt( this.poll_status_interval);
this.on_url = "http://"+this.ip_address+":1925/"+this.api_version+"/powerstate";
this.on_url = "http://"+this.ip_address+":"+this.port+"/"+this.api_version+"/powerstate";
this.on_body = JSON.stringify({"powerstate":"On"});
this.off_url = "http://"+this.ip_address+":1925/"+this.api_version+"/powerstate";
this.off_url = "http://"+this.ip_address+":"+this.port+"/"+this.api_version+"/powerstate";
this.off_body = JSON.stringify({"powerstate":"Standby"});
this.status_url = "http://"+this.ip_address+":1925/"+this.api_version+"/powerstate";
this.info_url = "http://"+this.ip_address+":1925/"+this.api_version+"/system";
this.status_url = "http://"+this.ip_address+":"+this.port+"/"+this.api_version+"/powerstate";
this.info_url = "http://"+this.ip_address+":"+this.port+"/"+this.api_version+"/system";
this.powerstateOnError = "0";
this.powerstateOnConnect = "1";
this.info = {
Expand Down Expand Up @@ -243,7 +244,14 @@ getPowerState: function(callback, context) {
} else {
var parsed = false;
if (responseBody) {
var responseBodyParsed = JSON.parse( responseBody);
var responseBodyParsed;
try {
responseBodyParsed = JSON.parse(responseBody);
} catch (error) {
that.log(error.message);
responseBodyParsed = false;
// should execute ´if (!parsed)´ block below
}
if (responseBodyParsed && responseBodyParsed.powerstate) {
if (responseBodyParsed.powerstate == "On") {
tResp = that.powerstateOnConnect;
Expand Down