Sroose / homebridge-loxone-ws

Websocket based Loxone plugin for homebridge
MIT License
39 stars 26 forks source link

Fix bug in DimmerItem that tries to getItemState before connection established #28

Closed Nexus2k closed 6 years ago

Nexus2k commented 6 years ago

Plus update to latest node-lox-ws-api and switch to Token-Enc Auth.

WolfMa99 commented 6 years ago

Still with the changes it throws the same error. Any ideas?

Nexus2k commented 6 years ago

Can you post the full error message?

WolfMa99 commented 6 years ago

`[2018-02-08 10:58:31] [Loxone] [dimmer] iOS - send brightness message to Master-Helligkeit of Lichtsteuerung in Kinderzimmer: 0 /opt/node/lib/node_modules/homebridge-loxone-ws/node_modules/node-lox-ws-api/lib/API.js:190 this.connection.send(this._auth.prepare_control_command(control, command)); ^

TypeError: Cannot read property 'prepare_control_command' of undefined at API.send_control_command (/opt/node/lib/node_modules/homebridge-loxone-ws/node_modules/node-lox-ws-api/lib/API.js:190:36) at API.send_cmd (/opt/node/lib/node_modules/homebridge-loxone-ws/node_modules/node-lox-ws-api/lib/API.js:203:10) at WSListener.sendCommand (/opt/node/lib/node_modules/homebridge-loxone-ws/libs/WSListener.js:113:13) at DimmerItem.setItemState (/opt/node/lib/node_modules/homebridge-loxone-ws/items/DimmerItem.js:95:22) at emitMany (events.js:127:13) at emit (events.js:201:7) at Characteristic.setValue (/opt/node/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Characteristic.js:311:10) at DimmerItem.getOtherServices (/opt/node/lib/node_modules/homebridge-loxone-ws/items/DimmerItem.js:54:10) at DimmerItem.AbstractItem.getServices (/opt/node/lib/node_modules/homebridge-loxone-ws/items/AbstractItem.js:30:30) at Server._createAccessory (/opt/node/lib/node_modules/homebridge/lib/server.js:388:36)`

Nexus2k commented 6 years ago

I've added the same fix to the setItemState function, you might want to pull the latest version and try again.

WolfMa99 commented 6 years ago

Now it throws:

[2018-02-08 11:29:05] [Loxone] [dimmer] iOS - send brightness message to Master-Helligkeit of Lichtsteuerung in Kinderzimmer: 0 /opt/node/lib/node_modules/homebridge-loxone-ws/items/DimmerItem.js:95 if (this.platform.ws.is_connected()) { ^

TypeError: this.platform.ws.is_connected is not a function at DimmerItem.setItemState (/opt/node/lib/node_modules/homebridge-loxone-ws/items/DimmerItem.js:95:26) at emitMany (events.js:127:13) at emit (events.js:201:7) at Characteristic.setValue (/opt/node/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Characteristic.js:311:10) at DimmerItem.getOtherServices (/opt/node/lib/node_modules/homebridge-loxone-ws/items/DimmerItem.js:54:10) at DimmerItem.AbstractItem.getServices (/opt/node/lib/node_modules/homebridge-loxone-ws/items/AbstractItem.js:30:30) at Server._createAccessory (/opt/node/lib/node_modules/homebridge/lib/server.js:388:36) at Server. (/opt/node/lib/node_modules/homebridge/lib/server.js:374:32) at /opt/node/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/once.js:16:19 at Request._callback (/opt/node/lib/node_modules/homebridge-loxone-ws/index.js:67:13)

Nexus2k commented 6 years ago

Hmmm... Very strange, sounds like the WebSocket is not connected at this point. I added another check for that. I do however currently expect that the login credentials are wrong.

WolfMa99 commented 6 years ago

it throws again the same error, but I think the credentials are right because it connects and see everything

in WSListener.js I found var WSListener = function(platform) { this.ws = undefined;

WolfMa99 commented 6 years ago

I could solve the problem by setting if (this.connection !== undefined) { this.platform.ws.sendCommand(this.uuidAction, command); } I can control now from Home in iOS the color and brightness, but always show the old state, after I click on it, it changes to the new one. I hope you can help me with that.

Nexus2k commented 6 years ago

this.connection will always be undefined as it doesn't exist, the idea is to check if the this.platform.ws object is already assigned which indicates that it's connected.

WolfMa99 commented 6 years ago

How to achieve that? Because for now I can control over HomeKit the color and so.

Nexus2k commented 6 years ago
if (this.platform.ws !== undefined) {
  this.platform.ws.sendCommand(this.uuidAction, command);
}

might work

WolfMa99 commented 6 years ago

This throws the error from the beginning:

/opt/node/lib/node_modules/homebridge-loxone-ws/node_modules/node-lox-ws-api/lib/API.js:190 this.connection.send(this._auth.prepare_control_command(control, command)); ^

TypeError: Cannot read property 'prepare_control_command' of undefined at API.send_control_command (/opt/node/lib/node_modules/homebridge-loxone-ws/node_modules/node-lox-ws-api/lib/API.js:190:36) at API.send_cmd (/opt/node/lib/node_modules/homebridge-loxone-ws/node_modules/node-lox-ws-api/lib/API.js:203:10) at WSListener.sendCommand (/opt/node/lib/node_modules/homebridge-loxone-ws/libs/WSListener.js:113:13) at DimmerItem.setItemState (/opt/node/lib/node_modules/homebridge-loxone-ws/items/DimmerItem.js:96:24) at emitMany (events.js:127:13) at emit (events.js:201:7) at Characteristic.setValue (/opt/node/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Characteristic.js:311:10) at DimmerItem.getOtherServices (/opt/node/lib/node_modules/homebridge-loxone-ws/items/DimmerItem.js:54:10) at DimmerItem.AbstractItem.getServices (/opt/node/lib/node_modules/homebridge-loxone-ws/items/AbstractItem.js:30:30) at Server._createAccessory (/opt/node/lib/node_modules/homebridge/lib/server.js:388:36)

WolfMa99 commented 6 years ago

Hey, Do you have now Andy idea? How to fix the problem? Shall i try a new and Fresh Installation?

chiefjoejj commented 6 years ago

I have the same problem - I guess. When adding one (or more) "light controller(s)" with at least one dimmer the loxone-plugin forces the homebridge to stop.

Thats what the terminal shows:

[2018-2-24 13:58:27] Homebridge is running on port 51826. /usr/lib/node_modules/homebridge-loxone-ws/libs/WSListener.js:44 throw new Error("LOXONE WS: connection error"); ^

Error: LOXONE WS: connection error at API. (/usr/lib/node_modules/homebridge-loxone-ws/libs/WSListener.js:44:14) at API.emit (events.js:127:13) at Connection. (/usr/lib/node_modules/homebridge-loxone-ws/node_modules/node-lox-ws-api/lib/API.js:98:14) at Connection.emit (events.js:127:13) at WebSocketConnection. (/usr/lib/node_modules/homebridge-loxone-ws/node_modules/node-lox-ws-api/lib/Connection.js:99:14) at WebSocketConnection.emit (events.js:127:13) at WebSocketConnection.handleSocketError (/usr/lib/node_modules/homebridge-loxone-ws/node_modules/websocket/lib/WebSocketConnection.js:347:14) at Socket.emit (events.js:127:13) at Socket.writeAfterFIN [as write] (net.js:374:8) at WebSocketConnection.sendFrame (/usr/lib/node_modules/homebridge-loxone-ws/node_modules/websocket/lib/WebSocketConnection.js:857:31)

When I hide all light controllers with dimmers from my homebridge user within Loxone all works great. Hope somebody can help.

Cheers Jay