From ba2ebc730b043f24897a53f5df3c0f61ba76c99e Mon Sep 17 00:00:00 2001 From: Alex X Date: Tue, 13 Feb 2024 07:52:53 +0300 Subject: [PATCH] Fix T5 actions error in some cases #1328 --- custom_components/sonoff/sensor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/custom_components/sonoff/sensor.py b/custom_components/sonoff/sensor.py index 53ce29fa..d0fb75d4 100644 --- a/custom_components/sonoff/sensor.py +++ b/custom_components/sonoff/sensor.py @@ -322,7 +322,8 @@ def set_state(self, params: dict): async def clear_state(self): await asyncio.sleep(0.5) self._attr_native_value = "" - self._async_write_ha_state() + if self.hass: + self._async_write_ha_state() class XT5Action(XEntity, SensorEntity): @@ -346,7 +347,8 @@ def set_state(self, params: dict): async def clear_state(self): await asyncio.sleep(0.5) self._attr_native_value = "" - self._async_write_ha_state() + if self.hass: + self._async_write_ha_state() class XUnknown(XEntity, SensorEntity):