summaryrefslogtreecommitdiff
path: root/kvmd/plugins/hid/otg
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2024-10-21 17:46:59 +0300
committerMaxim Devaev <[email protected]>2024-10-21 17:46:59 +0300
commitcda32a083faf3e7326cfe317336e473c905c6dfd (patch)
tree19445e4098d4603f3b2cd296504a648110712af1 /kvmd/plugins/hid/otg
parentb67a2325842a6f407d3935f8445d50cb8bf307f2 (diff)
new events model
Diffstat (limited to 'kvmd/plugins/hid/otg')
-rw-r--r--kvmd/plugins/hid/otg/__init__.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/kvmd/plugins/hid/otg/__init__.py b/kvmd/plugins/hid/otg/__init__.py
index 3516546d..7686ebdd 100644
--- a/kvmd/plugins/hid/otg/__init__.py
+++ b/kvmd/plugins/hid/otg/__init__.py
@@ -20,6 +20,8 @@
# ========================================================================== #
+import copy
+
from typing import Iterable
from typing import AsyncGenerator
from typing import Any
@@ -150,14 +152,18 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
**self._get_jiggler_state(),
}
+ async def trigger_state(self) -> None:
+ self.__notifier.notify(1)
+
async def poll_state(self) -> AsyncGenerator[dict, None]:
- prev_state: dict = {}
+ prev: dict = {}
while True:
- state = await self.get_state()
- if state != prev_state:
- yield state
- prev_state = state
- await self.__notifier.wait()
+ if (await self.__notifier.wait()) > 0:
+ prev = {}
+ new = await self.get_state()
+ if new != prev:
+ prev = copy.deepcopy(new)
+ yield new
async def reset(self) -> None:
self.__keyboard_proc.send_reset_event()