Skip to content

Commit 0923920

Browse files
authored
Fix thread-safe state update on rotation change
I found and fixed a thread-safety issue in the rotation update signal. The image entity now schedules the state update back onto the Home Assistant event loop before calling `async_write_ha_state()`, instead of calling it directly from the dispatcher callback.
1 parent 2c83c1f commit 0923920

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

  • custom_components/roborock_custom_map

custom_components/roborock_custom_map/image.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from homeassistant.components.roborock.entity import RoborockCoordinatedEntityV1
1616
from homeassistant.config_entries import ConfigEntry
1717
from homeassistant.const import EntityCategory
18-
from homeassistant.core import HomeAssistant
18+
from homeassistant.core import HomeAssistant, callback
1919
from homeassistant.exceptions import HomeAssistantError
2020
from homeassistant.helpers.dispatcher import async_dispatcher_connect
2121
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@@ -154,6 +154,12 @@ async def async_added_to_hass(self) -> None:
154154
self.async_write_ha_state()
155155

156156
def _handle_rotation_changed(self) -> None:
157+
"""Rotation changed; schedule state update in the event loop."""
158+
self.hass.loop.call_soon_threadsafe(self._async_handle_rotation_changed)
159+
160+
161+
@callback
162+
def _async_handle_rotation_changed(self) -> None:
157163
"""Rotation changed; bump last_updated to bust the image cache."""
158164
self._attr_image_last_updated = dt_util.utcnow()
159165
self.async_write_ha_state()

0 commit comments

Comments
 (0)