From 7be061796d4f4e84a424d3c24908127ba2b0597d Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Sun, 10 May 2026 08:14:03 +0200 Subject: [PATCH] Fix entities refresh for UptimeRobot (#170217) --- .../components/uptimerobot/binary_sensor.py | 5 ++--- homeassistant/components/uptimerobot/const.py | 3 +++ homeassistant/components/uptimerobot/entity.py | 14 +++++++++----- homeassistant/components/uptimerobot/icons.json | 1 + homeassistant/components/uptimerobot/sensor.py | 2 +- homeassistant/components/uptimerobot/strings.json | 1 + homeassistant/components/uptimerobot/switch.py | 5 ++--- tests/components/uptimerobot/test_sensor.py | 1 + 8 files changed, 20 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/uptimerobot/binary_sensor.py b/homeassistant/components/uptimerobot/binary_sensor.py index d76a727cba1c..9ecd25702cf6 100644 --- a/homeassistant/components/uptimerobot/binary_sensor.py +++ b/homeassistant/components/uptimerobot/binary_sensor.py @@ -12,7 +12,7 @@ from homeassistant.components.binary_sensor import ( from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback -from .const import STATUS_UP +from .const import STATUSES_ON from .coordinator import UptimeRobotConfigEntry from .entity import UptimeRobotEntity from .utils import new_device_listener @@ -38,7 +38,6 @@ async def async_setup_entry( key=str(monitor.id), device_class=BinarySensorDeviceClass.CONNECTIVITY, ), - monitor=monitor, ) for monitor in new_monitors ] @@ -54,4 +53,4 @@ class UptimeRobotBinarySensor(UptimeRobotEntity, BinarySensorEntity): @property def is_on(self) -> bool: """Return True if the entity is on.""" - return bool(self._monitor.status == STATUS_UP) + return bool(self._monitor.status in STATUSES_ON) diff --git a/homeassistant/components/uptimerobot/const.py b/homeassistant/components/uptimerobot/const.py index b0fa6346ae21..a782133e1764 100644 --- a/homeassistant/components/uptimerobot/const.py +++ b/homeassistant/components/uptimerobot/const.py @@ -24,3 +24,6 @@ API_ATTR_OK: Final = "ok" STATUS_UP = "UP" STATUS_DOWN = "DOWN" +STATUS_STARTED = "STARTED" + +STATUSES_ON = [STATUS_UP, STATUS_STARTED] diff --git a/homeassistant/components/uptimerobot/entity.py b/homeassistant/components/uptimerobot/entity.py index f01902f8387d..d28dca7c63a6 100644 --- a/homeassistant/components/uptimerobot/entity.py +++ b/homeassistant/components/uptimerobot/entity.py @@ -23,22 +23,26 @@ class UptimeRobotEntity(CoordinatorEntity[UptimeRobotDataUpdateCoordinator]): self, coordinator: UptimeRobotDataUpdateCoordinator, description: EntityDescription, - monitor: UptimeRobotMonitor, ) -> None: """Initialize UptimeRobot entities.""" super().__init__(coordinator) self.entity_description = description - self._monitor = monitor + self._monitor_id = description.key self._attr_device_info = DeviceInfo( - identifiers={(DOMAIN, str(self._monitor.id))}, + identifiers={(DOMAIN, self._monitor_id)}, name=self._monitor.friendlyName, manufacturer="UptimeRobot Team", entry_type=DeviceEntryType.SERVICE, model=self._monitor.type, - configuration_url=f"https://uptimerobot.com/dashboard#{self._monitor.id}", + configuration_url=f"https://uptimerobot.com/dashboard#{self._monitor_id}", ) self._attr_extra_state_attributes = { ATTR_TARGET: self._monitor.url, } - self._attr_unique_id = str(self._monitor.id) + self._attr_unique_id = self._monitor_id self.api = coordinator.api + + @property + def _monitor(self) -> UptimeRobotMonitor: + """Handle monitor updates.""" + return self.coordinator.data[int(self._monitor_id)] diff --git a/homeassistant/components/uptimerobot/icons.json b/homeassistant/components/uptimerobot/icons.json index 2cfbc6e32abb..f5bf123a68dd 100644 --- a/homeassistant/components/uptimerobot/icons.json +++ b/homeassistant/components/uptimerobot/icons.json @@ -7,6 +7,7 @@ "down": "mdi:television-off", "pause": "mdi:television-pause", "seems_down": "mdi:television-off", + "started": "mdi:television-play", "up": "mdi:television-shimmer" } } diff --git a/homeassistant/components/uptimerobot/sensor.py b/homeassistant/components/uptimerobot/sensor.py index cb56136433ad..1b0f00042407 100644 --- a/homeassistant/components/uptimerobot/sensor.py +++ b/homeassistant/components/uptimerobot/sensor.py @@ -43,11 +43,11 @@ async def async_setup_entry( "not_checked_yet", "pause", "seems_down", + "started", "up", ], translation_key="monitor_status", ), - monitor=monitor, ) for monitor in new_monitors ] diff --git a/homeassistant/components/uptimerobot/strings.json b/homeassistant/components/uptimerobot/strings.json index 2b11b51dbb0e..64e73fd39f10 100644 --- a/homeassistant/components/uptimerobot/strings.json +++ b/homeassistant/components/uptimerobot/strings.json @@ -50,6 +50,7 @@ "not_checked_yet": "Not checked yet", "pause": "[%key:common::action::pause%]", "seems_down": "Seems down", + "started": "Started", "up": "Up" } } diff --git a/homeassistant/components/uptimerobot/switch.py b/homeassistant/components/uptimerobot/switch.py index a4e7f4a807ff..5a23ff51313c 100644 --- a/homeassistant/components/uptimerobot/switch.py +++ b/homeassistant/components/uptimerobot/switch.py @@ -14,7 +14,7 @@ from homeassistant.components.switch import ( from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback -from .const import STATUS_UP +from .const import STATUSES_ON from .coordinator import UptimeRobotConfigEntry from .entity import UptimeRobotEntity from .utils import new_device_listener, uptimerobot_api_call @@ -40,7 +40,6 @@ async def async_setup_entry( key=str(monitor.id), device_class=SwitchDeviceClass.SWITCH, ), - monitor=monitor, ) for monitor in new_monitors ] @@ -58,7 +57,7 @@ class UptimeRobotSwitch(UptimeRobotEntity, SwitchEntity): @property def is_on(self) -> bool: """Return True if the entity is on.""" - return bool(self._monitor.status == STATUS_UP) + return bool(self._monitor.status in STATUSES_ON) @uptimerobot_api_call async def async_turn_off(self, **kwargs: Any) -> None: diff --git a/tests/components/uptimerobot/test_sensor.py b/tests/components/uptimerobot/test_sensor.py index 20462a27a4f9..756168b498f2 100644 --- a/tests/components/uptimerobot/test_sensor.py +++ b/tests/components/uptimerobot/test_sensor.py @@ -36,6 +36,7 @@ async def test_presentation(hass: HomeAssistant) -> None: "not_checked_yet", "pause", "seems_down", + "started", "up", ]