Skip to content

Commit

Permalink
🐛 Fixed issue where init of client would fail without credentials
Browse files Browse the repository at this point in the history
🎨 Refactor getting of mac address to `network/devices` call
🐛 Fix bug in pairing process for tv which do not have the `notifychange` endpoint
  • Loading branch information
lucasvdh committed Jun 5, 2019
1 parent 20a4efa commit 7d6dbb5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
13 changes: 12 additions & 1 deletion drivers/philips-jointspace/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ class PhilipsTV extends Homey.Device {
this._settings = this.getSettings();

this.client = new JointspaceClient(this.getCredentials().user);
this.client.setConfig(this.getIPAddress(), this.getAPIVersion(), this.getCredentials().user, this.getCredentials().pass);

if (this.hasCredentials()) {
this.client.setConfig(this.getIPAddress(), this.getAPIVersion(), this.getCredentials().user, this.getCredentials().pass);
} else {
this.client.setConfig(this.getIPAddress(), this.getAPIVersion());
}

this.log('PhilipsTV Device [' + this.getCredentials().user + '] initialized');

Expand Down Expand Up @@ -76,6 +81,12 @@ class PhilipsTV extends Homey.Device {
return this._data.credentials;
}

hasCredentials() {
return this._data.credentials !== null
&& (typeof this._data.credentials.user !== "undefined")
&& this._data.credentials.user !== null;
}

updateDevice() {
this.client.getInfo().then((response) => {
this.setCapabilityValue('onoff', (response.powerstate.powerstate === 'On'))
Expand Down
16 changes: 8 additions & 8 deletions drivers/philips-jointspace/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,22 @@ class PhilipsJointSpaceDriver extends Homey.Driver {
});

socket.on('verify_wol', (data, callback) => {
this.jointspaceClient.getInfo().then((response) => {
if (typeof response['network/devices'] !== "undefined") {
for (let i in response['network/devices']) {
let networkAdapter = response['network/devices'][i];
this.jointspaceClient.getNetworkDevices().then((networkDevices) => {
if (Array.isArray(networkDevices)) {
for (let i in networkDevices) {
let networkDevice = networkDevices[i];

if (typeof networkAdapter['wake-on-lan'] !== "undefined" && networkAdapter['wake-on-lan'] === 'Enabled') {
pairingDevice.data.mac = networkAdapter["mac"];
if (typeof networkDevice['wake-on-lan'] !== "undefined" && networkDevice['wake-on-lan'] === 'Enabled') {
pairingDevice.data.mac = networkDevice["mac"];
callback(null, true);
break;
}
}
} else {
this.error('Could not get mac address from tv device')
console.log('Could not get mac address from tv', JSON.stringify(networkDevices));
callback(null, false);
}

callback(null, false);
}).catch((error) => {
callback(null, false);
this.error(error);
Expand Down
4 changes: 4 additions & 0 deletions lib/JointspaceClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ class JointspaceClient {
});
}

getNetworkDevices() {
return this.request('network/devices', 'GET');
}

getPowerState() {
return this.request('powerstate', 'GET');
}
Expand Down

0 comments on commit 7d6dbb5

Please sign in to comment.