send only changed states

This commit is contained in:
Devaev Maxim 2019-06-08 06:42:45 +03:00
parent 5181b09db8
commit 67d62cd452
3 changed files with 15 additions and 4 deletions

View File

@ -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)

View File

@ -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():
state = self.get_state()
if state != prev_state:
yield self.get_state()
prev_state = state
await asyncio.sleep(self.__state_poll)
@aiotools.tasked

View File

@ -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: