From 4a9f490c69001a68549a8a945b4bcc74c75312fa Mon Sep 17 00:00:00 2001 From: Joshua Mulliken Date: Fri, 2 Jul 2021 09:15:52 -0400 Subject: [PATCH] Update to fix the threading on the updater service for cameras --- Pipfile | 2 ++ Pipfile.lock | 18 +++++++++++++++++- setup.cfg | 2 +- sonar-project.properties | 2 +- src/wyzeapy/services/camera_service.py | 7 ++++--- src/wyzeapy/types.py | 6 ------ 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Pipfile b/Pipfile index bf081bc..08587b0 100644 --- a/Pipfile +++ b/Pipfile @@ -9,6 +9,8 @@ coverage = "*" aiohttp = "*" aiodns = "*" cchardet = "*" +wyzeapy = "*" +wheel = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 637200a..c73f382 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b5990f8dc46e6c32651aa5000ead454fadbfd198278fa79460c90db0d74db1be" + "sha256": "6f738d2be212f8105c11a1cf833a1c1db76164ea917e14bb6dcc91b392fc20a7" }, "pipfile-spec": 6, "requires": { @@ -387,6 +387,22 @@ ], "version": "==3.10.0.0" }, + "wheel": { + "hashes": [ + "sha256:78b5b185f0e5763c26ca1e324373aadd49182ca90e825f7853f4b2509215dc0e", + "sha256:e11eefd162658ea59a60a0f6c7d493a7190ea4b9a85e335b33489d9f17e0245e" + ], + "index": "pypi", + "version": "==0.36.2" + }, + "wyzeapy": { + "hashes": [ + "sha256:0ee696e8d213b29d60cc4dea315ef20c94a2ea9f94fd99c0568c3f2c3fd4b277", + "sha256:d1b8800130433c4fb3409a00f858e32b20528088462879aa63e50bf1a4c8f1a0" + ], + "index": "pypi", + "version": "==0.1.1" + }, "yarl": { "hashes": [ "sha256:00d7ad91b6583602eb9c1d085a2cf281ada267e9a197e8b7cae487dadbfa293e", diff --git a/setup.cfg b/setup.cfg index 37e2afc..3db92a9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = wyzeapy -version = 0.1.1 +version = 0.1.2 author = Mulliken LLC author_email = joshua@mulliken.net description = Python client for private Wyze API diff --git a/sonar-project.properties b/sonar-project.properties index c87ddf5..fed9fa9 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -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.1 +sonar.projectVersion=0.1.2 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. #sonar.sources=. diff --git a/src/wyzeapy/services/camera_service.py b/src/wyzeapy/services/camera_service.py index 08990bb..15b83ac 100644 --- a/src/wyzeapy/services/camera_service.py +++ b/src/wyzeapy/services/camera_service.py @@ -47,13 +47,14 @@ async def update(self, camera: Camera): return camera async def register_for_updates(self, camera: Camera, callback: Callable[[Camera], None]): + loop = asyncio.get_event_loop() if not self._updater_thread: - self._updater_thread = Thread(target=self.update_worker, daemon=True) + self._updater_thread = Thread(target=self.update_worker, args=[loop,], daemon=True) + self._updater_thread.start() self._subscribers.append((camera, callback)) - def update_worker(self): - loop = asyncio.get_event_loop() + def update_worker(self, loop): while True: if len(self._subscribers) < 1: time.sleep(0.1) diff --git a/src/wyzeapy/types.py b/src/wyzeapy/types.py index a40a88a..a78ee1a 100644 --- a/src/wyzeapy/types.py +++ b/src/wyzeapy/types.py @@ -161,9 +161,6 @@ def __init__(self, dictionary: Dict[Any, Any]): else: self.type = "Video" - def __repr__(self) -> str: - return "".format(self.file_id, self.type) - class Event: event_id: str @@ -190,9 +187,6 @@ def __init__(self, dictionary: Dict[Any, Any]): for file in self.file_list: self.typed_file_list.append(File(file)) - def __repr__(self) -> str: - return "".format(self.event_id, self.event_ts) - class HMSStatus(Enum): DISARMED = 'disarmed'