Fix non-thread-safe state write in tellduslive (#117487)

This commit is contained in:
J. Nick Koston 2024-05-15 19:08:24 +09:00 committed by GitHub
parent e286621f93
commit 37c55d81e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 21 deletions

View File

@ -24,7 +24,6 @@ SCAN_INTERVAL = timedelta(minutes=1)
ATTR_LAST_UPDATED = "time_last_updated"
SIGNAL_UPDATE_ENTITY = "tellduslive_update"
TELLDUS_DISCOVERY_NEW = "telldus_new_{}_{}"
CLOUD_NAME = "Cloud API"

View File

@ -46,14 +46,14 @@ class TelldusLiveCover(TelldusLiveEntity, CoverEntity):
def close_cover(self, **kwargs: Any) -> None:
"""Close the cover."""
self.device.down()
self._update_callback()
self.schedule_update_ha_state()
def open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
self.device.up()
self._update_callback()
self.schedule_update_ha_state()
def stop_cover(self, **kwargs: Any) -> None:
"""Stop the cover."""
self.device.stop()
self._update_callback()
self.schedule_update_ha_state()

View File

@ -11,7 +11,6 @@ from homeassistant.const import (
ATTR_MODEL,
ATTR_VIA_DEVICE,
)
from homeassistant.core import callback
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity
@ -33,25 +32,16 @@ class TelldusLiveEntity(Entity):
"""Initialize the entity."""
self._id = device_id
self._client = client
self._async_unsub_dispatcher_connect = None
async def async_added_to_hass(self):
"""Call when entity is added to hass."""
_LOGGER.debug("Created device %s", self)
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
self.hass, SIGNAL_UPDATE_ENTITY, self._update_callback
self.async_on_remove(
async_dispatcher_connect(
self.hass, SIGNAL_UPDATE_ENTITY, self.async_write_ha_state
)
)
async def async_will_remove_from_hass(self):
"""Disconnect dispatcher listener when removed."""
if self._async_unsub_dispatcher_connect:
self._async_unsub_dispatcher_connect()
@callback
def _update_callback(self):
"""Return the property of the device might have changed."""
self.async_write_ha_state()
@property
def device_id(self):
"""Return the id of the device."""

View File

@ -50,7 +50,7 @@ class TelldusLiveLight(TelldusLiveEntity, LightEntity):
def changed(self):
"""Define a property of the device that might have changed."""
self._last_brightness = self.brightness
self._update_callback()
self.schedule_update_ha_state()
@property
def brightness(self):

View File

@ -45,9 +45,9 @@ class TelldusLiveSwitch(TelldusLiveEntity, SwitchEntity):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on."""
self.device.turn_on()
self._update_callback()
self.schedule_update_ha_state()
def turn_off(self, **kwargs: Any) -> None:
"""Turn the switch off."""
self.device.turn_off()
self._update_callback()
self.schedule_update_ha_state()