From 3da61b77a90d3ee9042d1ed240768cde9f3e1ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sun, 8 Aug 2021 12:26:14 +0200 Subject: [PATCH] Remove monitor checks in Uptime Robot entities (#54259) --- .../components/uptimerobot/entity.py | 54 ++++++------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/homeassistant/components/uptimerobot/entity.py b/homeassistant/components/uptimerobot/entity.py index b265af77535..b9783c88b9c 100644 --- a/homeassistant/components/uptimerobot/entity.py +++ b/homeassistant/components/uptimerobot/entity.py @@ -4,7 +4,7 @@ from __future__ import annotations from pyuptimerobot import UptimeRobotMonitor 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 ( CoordinatorEntity, DataUpdateCoordinator, @@ -25,56 +25,34 @@ class UptimeRobotEntity(CoordinatorEntity): """Initialize Uptime Robot entities.""" super().__init__(coordinator) 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 = { ATTR_ATTRIBUTION: ATTRIBUTION, - ATTR_TARGET: self._target, + ATTR_TARGET: target, } + self._attr_unique_id = str(self.monitor.id) @property - def unique_id(self) -> str | None: - """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]: + def _monitors(self) -> list[UptimeRobotMonitor]: """Return all monitors.""" return self.coordinator.data or [] @property - def monitor(self) -> UptimeRobotMonitor | None: + 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 - ), - None, + monitor + for monitor in self._monitors + if str(monitor.id) == self.entity_description.key ) @property def monitor_available(self) -> bool: """Returtn if the monitor is available.""" - status: bool = self.monitor.status == 2 if self.monitor else False - 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 + return bool(self.monitor.status == 2)