Skip to content

Commit

Permalink
Adding logging to publish/subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Mulliken committed Jun 18, 2021
1 parent 428bf8e commit 5cf4fb9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
# replace with your username:
name = wyzeapy
version = 0.0.31-beta.18
version = 0.0.31-beta.19
author = Mulliken LLC
author_email = [email protected]
description = Python client for private Wyze API
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sonar.organization=joshuamulliken

# This is the name and version displayed in the SonarCloud UI.
sonar.projectName=wyzeapy
sonar.projectVersion=0.0.31-beta.18
sonar.projectVersion=0.0.31-beta.19

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
#sonar.sources=.
Expand Down
5 changes: 5 additions & 0 deletions src/wyzeapy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import time
from asyncio import Task
from builtins import function

from typing import Any, Optional, List, Tuple, Iterable, Dict
from .base_client import NetClient
Expand Down Expand Up @@ -149,11 +150,13 @@ async def register_for_sensor_updates(self, callback, sensor):

async def sensor_update_publisher(self):
while True:
_LOGGER.debug("Updating sensors")
sensors = await self.get_sensors(force_update=True)

for callback, sensor in self._subscribers:
for i in sensors:
if i.mac == sensor.mac:
_LOGGER.debug(f"Updating {i.mac}")
callback(i)

raise RuntimeError(f"Unable to find sensor with mac: {sensor.mac}")
Expand Down Expand Up @@ -284,11 +287,13 @@ async def register_for_event_updates(self, callback, device):

async def event_update_publisher(self):
while True:
_LOGGER.debug("Updating events")
raw_events = (await self.net_client.get_full_event_list(10))['data']['event_list']
latest_events = [Event(raw_event) for raw_event in raw_events]

for callback, device in self._event_subscribers:
if event := self.return_event_for_device(device, latest_events) is not None:
_LOGGER.debug(f"Updating {device.mac}")
callback(event)

async def get_latest_event(self, device: Device) -> Optional[Event]:
Expand Down

0 comments on commit 5cf4fb9

Please sign in to comment.