Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It seems that via wink-js we are not receiving the expected "desired_state", except for when it's been applied (see winfinit/wink-js#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 #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.