Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only log number of published messages at INFO level #138

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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