Use entity class attributes for Cert expiry (#53363)

* Use entity class attributes for cert_expiry

* Use entity class attributes for cert_expiry
This commit is contained in:
Robert Hillis 2021-07-23 01:54:06 -04:00 committed by GitHub
parent 0b6e1d3d82
commit 1d44bfcfb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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"