Skip to content

Commit af66180

Browse files
authored
Store rotation state per device and map instead of only map_flag.
This prevents multiple Roborock devices with identical map_flag values from sharing rotation state and dispatcher signals.
1 parent 9dcf86d commit af66180

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

  • custom_components/roborock_custom_map

custom_components/roborock_custom_map/select.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import annotations
44

5-
import logging
6-
75
from homeassistant.components.roborock.coordinator import RoborockDataUpdateCoordinator
86
from homeassistant.components.roborock.entity import RoborockCoordinatedEntityV1
97
from homeassistant.components.select import SelectEntity
@@ -22,8 +20,6 @@
2220
SIGNAL_ROTATION_CHANGED,
2321
)
2422

25-
_LOGGER = logging.getLogger(__name__)
26-
2723
PARALLEL_UPDATES = 0
2824

2925

@@ -52,6 +48,7 @@ class RoborockMapRotationSelect(RoborockCoordinatedEntityV1, RestoreEntity, Sele
5248

5349
_attr_has_entity_name = True
5450
_attr_entity_category = EntityCategory.CONFIG
51+
_attr_translation_key = "rotation"
5552

5653
def __init__(
5754
self,
@@ -66,14 +63,14 @@ def __init__(
6663

6764
self.config_entry = config_entry
6865
self.map_flag = map_flag
66+
self.rotation_key = f"{coordinator.duid_slug}_{map_flag}"
6967

7068
if not map_name:
7169
map_name = f"Map {map_flag}"
7270

7371
self._attr_name = f"{map_name} rotation"
7472
self._attr_options = [str(v) for v in MAP_ROTATION_OPTIONS]
7573
self._attr_current_option = str(DEFAULT_MAP_ROTATION)
76-
self._attr_translation_key = "rotation"
7774

7875
async def async_added_to_hass(self) -> None:
7976
"""Restore previous rotation setting and store in hass.data."""
@@ -85,7 +82,7 @@ async def async_added_to_hass(self) -> None:
8582

8683
# Persist selection for the image entity to read
8784
self.hass.data[DOMAIN][self.config_entry.entry_id][CONF_MAP_ROTATION][
88-
self.map_flag
85+
self.rotation_key
8986
] = int(self._attr_current_option)
9087

9188
self.async_write_ha_state()
@@ -98,13 +95,13 @@ async def async_select_option(self, option: str) -> None:
9895
self._attr_current_option = option
9996

10097
self.hass.data[DOMAIN][self.config_entry.entry_id][CONF_MAP_ROTATION][
101-
self.map_flag
98+
self.rotation_key
10299
] = int(option)
103100

104101
# Notify the image entity to bust the cache via image_last_updated bump
105102
async_dispatcher_send(
106103
self.hass,
107-
f"{SIGNAL_ROTATION_CHANGED}_{self.config_entry.entry_id}_{self.map_flag}",
104+
f"{SIGNAL_ROTATION_CHANGED}_{self.config_entry.entry_id}_{self.rotation_key}",
108105
)
109106

110107
self.async_write_ha_state()

0 commit comments

Comments
 (0)