Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions homeassistant/components/cert_expiry/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CONF_PORT,
EVENT_HOMEASSISTANT_START,
)
from homeassistant.core import callback
from homeassistant.helpers.entity import Entity

from .const import DOMAIN, DEFAULT_NAME, DEFAULT_PORT
Expand All @@ -35,18 +36,26 @@

async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up certificate expiry sensor."""
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=dict(config)

@callback
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):
"""Add cert-expiry entry."""
async_add_entities(
[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

Expand Down Expand Up @@ -84,17 +93,22 @@ def icon(self):

@property
def available(self):
"""Icon to use in the frontend, if any."""
"""Return the availability of the sensor."""
return self._available

async def async_added_to_hass(self):
"""Once the entity is added we should update to get the initial data loaded."""

@callback
def do_update(_):
Comment thread
MartinHjelmare marked this conversation as resolved.
"""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)
Comment thread
jjlawren marked this conversation as resolved.
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):
"""Fetch the certificate information."""
Expand Down