Update cert_expiry to use CoordinatorEntity (#39397)
This commit is contained in:
parent
21f1875816
commit
0f5733ac59
1 changed files with 2 additions and 26 deletions
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue