NorthernMan54 / node-red-contrib-homebridge-automation

Homebridge and Node-RED Integration
Apache License 2.0
107 stars 18 forks source link

New status reporting logic breaks event nodes? #70

Closed thiete closed 3 years ago

thiete commented 3 years ago

Updating from 0.0.73 to 0.0.76 breaks my Event nodes. I'm pretty sure the breaking change is related to commit 30c5c07642fb258f7a8df87fb31a8e1f281cdc89.

The Event node still registers the event - it shows a red status dot below the node with a " Disconnected: 0" or "Disconnected: 1" status text, where the previous version shows a green dot with {"On": 0} or {"On": 1}. The new version does not emit an actual node-red message. Here are two log snippets for events firing:

0.0.73:

Nov 15 10:42:31 MikeServer Node-RED[14446]: 2020-11-15T09:42:31.833Z hapNodeJSClient Events [{"host":"192.168.0.10","port":51883,"deviceID":"0E:E6:A9:CF:5A:55","aid":32,"iid":26,"value":1,"status":1}]
Nov 15 10:42:31 MikeServer Node-RED[14446]: 2020-11-15T09:42:31.834Z hapNodeRed hbEvent Clean Living Room {
Nov 15 10:42:31 MikeServer Node-RED[14446]:   host: '192.168.0.10',
Nov 15 10:42:31 MikeServer Node-RED[14446]:   port: 51883,
Nov 15 10:42:31 MikeServer Node-RED[14446]:   deviceID: '0E:E6:A9:CF:5A:55',
Nov 15 10:42:31 MikeServer Node-RED[14446]:   aid: 32,
Nov 15 10:42:31 MikeServer Node-RED[14446]:   iid: 26,
Nov 15 10:42:31 MikeServer Node-RED[14446]:   value: 1,
Nov 15 10:42:31 MikeServer Node-RED[14446]:   status: 1
Nov 15 10:42:31 MikeServer Node-RED[14446]: } { On: 0 }

0.0.76:

Nov 15 10:44:57 MikeServer Node-RED[17096]: 2020-11-15T09:44:57.979Z hapNodeJSClient Events [{"host":"192.168.0.10","port":51883,"deviceID":"0E:E6:A9:CF:5A:55","aid":32,"iid":26,"value":1,"status":1}]
Nov 15 10:44:57 MikeServer Node-RED[17096]: 2020-11-15T09:44:57.979Z hapNodeRed hbEvent Clean Living Room {
Nov 15 10:44:57 MikeServer Node-RED[17096]:   host: '192.168.0.10',
Nov 15 10:44:57 MikeServer Node-RED[17096]:   port: 51883,
Nov 15 10:44:57 MikeServer Node-RED[17096]:   deviceID: '0E:E6:A9:CF:5A:55',
Nov 15 10:44:57 MikeServer Node-RED[17096]:   aid: 32,
Nov 15 10:44:57 MikeServer Node-RED[17096]:   iid: 26,
Nov 15 10:44:57 MikeServer Node-RED[17096]:   value: 1,
Nov 15 10:44:57 MikeServer Node-RED[17096]:   status: 1
Nov 15 10:44:57 MikeServer Node-RED[17096]: } { On: 0 }

And some debug logs where I started node-red with the two versions of the plugin, and then toggled my "Clean Living Room" switch several times: Node-RED_0073.log Node-RED_0076.log

thiete commented 3 years ago

I should note, I am using homebridge v1.3.0-beta.24

Is it that you are using strict boolean comparisons:if (event.status === true && event.value !== undefined) while the events contain an integer "status": 1, which evaluates as false?

EDIT: Changing to if (event.status == true && event.value !== undefined) makes switch-on events fire but switch-off events still do not fire :) It seems like node-red-hb-automation expects the 'status' to be true if the status request was successfully completed, while it seems currently "status" == "value" == the state of the switch?

NorthernMan54 commented 3 years ago

Tks for discovering this issue.

Under the covers I had made a change to hap-node-client to have status be the connectivity status of the device. But for some reason that is missing, give me a couple of hours to fix things.

NorthernMan54 commented 3 years ago

If you update to the latest, it should be good. When I promoted the change, I had missed including the newer version of hap-node-client, and this version includes that as a dependancy

The working version is v0.0.77

thiete commented 3 years ago

Yep, seems to be fine now! Thank you!