KraigM / homebridge-wink

Wink hub plugin for HomeBridge
54 stars 37 forks source link

Brightness / Dimness settings fixes #75

Open scoobyshi opened 7 years ago

scoobyshi commented 7 years ago

It seems that via wink-js we are not receiving the expected "desired_state", except for when it's been applied (see https://github.com/winfinit/wink-js/issues/12). Thus, any checks for this will error out incorrectly. While I can see this node typically populated if I query the API directly (eg via Postman), I don't see it returning data via wink-js. I would say the problem is there except that in the Wink documentation for the API it specifically mentions this should be expected "http://docs.winkapiv2.apiary.io/#reference/device/desired-state-and-last-reading/retrieve-all-devices-of-user": "When the device acknowledges that the state has been applied, the server will clear the field from desired_state."

Granted, that is the v2 documentation, and the v1 API specifically states that desired_state will describe writeable states, I suspect Wink has perhaps deprecated that behaviour.

As a result, the checks in accessories/light_bulbs.js result in no brightness characters being set (see https://github.com/KraigM/homebridge-wink/issues/61); However, if we check last_reading, it does get set correctly. I tried this with numerous bulbs and switches (Lutron switch, Ecosmart A19 Bulb, Par20 Pot lights).

Also, due to the same concern with desired_state, when we're checking for whether to retry or not (in lib/wink_accessory.js), based on the behaviour I've been observing and the updated Wink documentation, it seems we should be checking for the absence of desired_state properties, since they get cleared once applied. Otherwise, desired_state.powered (for example) will never equal last_reading.powered... which was the behaviour we observed.

Once I applied the changes in this optional patch, the behaviour seemed much more consistent with how it likely behaved previously.

ckdake commented 7 years ago

+1 on this working correctly.

scoobyshi commented 7 years ago

Any chance of this being merged or reviewed?