Skip to content

Commit

Permalink
Fix non-thread-safe state write in tellduslive (#117487)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored and frenck committed May 17, 2024
1 parent 970ad8c commit b86513c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
1 change: 0 additions & 1 deletion homeassistant/components/tellduslive/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

ATTR_LAST_UPDATED = "time_last_updated"

SIGNAL_UPDATE_ENTITY = "tellduslive_update"
TELLDUS_DISCOVERY_NEW = "telldus_new_{}_{}"

CLOUD_NAME = "Cloud API"
6 changes: 3 additions & 3 deletions homeassistant/components/tellduslive/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ def is_closed(self) -> bool:
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()
18 changes: 4 additions & 14 deletions homeassistant/components/tellduslive/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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
Expand All @@ -33,25 +32,16 @@ def __init__(self, client, device_id):
"""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."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tellduslive/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, client, device_id):
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):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/tellduslive/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def is_on(self):
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()

0 comments on commit b86513c

Please sign in to comment.