I’m a bit confused how to properly update a channel state in my binding, maybe some of you experts can help me to do that right
The binding communicates to a wifi device via simple UDP messages.
The device has 3 or 8 relays which may be switched on and off, if they are not locked.
My ThingHandler has an internal state which caches the state of each relay (and whether they are locked or not).
On Thing initialization, I request the states of all relays from the device and store them in the internal state.
If the device changes the state, the ThingHandler gets notified via a UDP message, updates its internal state, and calls
That works fine, the linked items are updated.
If the ThingHandler receives a command to change the state (let’s say from OFF to ON), I’m not sure how to proceed correctly.
There are two cases:
- The relay is not locked.
- Then the ThingHandler sends a UDP message to the device to switch the relay on.
- The internal state is unset because we are waiting for a response from the device whether or not switching the relay was successful.
- If I understand it correctly, the default autoupdate behavior automatically changes the linked item states to ON?
- As soon as the ThingHandler receives the confirmation from the device, the internal state for that relay can be set to ON and the channel state can also be updated to ON. (which has no effect because autoupdate already set the state to ON, right?)
- The relay is locked.
- Then the ThingHandler should not send anything to the device but it should, simply speaking, reject this command. That is, the channel state should remain OFF.
- However, autoupdate still changes the linked item states to ON, right?
- I tried to
updateState(channelUid, OFF), but it does not work. The linked item is still updated to ON.
- I tried it async:
scheduler.execute(() -> updateState(channelUid, OFF)), but the linked item is still updated to ON.
How should a ThingHandler properly update the channel in such cases?
Btw, because of the fact that relays may be locked, I set the channel’s autoUpdatePolicy to ‘veto’.
It that the intended configuration for this scenario?
How does that affect how the ThingHandler should react on commands and set channel states?