Skip to content

Commit

Permalink
maint: Delay startup to avoid MQTT miss
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Jan 20, 2025
1 parent 226b1fa commit 19f7958
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions custom_components/mqtt_discoverystream_alt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Publish simple item state changes via MQTT."""

import asyncio
import json
import logging

Expand All @@ -18,6 +19,7 @@
CONF_PUBLISH_RETAIN,
CONF_PUBLISH_TIMESTAMPS,
DOMAIN,
STARTUP_DELAY,
)
from .publisher import Publisher
from .schema import CONFIG_SCHEMA # noqa: F401
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions custom_components/mqtt_discoverystream_alt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/mqtt_discoverystream_alt/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
CONF_REMOTE_STATUS,
CONF_REPUBLISH_TIME,
CONF_UNIQUE_PREFIX,
DEFAULT_LOOP_TIME,
DEFAULT_REFRESH_TIME,
DEFAULT_RETAIN,
DOMAIN,
)
Expand Down Expand Up @@ -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,
}
),
Expand Down

0 comments on commit 19f7958

Please sign in to comment.