Fix ness_alarm tasks being fired before required sensors and panel are loaded asynchronously (#94590)
Co-authored-by: Erik Montnemery <erik@montnemery.com>pull/94752/head^2
parent
7a82176670
commit
5955be46a4
|
@ -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])
|
||||
|
||||
|
|
Loading…
Reference in New Issue