From 67d62cd452b19b9fce27209154266b49eb976dc3 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sat, 8 Jun 2019 06:42:45 +0300 Subject: send only changed states --- kvmd/apps/kvmd/atx.py | 7 +++++-- kvmd/apps/kvmd/hid.py | 6 +++++- kvmd/apps/kvmd/streamer.py | 6 +++++- 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'kvmd/apps') diff --git a/kvmd/apps/kvmd/atx.py b/kvmd/apps/kvmd/atx.py index 6f39e01e..aa22d831 100644 --- a/kvmd/apps/kvmd/atx.py +++ b/kvmd/apps/kvmd/atx.py @@ -108,7 +108,6 @@ class Atx: # pylint: disable=too-many-instance-attributes hdd_led_state = operator.xor(self.__hdd_led_inverted, gpio.read(self.__hdd_led_pin)) else: power_led_state = hdd_led_state = False - return { "enabled": self._enabled, "busy": self.__region.is_busy(), @@ -119,9 +118,13 @@ class Atx: # pylint: disable=too-many-instance-attributes } async def poll_state(self) -> AsyncGenerator[Dict, None]: + prev_state: Dict = {} while True: if self._enabled: - yield self.get_state() + state = self.get_state() + if state != prev_state: + yield state + prev_state = state await asyncio.sleep(self.__state_poll) else: await asyncio.sleep(60) diff --git a/kvmd/apps/kvmd/hid.py b/kvmd/apps/kvmd/hid.py index 9e866bf6..5530b188 100644 --- a/kvmd/apps/kvmd/hid.py +++ b/kvmd/apps/kvmd/hid.py @@ -161,8 +161,12 @@ class Hid(multiprocessing.Process): # pylint: disable=too-many-instance-attribu return {"online": bool(self.__online_shared.value)} async def poll_state(self) -> AsyncGenerator[Dict, None]: + prev_state: Dict = {} while self.is_alive(): - yield self.get_state() + state = self.get_state() + if state != prev_state: + yield self.get_state() + prev_state = state await asyncio.sleep(self.__state_poll) @aiotools.tasked diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py index 90c22356..b89e9fc2 100644 --- a/kvmd/apps/kvmd/streamer.py +++ b/kvmd/apps/kvmd/streamer.py @@ -139,8 +139,12 @@ class Streamer: # pylint: disable=too-many-instance-attributes } async def poll_state(self) -> AsyncGenerator[Dict, None]: + prev_state: Dict = {} while True: - yield (await self.get_state()) + state = await self.get_state() + if state != prev_state: + yield state + prev_state = state await asyncio.sleep(self.__state_poll) def get_app(self) -> str: -- cgit v1.2.3