jnimmo / hass-dmx

Home Assistant DMX over IP Integration
MIT License
107 stars 46 forks source link

Restoring the previous value does not work properly for lights off #61

Open sapdemon opened 2 years ago

sapdemon commented 2 years ago

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
            )
        )
hypnosiss commented 2 years ago

after code update my lights behave strange - turning on two lights in the same time gives only one light flashing, but after turning another light (third one) missing one start to flash. I am not sure, but probably issue opened by sapdemon have connection with my problem.