From 5f10ad127ef738371dc26dab3f6607ca3e546c06 Mon Sep 17 00:00:00 2001 From: Lukas Tiefensee Date: Thu, 21 Feb 2019 11:30:31 +0100 Subject: [PATCH 1/3] added try-catch around JSON.parse() to prevent homebridge from crashing from an uncaught SyntaxError --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 909a988..7c265c7 100644 --- a/index.js +++ b/index.js @@ -243,7 +243,13 @@ 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); + // should execute ´if (!parsed)´ block below + } if (responseBodyParsed && responseBodyParsed.powerstate) { if (responseBodyParsed.powerstate == "On") { tResp = that.powerstateOnConnect; From b6371465ef8095f1ff0355eadc504bf5bb9a58b4 Mon Sep 17 00:00:00 2001 From: Lukas Tiefensee Date: Thu, 21 Feb 2019 11:39:22 +0100 Subject: [PATCH 2/3] added port option to config.json --- README.md | 13 +++++++++++++ index.js | 9 +++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9ab193e..130de38 100644 --- a/README.md +++ b/README.md @@ -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" + } +] + ``` diff --git a/index.js b/index.js index 7c265c7..6109d79 100644 --- a/index.js +++ b/index.js @@ -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"; @@ -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 = { From eb63a3cd662721a36505be9c64d9c0c05292b6e5 Mon Sep 17 00:00:00 2001 From: Lukas <37399744+Lukcyluke@users.noreply.github.com> Date: Thu, 7 Mar 2019 23:38:13 +0100 Subject: [PATCH 3/3] fixed bug for gw-wiscon/homebridge-philipstv#8 --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 6109d79..555d3cb 100644 --- a/index.js +++ b/index.js @@ -249,6 +249,7 @@ getPowerState: function(callback, context) { responseBodyParsed = JSON.parse(responseBody); } catch (error) { that.log(error.message); + responseBodyParsed = false; // should execute ´if (!parsed)´ block below } if (responseBodyParsed && responseBodyParsed.powerstate) {