Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
frenck marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This signal is not specific to the config entry to it will update all entities when it fires, but this is an existing problem, and I wanted to keep this change small since I cannot test it

)
)

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()