diff --git a/homeassistant/components/ness_alarm/__init__.py b/homeassistant/components/ness_alarm/__init__.py index c81c3e0c7f7..c1d97f781af 100644 --- a/homeassistant/components/ness_alarm/__init__.py +++ b/homeassistant/components/ness_alarm/__init__.py @@ -1,6 +1,7 @@ """Support for Ness D8X/D16X devices.""" from collections import namedtuple import datetime +import logging from nessclient import ArmingState, Client import voluptuous as vol @@ -21,8 +22,11 @@ from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import config_validation as cv from homeassistant.helpers.discovery import async_load_platform from homeassistant.helpers.dispatcher import async_dispatcher_send +from homeassistant.helpers.start import async_at_started from homeassistant.helpers.typing import ConfigType +_LOGGER = logging.getLogger(__name__) + DOMAIN = "ness_alarm" DATA_NESS = "ness_alarm" @@ -109,6 +113,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _close) + async def _started(event): + # Force update for current arming status and current zone states (once Home Assistant has finished loading required sensors and panel) + _LOGGER.debug("invoking client keepalive() & update()") + hass.loop.create_task(client.keepalive()) + hass.loop.create_task(client.update()) + + async_at_started(hass, _started) + hass.async_create_task( async_load_platform( hass, Platform.BINARY_SENSOR, DOMAIN, {CONF_ZONES: zones}, config @@ -131,10 +143,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: client.on_zone_change(on_zone_change) client.on_state_change(on_state_change) - # Force update for current arming status and current zone states - hass.loop.create_task(client.keepalive()) - hass.loop.create_task(client.update()) - async def handle_panic(call: ServiceCall) -> None: await client.panic(call.data[ATTR_CODE])