Skip to content

Commit 25a9948

Browse files
authored
Portainer fix ephemeral coordinator ID (home-assistant#155056)
1 parent f0f420e commit 25a9948

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

homeassistant/components/portainer/binary_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,5 @@ def available(self) -> bool:
142142
def is_on(self) -> bool | None:
143143
"""Return true if the binary sensor is on."""
144144
return self.entity_description.state_fn(
145-
self.coordinator.data[self.endpoint_id].containers[self.device_id]
145+
self.coordinator.data[self.endpoint_id].containers[self.device_name]
146146
)

homeassistant/components/portainer/button.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,7 @@ def __init__(
9595
self.entity_description = entity_description
9696
super().__init__(device_info, coordinator, via_device)
9797

98-
device_identifier = (
99-
self._device_info.names[0].replace("/", " ").strip()
100-
if self._device_info.names
101-
else None
102-
)
103-
self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{device_identifier}_{entity_description.key}"
98+
self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{self.device_name}_{entity_description.key}"
10499

105100
async def async_press(self) -> None:
106101
"""Trigger the Portainer button press service."""

homeassistant/components/portainer/coordinator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ async def _async_update_data(self) -> dict[int, PortainerCoordinatorData]:
144144
id=endpoint.id,
145145
name=endpoint.name,
146146
endpoint=endpoint,
147-
containers={container.id: container for container in containers},
147+
containers={
148+
container.names[0].replace("/", " ").strip(): container
149+
for container in containers
150+
},
148151
docker_version=docker_version,
149152
docker_info=docker_info,
150153
)

homeassistant/components/portainer/sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def available(self) -> bool:
212212
def native_value(self) -> StateType:
213213
"""Return the state of the sensor."""
214214
return self.entity_description.value_fn(
215-
self.coordinator.data[self.endpoint_id].containers[self.device_id]
215+
self.coordinator.data[self.endpoint_id].containers[self.device_name]
216216
)
217217

218218

homeassistant/components/portainer/switch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def __init__(
123123
def is_on(self) -> bool | None:
124124
"""Return the state of the device."""
125125
return self.entity_description.is_on_fn(
126-
self.coordinator.data[self.endpoint_id].containers[self.device_id]
126+
self.coordinator.data[self.endpoint_id].containers[self.device_name]
127127
)
128128

129129
async def async_turn_on(self, **kwargs: Any) -> None:

0 commit comments

Comments
 (0)