@@ -189,7 +189,8 @@ async def async_will_remove_from_hass(self) -> None:
189189
190190 def handle_event (self , event ):
191191 self ._state = event .data .get ('value' )
192- self .hass .async_create_task (self .async_write_ha_state ())
192+ if self .hass :
193+ self .hass .loop .call_soon_threadsafe (self .async_schedule_update_ha_state )
193194
194195 @property
195196 def device_info (self ) -> DeviceInfo :
@@ -242,7 +243,8 @@ async def async_will_remove_from_hass(self) -> None:
242243
243244 def handle_event (self , event ):
244245 self ._state = event .data .get ('value' )
245- self .hass .async_create_task (self .async_write_ha_state ())
246+ if self .hass :
247+ self .hass .loop .call_soon_threadsafe (self .async_schedule_update_ha_state )
246248
247249 @property
248250 def device_info (self ) -> DeviceInfo :
@@ -290,7 +292,8 @@ async def async_will_remove_from_hass(self) -> None:
290292
291293 def handle_event (self , event ):
292294 self ._state = event .data .get ('value' )
293- self .hass .async_create_task (self .async_write_ha_state ())
295+ if self .hass :
296+ self .hass .loop .call_soon_threadsafe (self .async_schedule_update_ha_state )
294297
295298 @property
296299 def device_info (self ) -> DeviceInfo :
@@ -335,7 +338,8 @@ async def async_will_remove_from_hass(self) -> None:
335338
336339 def handle_event (self , event ):
337340 self ._state = event .data .get ('value' )
338- self .hass .async_create_task (self .async_write_ha_state ())
341+ if self .hass :
342+ self .hass .loop .call_soon_threadsafe (self .async_schedule_update_ha_state )
339343
340344 @property
341345 def device_info (self ) -> DeviceInfo :
@@ -379,7 +383,8 @@ async def async_will_remove_from_hass(self) -> None:
379383
380384 def handle_event (self , event ):
381385 self ._state = event .data .get ('text' )
382- self .hass .async_create_task (self .async_write_ha_state ())
386+ if self .hass :
387+ self .hass .loop .call_soon_threadsafe (self .async_schedule_update_ha_state )
383388
384389 @property
385390 def device_info (self ) -> DeviceInfo :
0 commit comments