diff --git a/homeassistant/components/portainer/binary_sensor.py b/homeassistant/components/portainer/binary_sensor.py index 6d38e012548..9209fec86b5 100644 --- a/homeassistant/components/portainer/binary_sensor.py +++ b/homeassistant/components/portainer/binary_sensor.py @@ -132,11 +132,6 @@ class PortainerEndpointSensor(PortainerEndpointEntity, BinarySensorEntity): self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{device_info.id}_{entity_description.key}" - @property - def available(self) -> bool: - """Return if the device is available.""" - return super().available and self.device_id in self.coordinator.data - @property def is_on(self) -> bool | None: """Return true if the binary sensor is on.""" @@ -161,15 +156,6 @@ class PortainerContainerSensor(PortainerContainerEntity, BinarySensorEntity): self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{self.device_name}_{entity_description.key}" - @property - def available(self) -> bool: - """Return if the device is available.""" - return ( - super().available - and self.endpoint_id in self.coordinator.data - and self.device_name in self.coordinator.data[self.endpoint_id].containers - ) - @property def is_on(self) -> bool | None: """Return true if the binary sensor is on.""" diff --git a/homeassistant/components/portainer/entity.py b/homeassistant/components/portainer/entity.py index fd3c43adfc9..9401d550b02 100644 --- a/homeassistant/components/portainer/entity.py +++ b/homeassistant/components/portainer/entity.py @@ -44,6 +44,11 @@ class PortainerEndpointEntity(PortainerCoordinatorEntity): name=device_info.endpoint.name, ) + @property + def available(self) -> bool: + """Return if the device is available.""" + return super().available and self.device_id in self.coordinator.data + class PortainerContainerEntity(PortainerCoordinatorEntity): """Base implementation for Portainer container.""" @@ -84,6 +89,15 @@ class PortainerContainerEntity(PortainerCoordinatorEntity): translation_key=None if self.device_name else "unknown_container", ) + @property + def available(self) -> bool: + """Return if the device is available.""" + return ( + super().available + and self.endpoint_id in self.coordinator.data + and self.device_name in self.coordinator.data[self.endpoint_id].containers + ) + @property def container_data(self) -> PortainerContainerData: """Return the coordinator data for this container.""" diff --git a/homeassistant/components/portainer/sensor.py b/homeassistant/components/portainer/sensor.py index 7fa59912ee7..e1e3dee9a6d 100644 --- a/homeassistant/components/portainer/sensor.py +++ b/homeassistant/components/portainer/sensor.py @@ -300,15 +300,6 @@ class PortainerContainerSensor(PortainerContainerEntity, SensorEntity): self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{self.device_name}_{entity_description.key}" - @property - def available(self) -> bool: - """Return if the device is available.""" - return ( - super().available - and self.endpoint_id in self.coordinator.data - and self.device_name in self.coordinator.data[self.endpoint_id].containers - ) - @property def native_value(self) -> StateType: """Return the state of the sensor.""" @@ -332,11 +323,6 @@ class PortainerEndpointSensor(PortainerEndpointEntity, SensorEntity): self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{device_info.id}_{entity_description.key}" - @property - def available(self) -> bool: - """Return if the device is available.""" - return super().available and self.device_id in self.coordinator.data - @property def native_value(self) -> StateType: """Return the state of the sensor."""