Skip to content

Commit

Permalink
Update to fix the threading on the updater service for cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Mulliken committed Jul 2, 2021
1 parent bf73dc0 commit 4a9f490
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ coverage = "*"
aiohttp = "*"
aiodns = "*"
cchardet = "*"
wyzeapy = "*"
wheel = "*"

[dev-packages]

Expand Down
18 changes: 17 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.1
version = 0.1.2
author = Mulliken LLC
author_email = joshua@mulliken.net
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.1
sonar.projectVersion=0.1.2

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
#sonar.sources=.
Expand Down
7 changes: 4 additions & 3 deletions src/wyzeapy/services/camera_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions src/wyzeapy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ def __init__(self, dictionary: Dict[Any, Any]):
else:
self.type = "Video"

def __repr__(self) -> str:
return "<File: {}, {}>".format(self.file_id, self.type)


class Event:
event_id: str
Expand All @@ -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 "<Event: {}, {}>".format(self.event_id, self.event_ts)


class HMSStatus(Enum):
DISARMED = 'disarmed'
Expand Down

0 comments on commit 4a9f490

Please sign in to comment.