wait for broker to be started

This commit is contained in:
Robert Resch 2022-03-08 00:24:30 +01:00
parent 6a58d8fb7f
commit 240a66155f
2 changed files with 15 additions and 14 deletions

View file

@ -110,20 +110,18 @@ async def start():
global xmpp_server global xmpp_server
xmpp_server = XMPPServer((bumper_listen, xmpp_listen_port)) xmpp_server = XMPPServer((bumper_listen, xmpp_listen_port))
# Start MQTT Server
# await start otherwise we get an error connecting the helper bot
await asyncio.create_task(mqtt_server.start())
# Start MQTT Helperbot
asyncio.create_task(mqtt_helperbot.start())
# Start XMPP Server # Start XMPP Server
asyncio.create_task(xmpp_server.start_async_server()) asyncio.create_task(xmpp_server.start_async_server())
# Wait for helperbot to connect first # Start MQTT Server
while not mqtt_helperbot.is_connected: # await start otherwise we get an error connecting the helper bot
await mqtt_server.start()
while not mqtt_server.state == "started":
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
# Start MQTT Helperbot
await mqtt_helperbot.start()
# Start web servers # Start web servers
await web_server.start() await web_server.start()

View file

@ -52,11 +52,14 @@ class HelperBot:
async def _on_message( async def _on_message(
client: Client, topic: str, payload: bytes, qos: int, properties: dict client: Client, topic: str, payload: bytes, qos: int, properties: dict
) -> None: ) -> None:
_LOGGER.debug("Got message: topic=%s; payload=%s;", topic, payload.decode()) try:
topic_split = topic.split("/") _LOGGER.debug("Got message: topic=%s; payload=%s;", topic, payload.decode())
data_decoded = str(payload.decode()) topic_split = topic.split("/")
if topic_split[10] in self._commands: data_decoded = str(payload.decode())
self._commands[topic_split[10]].add_response(data_decoded) if topic_split[10] in self._commands:
self._commands[topic_split[10]].add_response(data_decoded)
except Exception:
_LOGGER.error("An exception occured during handling message.", exc_info=True)
self._client.on_message = _on_message self._client.on_message = _on_message