mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix update on cert_expiry startup (#27137)
* Don't force extra update on startup * Skip on entity add instead * Conditional update based on HA state * Only force entity state update when postponed * Clean up state updating * Delay YAML import
This commit is contained in:
parent
2ccd0039d7
commit
d39e320b9e
@ -15,6 +15,7 @@ from homeassistant.const import (
|
|||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from .const import DOMAIN, DEFAULT_NAME, DEFAULT_PORT
|
from .const import DOMAIN, DEFAULT_NAME, DEFAULT_PORT
|
||||||
@ -35,18 +36,26 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||||
"""Set up certificate expiry sensor."""
|
"""Set up certificate expiry sensor."""
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
@callback
|
||||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=dict(config)
|
def do_import(_):
|
||||||
|
"""Process YAML import after HA is fully started."""
|
||||||
|
hass.async_create_task(
|
||||||
|
hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_IMPORT}, data=dict(config)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
# Delay to avoid validation during setup in case we're checking our own cert.
|
||||||
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, do_import)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry, async_add_entities):
|
async def async_setup_entry(hass, entry, async_add_entities):
|
||||||
"""Add cert-expiry entry."""
|
"""Add cert-expiry entry."""
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[SSLCertificate(entry.title, entry.data[CONF_HOST], entry.data[CONF_PORT])],
|
[SSLCertificate(entry.title, entry.data[CONF_HOST], entry.data[CONF_PORT])],
|
||||||
True,
|
False,
|
||||||
|
# Don't update in case we're checking our own cert.
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -84,17 +93,22 @@ class SSLCertificate(Entity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""Icon to use in the frontend, if any."""
|
"""Return the availability of the sensor."""
|
||||||
return self._available
|
return self._available
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Once the entity is added we should update to get the initial data loaded."""
|
"""Once the entity is added we should update to get the initial data loaded."""
|
||||||
|
|
||||||
|
@callback
|
||||||
def do_update(_):
|
def do_update(_):
|
||||||
"""Run the update method when the start event was fired."""
|
"""Run the update method when the start event was fired."""
|
||||||
self.update()
|
self.async_schedule_update_ha_state(True)
|
||||||
|
|
||||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, do_update)
|
if self.hass.is_running:
|
||||||
|
self.async_schedule_update_ha_state(True)
|
||||||
|
else:
|
||||||
|
# Delay until HA is fully started in case we're checking our own cert.
|
||||||
|
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, do_update)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Fetch the certificate information."""
|
"""Fetch the certificate information."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user