Skip to content

Commit

Permalink
Only log number of published messages at INFO level (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
koenvervloesem authored Jun 1, 2023
1 parent 43b777e commit 606814f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion TheengsGateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"presence_topic": "home/TheengsGateway/presence",
"presence": 0,
"publish_all": 1,
"log_level": "WARNING",
"log_level": "INFO",
"discovery": 1,
"hass_discovery": 1,
"discovery_topic": "homeassistant/sensor",
Expand Down
10 changes: 8 additions & 2 deletions TheengsGateway/ble_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(
self.scanning_mode = scanning_mode
self.stopped = False
self.clock_updates: Dict[str, float] = {}
self.published_messages = 0

def connect_mqtt(self) -> None:
"""Connect to MQTT broker."""
Expand Down Expand Up @@ -190,7 +191,8 @@ def publish(
result = self.client.publish(pub_topic, msg, 0, retain)
status = result[0]
if status == 0:
logger.info("Sent `%s` to topic `%s`", msg, pub_topic)
logger.debug("Sent `%s` to topic `%s`", msg, pub_topic)
self.published_messages = self.published_messages + 1
else:
logger.error("Failed to send message to topic %s", pub_topic)

Expand Down Expand Up @@ -229,7 +231,7 @@ async def update_clock_times(self) -> None:
await clock.set_time(ampm=self.time_format)
logger.info("Synchronized time")
else:
logger.info(f"Didn't find device {address}.")
logger.warning(f"Didn't find device {address}.")
except UnsupportedDeviceError:
logger.exception("Unsupported clock")
# There's no point in retrying for an unsupported device.
Expand Down Expand Up @@ -290,9 +292,13 @@ async def ble_scan_loop(self) -> None:
while not self.stopped:
try:
if self.client.is_connected():
self.published_messages = 0
await scanner.start()
await asyncio.sleep(self.scan_time)
await scanner.stop()
logger.info(
"Sent %s messages to MQTT", self.published_messages
)
await asyncio.sleep(self.time_between_scans)

# Update time for all clocks once a day
Expand Down
2 changes: 1 addition & 1 deletion docs/use/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ docker run --rm \
-e PUBLISH_ALL=true \
-e TIME_BETWEEN=60 \
-e SCAN_TIME=60 \
-e LOG_LEVEL=DEBUG \
-e LOG_LEVEL=INFO \
-e HAAS_DISCOVERY=true \
-e DISCOVERY=true \
-e DISCOVERY_TOPIC=homeassistant/sensor \
Expand Down

0 comments on commit 606814f

Please sign in to comment.