Skip to content

Commit e6d5981

Browse files
authored
Merge pull request #295 from krombel/mk/add_random_delay_before_pushing_discovery
add random delay before pushing discovery
2 parents d73e84e + 2cfb2e0 commit e6d5981

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

mqtt_gateway.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import signal
66
import sys
7+
from random import uniform
78
from typing import override, Optional
89

910
import apscheduler.schedulers.asyncio
@@ -184,6 +185,8 @@ async def on_mqtt_global_command_received(self, *, topic: str, payload: str):
184185
case self.configuration.ha_lwt_topic:
185186
if payload == 'online':
186187
for (vin, vh) in self.vehicle_handlers.items():
188+
# wait randomly between 0.1 and 10 seconds before sending discovery
189+
await asyncio.sleep(uniform(0.1, 10.0))
187190
LOG.debug(f'Send HomeAssistant discovery for car {vin}')
188191
vh.publish_ha_discovery_messages(force=True)
189192
case _:

0 commit comments

Comments
 (0)