From 1d44bfcfb62c223b56256645952d7309a0b6c2d0 Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Fri, 23 Jul 2021 01:54:06 -0400 Subject: [PATCH] Use entity class attributes for Cert expiry (#53363) * Use entity class attributes for cert_expiry * Use entity class attributes for cert_expiry --- .../components/cert_expiry/sensor.py | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/cert_expiry/sensor.py b/homeassistant/components/cert_expiry/sensor.py index a05acdb5d77..787465bb6f3 100644 --- a/homeassistant/components/cert_expiry/sensor.py +++ b/homeassistant/components/cert_expiry/sensor.py @@ -62,10 +62,7 @@ async def async_setup_entry(hass, entry, async_add_entities): class CertExpiryEntity(CoordinatorEntity): """Defines a base Cert Expiry entity.""" - @property - def icon(self): - """Icon to use in the frontend, if any.""" - return "mdi:certificate" + _attr_icon = "mdi:certificate" @property def extra_state_attributes(self): @@ -79,15 +76,13 @@ class CertExpiryEntity(CoordinatorEntity): class SSLCertificateTimestamp(CertExpiryEntity, SensorEntity): """Implementation of the Cert Expiry timestamp sensor.""" - @property - def device_class(self): - """Return the device class of the sensor.""" - return DEVICE_CLASS_TIMESTAMP + _attr_device_class = DEVICE_CLASS_TIMESTAMP - @property - def name(self): - """Return the name of the sensor.""" - return f"Cert Expiry Timestamp ({self.coordinator.name})" + def __init__(self, coordinator) -> None: + """Initialize a Cert Expiry timestamp sensor.""" + super().__init__(coordinator) + self._attr_name = f"Cert Expiry Timestamp ({coordinator.name})" + self._attr_unique_id = f"{coordinator.host}:{coordinator.port}-timestamp" @property def state(self): @@ -95,8 +90,3 @@ class SSLCertificateTimestamp(CertExpiryEntity, SensorEntity): if self.coordinator.data: return self.coordinator.data.isoformat() return None - - @property - def unique_id(self): - """Return a unique id for the sensor.""" - return f"{self.coordinator.host}:{self.coordinator.port}-timestamp"