-
Notifications
You must be signed in to change notification settings - Fork 45
Restoring the previous value does not work properly for lights off #61
Description
Home Assistant 2021.11.1
Component Version 0.1.4
The logs:
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX state restored: 1 <- 13
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX entity brightness restored: 1 <- 13
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX state restored: 2 <- 13
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX entity brightness restored: 2 <- 13
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX state restored: 3 <- 13
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX entity brightness restored: 3 <- 13
....
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX state restored: 1 <- 133
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX entity brightness restored: 1 <- 0
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX state restored: 2 <- 164
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX entity brightness restored: 2 <- 0
....
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX state restored: 10 <- 255
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX entity brightness restored: 10 <- 0
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX state restored: 11 <- 255
2021-11-10 18:41:36 DEBUG (MainThread) [custom_components.dmx.light] DMX entity brightness restored: 11 <- 0
So if the light had OFF state before restarting HA it does not take it into consideration during the restore previous status of the entity and set restored dmx_values for this light.
It seems there is a bug in
async def async_added_to_hass(self) -> None:
if old_state.attributes.get("dmx_values"):
old_dmx_values = old_state.attributes.get("dmx_values")
_LOGGER.debug(
f"DMX state restored: {self._channel} <- {str(old_dmx_values)}"
)
_LOGGER.debug(
f"DMX entity brightness restored: {self._channel} <- {str(self._brightness)}"
)
asyncio.ensure_future(
self._dmx_gateway.set_channels_async(
self._channels, old_dmx_values, self._send_when_added
)
)