summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-06-08 06:42:45 +0300
committerDevaev Maxim <[email protected]>2019-06-08 06:42:45 +0300
commit67d62cd452b19b9fce27209154266b49eb976dc3 (patch)
tree6381b0bcdf501c668fe3c78945283018bc4dc318 /kvmd
parent5181b09db87adb2b0bdc27158f9f9da73d1cc50b (diff)
send only changed states
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/kvmd/atx.py7
-rw-r--r--kvmd/apps/kvmd/hid.py6
-rw-r--r--kvmd/apps/kvmd/streamer.py6
3 files changed, 15 insertions, 4 deletions
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: