mirror of
https://github.com/home-assistant/core.git
synced 2026-09-01 10:17:44 -05:00
Fix entities refresh for UptimeRobot (#170217)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -24,3 +24,6 @@ API_ATTR_OK: Final = "ok"
|
||||
|
||||
STATUS_UP = "UP"
|
||||
STATUS_DOWN = "DOWN"
|
||||
STATUS_STARTED = "STARTED"
|
||||
|
||||
STATUSES_ON = [STATUS_UP, STATUS_STARTED]
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
]
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
"not_checked_yet": "Not checked yet",
|
||||
"pause": "[%key:common::action::pause%]",
|
||||
"seems_down": "Seems down",
|
||||
"started": "Started",
|
||||
"up": "Up"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -36,6 +36,7 @@ async def test_presentation(hass: HomeAssistant) -> None:
|
||||
"not_checked_yet",
|
||||
"pause",
|
||||
"seems_down",
|
||||
"started",
|
||||
"up",
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user