michbeck100 / pimatic-hap

Pimatic homekit bridge
GNU General Public License v2.0
30 stars 10 forks source link

preventing dimming/switching of uninitialized devices and updating th… #48

Closed thexperiments closed 7 years ago

thexperiments commented 7 years ago

…e state/dimLevel when event happens and not only in the constructor

I found out that at the moment the plugin tries to determine if it should switch the state @_state was null and it was only written in the constructor at this point in time. I think it is legit to get the device state on every new set which comes in from homekit and use this for evaluation. In addition to that I think there can be the case that a device still was not yet able to update its internal state if a "set" comes from homekit. We should not switch a device in this state and thus I added a null check.

michbeck100 commented 7 years ago

I'm sorry but i can't accept your PR. The problem is, that is is not legit to get the devices state on every new set event from homekit, because some pimatic plugins set the device state AFTER sending the state change event. This would create an infinite loop. You have to consider that the set event is also triggered during the "device.on 'state' event handling (e.g. https://github.com/thexperiments/pimatic-hap/blob/master/accessories/switch.coffee#L48)