Update cert_expiry to use CoordinatorEntity (#39397)

This commit is contained in:
J. Nick Koston 2020-08-30 07:41:18 -05:00 committed by GitHub
parent 21f1875816
commit 0f5733ac59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,8 +15,8 @@ from homeassistant.const import (
)
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import dt
from .const import DEFAULT_PORT, DOMAIN
@ -65,38 +65,14 @@ async def async_setup_entry(hass, entry, async_add_entities):
async_add_entities(sensors, True)
class CertExpiryEntity(Entity):
class CertExpiryEntity(CoordinatorEntity):
"""Defines a base Cert Expiry entity."""
def __init__(self, coordinator):
"""Initialize the Cert Expiry entity."""
self.coordinator = coordinator
async def async_added_to_hass(self):
"""Connect to dispatcher listening for entity data notifications."""
self.async_on_remove(
self.coordinator.async_add_listener(self.async_write_ha_state)
)
async def async_update(self):
"""Update Cert Expiry entity."""
await self.coordinator.async_request_refresh()
@property
def available(self):
"""Return True if entity is available."""
return self.coordinator.last_update_success
@property
def icon(self):
"""Icon to use in the frontend, if any."""
return "mdi:certificate"
@property
def should_poll(self):
"""Return the polling requirement of the entity."""
return False
@property
def device_state_attributes(self):
"""Return additional sensor state attributes."""