fix unknown value on startup
This commit is contained in:
parent
dcd66bf9fc
commit
958d33f366
9
main.py
9
main.py
@ -282,14 +282,21 @@ class GadgetbridgeMQTTPublisher:
|
|||||||
) as client:
|
) as client:
|
||||||
self.mqtt_client = client
|
self.mqtt_client = client
|
||||||
await self.setup_home_assistant_entities()
|
await self.setup_home_assistant_entities()
|
||||||
|
# Publish immediately on startup
|
||||||
|
steps_data = self.get_steps_data()
|
||||||
|
if steps_data:
|
||||||
|
await self.publish_steps_data(steps_data)
|
||||||
|
self.logger.info(
|
||||||
|
f"Sleeping for {self.publish_interval} seconds before next publish..."
|
||||||
|
)
|
||||||
while True:
|
while True:
|
||||||
|
await asyncio.sleep(self.publish_interval)
|
||||||
steps_data = self.get_steps_data()
|
steps_data = self.get_steps_data()
|
||||||
if steps_data:
|
if steps_data:
|
||||||
await self.publish_steps_data(steps_data)
|
await self.publish_steps_data(steps_data)
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
f"Sleeping for {self.publish_interval} seconds before next publish..."
|
f"Sleeping for {self.publish_interval} seconds before next publish..."
|
||||||
)
|
)
|
||||||
await asyncio.sleep(self.publish_interval)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Failed to connect to MQTT broker: {e}")
|
self.logger.error(f"Failed to connect to MQTT broker: {e}")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user