Remove monitor checks in Uptime Robot entities (#54259)
This commit is contained in:
parent
a4fd718e41
commit
3da61b77a9
1 changed files with 16 additions and 38 deletions
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||||
from pyuptimerobot import UptimeRobotMonitor
|
from pyuptimerobot import UptimeRobotMonitor
|
||||||
|
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION
|
from homeassistant.const import ATTR_ATTRIBUTION
|
||||||
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
|
from homeassistant.helpers.entity import EntityDescription
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
|
@ -25,56 +25,34 @@ class UptimeRobotEntity(CoordinatorEntity):
|
||||||
"""Initialize Uptime Robot entities."""
|
"""Initialize Uptime Robot entities."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._target = target
|
self._attr_device_info = {
|
||||||
|
"identifiers": {(DOMAIN, str(self.monitor.id))},
|
||||||
|
"name": "Uptime Robot",
|
||||||
|
"manufacturer": "Uptime Robot Team",
|
||||||
|
"entry_type": "service",
|
||||||
|
"model": self.monitor.type.name,
|
||||||
|
}
|
||||||
self._attr_extra_state_attributes = {
|
self._attr_extra_state_attributes = {
|
||||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||||
ATTR_TARGET: self._target,
|
ATTR_TARGET: target,
|
||||||
}
|
}
|
||||||
|
self._attr_unique_id = str(self.monitor.id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str | None:
|
def _monitors(self) -> list[UptimeRobotMonitor]:
|
||||||
"""Return the unique_id of the entity."""
|
|
||||||
return str(self.monitor.id) if self.monitor else None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return device information about this AdGuard Home instance."""
|
|
||||||
if self.monitor:
|
|
||||||
return {
|
|
||||||
"identifiers": {(DOMAIN, str(self.monitor.id))},
|
|
||||||
"name": "Uptime Robot",
|
|
||||||
"manufacturer": "Uptime Robot Team",
|
|
||||||
"entry_type": "service",
|
|
||||||
"model": self.monitor.type.name,
|
|
||||||
}
|
|
||||||
return {}
|
|
||||||
|
|
||||||
@property
|
|
||||||
def monitors(self) -> list[UptimeRobotMonitor]:
|
|
||||||
"""Return all monitors."""
|
"""Return all monitors."""
|
||||||
return self.coordinator.data or []
|
return self.coordinator.data or []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def monitor(self) -> UptimeRobotMonitor | None:
|
def monitor(self) -> UptimeRobotMonitor:
|
||||||
"""Return the monitor for this entity."""
|
"""Return the monitor for this entity."""
|
||||||
return next(
|
return next(
|
||||||
(
|
monitor
|
||||||
monitor
|
for monitor in self._monitors
|
||||||
for monitor in self.monitors
|
if str(monitor.id) == self.entity_description.key
|
||||||
if str(monitor.id) == self.entity_description.key
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def monitor_available(self) -> bool:
|
def monitor_available(self) -> bool:
|
||||||
"""Returtn if the monitor is available."""
|
"""Returtn if the monitor is available."""
|
||||||
status: bool = self.monitor.status == 2 if self.monitor else False
|
return bool(self.monitor.status == 2)
|
||||||
return status
|
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self) -> bool:
|
|
||||||
"""Returtn if entity is available."""
|
|
||||||
if not self.coordinator.last_update_success:
|
|
||||||
return False
|
|
||||||
return self.monitor is not None
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue