mirror of
https://github.com/home-assistant/core.git
synced 2026-02-14 23:28:42 +00:00
Cleanup code for UptimeRobot (#162905)
This commit is contained in:
@@ -54,4 +54,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 == STATUS_UP)
|
||||
|
||||
@@ -30,32 +30,15 @@ class UptimeRobotEntity(CoordinatorEntity[UptimeRobotDataUpdateCoordinator]):
|
||||
self.entity_description = description
|
||||
self._monitor = monitor
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, str(self.monitor.id))},
|
||||
name=self.monitor.friendlyName,
|
||||
identifiers={(DOMAIN, str(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}",
|
||||
model=self._monitor.type,
|
||||
configuration_url=f"https://uptimerobot.com/dashboard#{self._monitor.id}",
|
||||
)
|
||||
self._attr_extra_state_attributes = {
|
||||
ATTR_TARGET: self.monitor.url,
|
||||
ATTR_TARGET: self._monitor.url,
|
||||
}
|
||||
self._attr_unique_id = str(self.monitor.id)
|
||||
self._attr_unique_id = str(self._monitor.id)
|
||||
self.api = coordinator.api
|
||||
|
||||
@property
|
||||
def _monitors(self) -> list[UptimeRobotMonitor]:
|
||||
"""Return all monitors."""
|
||||
return self.coordinator.data or []
|
||||
|
||||
@property
|
||||
def monitor(self) -> UptimeRobotMonitor:
|
||||
"""Return the monitor for this entity."""
|
||||
return next(
|
||||
(
|
||||
monitor
|
||||
for monitor in self._monitors
|
||||
if str(monitor.id) == self.entity_description.key
|
||||
),
|
||||
self._monitor,
|
||||
)
|
||||
|
||||
@@ -63,7 +63,7 @@ class UptimeRobotSensor(UptimeRobotEntity, SensorEntity):
|
||||
@property
|
||||
def native_value(self) -> str:
|
||||
"""Return the status of the monitor."""
|
||||
status = self.monitor.status.lower()
|
||||
status = self._monitor.status.lower()
|
||||
# The API returns "paused"
|
||||
# but the entity state will be "pause" to avoid a breaking change
|
||||
return {"paused": "pause"}.get(status, status) # type: ignore[no-any-return]
|
||||
|
||||
@@ -63,7 +63,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 == STATUS_UP)
|
||||
|
||||
async def _async_edit_monitor(self, **kwargs: Any) -> None:
|
||||
"""Edit monitor status."""
|
||||
@@ -83,8 +83,8 @@ class UptimeRobotSwitch(UptimeRobotEntity, SwitchEntity):
|
||||
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn off switch."""
|
||||
await self._async_edit_monitor(monitor_id=self.monitor.id, status=STATUS_DOWN)
|
||||
await self._async_edit_monitor(monitor_id=self._monitor.id, status=STATUS_DOWN)
|
||||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn on switch."""
|
||||
await self._async_edit_monitor(monitor_id=self.monitor.id, status=STATUS_UP)
|
||||
await self._async_edit_monitor(monitor_id=self._monitor.id, status=STATUS_UP)
|
||||
|
||||
Reference in New Issue
Block a user