From 19f7958eab7837da14451b09d9fb3475b5d81ceb Mon Sep 17 00:00:00 2001 From: RogerSelwyn Date: Mon, 20 Jan 2025 18:21:20 +0000 Subject: [PATCH] maint: Delay startup to avoid MQTT miss --- custom_components/mqtt_discoverystream_alt/__init__.py | 3 +++ custom_components/mqtt_discoverystream_alt/const.py | 4 ++-- custom_components/mqtt_discoverystream_alt/schema.py | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/custom_components/mqtt_discoverystream_alt/__init__.py b/custom_components/mqtt_discoverystream_alt/__init__.py index b32de96..ba618ab 100644 --- a/custom_components/mqtt_discoverystream_alt/__init__.py +++ b/custom_components/mqtt_discoverystream_alt/__init__.py @@ -1,5 +1,6 @@ """Publish simple item state changes via MQTT.""" +import asyncio import json import logging @@ -18,6 +19,7 @@ CONF_PUBLISH_RETAIN, CONF_PUBLISH_TIMESTAMPS, DOMAIN, + STARTUP_DELAY, ) from .publisher import Publisher from .schema import CONFIG_SCHEMA # noqa: F401 @@ -29,6 +31,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # sourcery skip: assign-if-exp, boolean-if-exp-identity, reintroduce-else """Set up the MQTT state feed.""" # Make sure MQTT is available and the entry is loaded + await asyncio.sleep(STARTUP_DELAY) if not await mqtt.async_wait_for_mqtt_client(hass): _LOGGER.error("MQTT integration is not available") return False diff --git a/custom_components/mqtt_discoverystream_alt/const.py b/custom_components/mqtt_discoverystream_alt/const.py index 26665e0..c700708 100644 --- a/custom_components/mqtt_discoverystream_alt/const.py +++ b/custom_components/mqtt_discoverystream_alt/const.py @@ -55,13 +55,13 @@ CONF_REPUBLISH_TIME = "republish_time" CONF_UNIQUE_PREFIX = "unique_prefix" -DEFAULT_LOOP_TIME = timedelta(minutes=5) +DEFAULT_REFRESH_TIME = timedelta(minutes=5) DEFAULT_RETAIN = False DEFAULT_STATE_SLEEP = 1.5 - DOMAIN = "mqtt_discoverystream_alt" +STARTUP_DELAY = 0.5 STATE_CAPITAL_ON = "ON" STATE_CAPITAL_OFF = "OFF" diff --git a/custom_components/mqtt_discoverystream_alt/schema.py b/custom_components/mqtt_discoverystream_alt/schema.py index cc47498..58c303d 100644 --- a/custom_components/mqtt_discoverystream_alt/schema.py +++ b/custom_components/mqtt_discoverystream_alt/schema.py @@ -24,7 +24,7 @@ CONF_REMOTE_STATUS, CONF_REPUBLISH_TIME, CONF_UNIQUE_PREFIX, - DEFAULT_LOOP_TIME, + DEFAULT_REFRESH_TIME, DEFAULT_RETAIN, DOMAIN, ) @@ -61,7 +61,7 @@ vol.Optional(CONF_PUBLISH_RETAIN, default=DEFAULT_RETAIN): cv.boolean, vol.Optional(CONF_UNIQUE_PREFIX, default="mqtt"): cv.string, vol.Optional( - CONF_REPUBLISH_TIME, default=DEFAULT_LOOP_TIME + CONF_REPUBLISH_TIME, default=DEFAULT_REFRESH_TIME ): cv.time_period, } ),