-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from asyncio import Task, get_event_loop | ||
from typing import Any, Dict, List | ||
|
||
from deckconnect.widgets.base import Widget | ||
from deckconnect.widgets.obs.connector import obs | ||
|
||
|
||
class OBSWidget(Widget): | ||
relevant_events: List[str] = [] | ||
|
||
def __init__( | ||
self, widget_config: Dict[str, Any], global_config: Dict[str, Any] | ||
) -> None: | ||
super().__init__(widget_config, global_config) | ||
self.listening_task: Task[None] | None = None | ||
|
||
async def activate(self) -> None: | ||
await obs.connect(self.global_config.get("deckconnect.widgets.obs.config", {})) | ||
|
||
if not self.listening_task: | ||
self.listening_task = get_event_loop().create_task(self.listener()) | ||
|
||
async def deactivate(self) -> None: | ||
if self.listening_task: | ||
self.listening_task.cancel() | ||
self.listening_task = None | ||
|
||
async def listener(self) -> None: | ||
async for event in obs.listen(): | ||
if event == "ConnectionEstablished": | ||
self.acquire_wake_lock() | ||
elif event == "ConnectionLost": | ||
self.release_wake_lock() | ||
|
||
if event in self.relevant_events: | ||
self.request_update() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters