diff options
author | Devaev Maxim <[email protected]> | 2021-04-09 05:57:04 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2021-04-09 05:57:04 +0300 |
commit | 6f60118320ed0c12a51f1d189b196c3e86aebaa7 (patch) | |
tree | 0ff5ec83da45775e3fef12e3662f5ba3b94f9d5d /kvmd/apps | |
parent | 6cc161427a0fceff2c010cc60c56d1d1ef7381a4 (diff) |
async gpio plugins
Diffstat (limited to 'kvmd/apps')
-rw-r--r-- | kvmd/apps/kvmd/ugpio.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/kvmd/apps/kvmd/ugpio.py b/kvmd/apps/kvmd/ugpio.py index d9e283da..d77a81c6 100644 --- a/kvmd/apps/kvmd/ugpio.py +++ b/kvmd/apps/kvmd/ugpio.py @@ -91,10 +91,10 @@ class _GpioInput: }, } - def get_state(self) -> Dict: + async def get_state(self) -> Dict: (online, state) = (True, False) try: - state = (self.__driver.read(self.__pin) ^ self.__inverted) + state = (await self.__driver.read(self.__pin) ^ self.__inverted) except GpioDriverOfflineError: online = False return { @@ -153,12 +153,12 @@ class _GpioOutput: # pylint: disable=too-many-instance-attributes }, } - def get_state(self) -> Dict: + async def get_state(self) -> Dict: busy = self.__region.is_busy() (online, state) = (True, False) if not busy: try: - state = self.__read() + state = await self.__read() except GpioDriverOfflineError: online = False return { @@ -201,27 +201,27 @@ class _GpioOutput: # pylint: disable=too-many-instance-attributes @aiotools.atomic async def __inner_switch(self, state: bool) -> None: - self.__write(state) + await self.__write(state) get_logger(0).info("Ensured switch %s to state=%d", self, state) await asyncio.sleep(self.__busy_delay) @aiotools.atomic async def __inner_pulse(self, delay: float) -> None: try: - self.__write(True) + await self.__write(True) await asyncio.sleep(delay) finally: - self.__write(False) + await self.__write(False) await asyncio.sleep(self.__busy_delay) get_logger(0).info("Pulsed %s with delay=%.2f", self, delay) # ===== - def __read(self) -> bool: - return (self.__driver.read(self.__pin) ^ self.__inverted) + async def __read(self) -> bool: + return (await self.__driver.read(self.__pin) ^ self.__inverted) - def __write(self, state: bool) -> None: - self.__driver.write(self.__pin, (state ^ self.__inverted)) + async def __write(self, state: bool) -> None: + await self.__driver.write(self.__pin, (state ^ self.__inverted)) def __str__(self) -> str: return f"Output({self.__channel}, driver={self.__driver}, pin={self.__pin})" @@ -267,8 +267,8 @@ class UserGpio: async def get_state(self) -> Dict: return { - "inputs": {channel: gin.get_state() for (channel, gin) in self.__inputs.items()}, - "outputs": {channel: gout.get_state() for (channel, gout) in self.__outputs.items()}, + "inputs": {channel: await gin.get_state() for (channel, gin) in self.__inputs.items()}, + "outputs": {channel: await gout.get_state() for (channel, gout) in self.__outputs.items()}, } async def poll_state(self) -> AsyncGenerator[Dict, None]: |