From cda32a083faf3e7326cfe317336e473c905c6dfd Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Mon, 21 Oct 2024 17:46:59 +0300 Subject: new events model --- kvmd/plugins/atx/gpio.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'kvmd/plugins/atx/gpio.py') diff --git a/kvmd/plugins/atx/gpio.py b/kvmd/plugins/atx/gpio.py index 538aafaf..e42b3959 100644 --- a/kvmd/plugins/atx/gpio.py +++ b/kvmd/plugins/atx/gpio.py @@ -21,6 +21,7 @@ import asyncio +import copy from typing import AsyncGenerator @@ -130,14 +131,18 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes }, } + 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 systask(self) -> None: await self.__reader.poll() -- cgit v1.2.3