Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Add examples in docs for component CMs
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarSoderberg authored and m4reko committed Aug 17, 2022
1 parent 3836ad6 commit 9ec335c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/glasses3/recordings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ async def stop_children_handler_tasks(self) -> None:

@property
def events(self) -> asyncio.Queue[Tuple[RecordingsEventKind, SignalBody]]:
"""The event queue containing added and removed recording events.
"""An event queue containing added and removed recording events.
Is updated in the context `keep_updated_in_context`."""
Is kept updated in the context `keep_updated_in_context`."""
return self._events

@property
Expand Down Expand Up @@ -207,7 +207,19 @@ def __getitem__(self, key: Union[int, slice]) -> Union[Recording, List[Recording

@asynccontextmanager
async def keep_updated_in_context(self):
"""Keep the `Recordings` state continuously updated in the context by listening for added and removed recordings."""
"""Keep the `Recordings` state continuously updated in the context by listening for added and removed recordings.
Example usage:
```
async with g3.recordings.keep_updated_in_context():
await g3.recorder.start()
await asyncio.sleep(3)
await g3.recorder.stop()
print(len(g3.recordings)) # current number of recordings on device
print(await g3.recordings.events.get()) # next event from the event queue
```
"""
await self.start_children_handler_tasks()
try:
yield
Expand Down
10 changes: 9 additions & 1 deletion src/glasses3/rudimentary.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,15 @@ async def subscribe_to_sync_port(

@asynccontextmanager
async def keep_alive_in_context(self):
"""Regularly sends keep alive messages to keep rudimentary streams alive."""
"""Regularly sends keep alive messages to keep rudimentary streams alive.
Example usage:
```
async with g3.rudimentary.keep_alive_in_context():
for _ in range(100):
print(await g3.rudimentary.get_gaze_sample())
```
"""
await self.start_streams()
try:
yield
Expand Down
2 changes: 1 addition & 1 deletion src/glasses3/zeroconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def services(self) -> List[G3Service]:
return list(self._services_handler.services.values())

@staticmethod
async def wait_for_single_service( # TODO: Add timeout
async def wait_for_single_service(
events: asyncio.Queue[Tuple[EventKind, G3Service]],
ip_version: IPVersion = IPVersion.All,
) -> G3Service:
Expand Down

0 comments on commit 9ec335c

Please sign in to comment.