summaryrefslogtreecommitdiff
path: root/kvmd/plugins/atx/gpio.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-06-06 06:29:29 +0300
committerDevaev Maxim <[email protected]>2020-06-06 06:29:29 +0300
commit1d7d4100a57b5d654c1434c91e97187fe25698ef (patch)
treed4709afc3fa03ceac99f1880726ef8639845702d /kvmd/plugins/atx/gpio.py
parent4f3ebf0fd1100d2076a626d9ae39f414e9adf90b (diff)
common component interface
Diffstat (limited to 'kvmd/plugins/atx/gpio.py')
-rw-r--r--kvmd/plugins/atx/gpio.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/kvmd/plugins/atx/gpio.py b/kvmd/plugins/atx/gpio.py
index 0ed29b49..2631faec 100644
--- a/kvmd/plugins/atx/gpio.py
+++ b/kvmd/plugins/atx/gpio.py
@@ -92,7 +92,7 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes
"state_poll": Option(0.1, type=valid_float_f01),
}
- def get_state(self) -> Dict:
+ async def get_state(self) -> Dict:
return {
"enabled": True,
"busy": self.__region.is_busy(),
@@ -105,7 +105,7 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes
async def poll_state(self) -> AsyncGenerator[Dict, None]:
prev_state: Dict = {}
while True:
- state = self.get_state()
+ state = await self.get_state()
if state != prev_state:
yield state
prev_state = state
@@ -124,25 +124,25 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes
# =====
async def power_on(self) -> bool:
- if not self.get_state()["leds"]["power"]:
+ if not (await self.__get_power()):
await self.click_power()
return True
return False
async def power_off(self) -> bool:
- if self.get_state()["leds"]["power"]:
+ if (await self.__get_power()):
await self.click_power()
return True
return False
async def power_off_hard(self) -> bool:
- if self.get_state()["leds"]["power"]:
+ if (await self.__get_power()):
await self.click_power_long()
return True
return False
async def power_reset_hard(self) -> bool:
- if self.get_state()["leds"]["power"]:
+ if (await self.__get_power()):
await self.click_reset()
return True
return False
@@ -160,6 +160,9 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes
# =====
+ async def __get_power(self) -> bool:
+ return (await self.get_state())["leds"]["power"]
+
@aiotools.atomic
async def __click(self, name: str, pin: int, delay: float) -> None:
await aiotools.run_region_task(