Skip to content

Commit

Permalink
Adding logging to the sensor_service.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Mulliken committed Jun 30, 2021
1 parent 281b5e7 commit abdf02b
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.1.0-beta.17
version = 0.1.0-beta.18
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.1.0-beta.17
sonar.projectVersion=0.1.0-beta.18

# 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/services/sensor_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
# the license with this file. If not, please write to:
# [email protected] to receive a copy
import asyncio
import logging
import time
from threading import Thread
from typing import List, Callable, Tuple, Optional

from wyzeapy.services.base_service import BaseService
from wyzeapy.types import Device, PropertyIDs

_LOGGER = logging.getLogger(__name__)


class Sensor(Device):
detected: bool = False
Expand Down Expand Up @@ -38,6 +41,7 @@ async def update(self, sensor: Sensor) -> Sensor:
return sensor

async def register_for_updates(self, sensor: Sensor, callback: Callable[[Sensor], None]):
_LOGGER.debug(f"Registering sensor: {sensor.nickname} for updates")
if not self._updater_thread:
self._updater_thread = Thread(target=self.update_worker, daemon=True)

Expand All @@ -50,6 +54,7 @@ def update_worker(self):
time.sleep(0.1)
else:
for sensor, callback in self._subscribers:
_LOGGER.debug(f"Providing update for {sensor.nickname}")
callback(asyncio.run_coroutine_threadsafe(self.update(sensor), loop).result())

async def get_sensors(self) -> List[Sensor]:
Expand Down

0 comments on commit abdf02b

Please sign in to comment.