summaryrefslogtreecommitdiff
path: root/kvmd/plugins
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
parent4f3ebf0fd1100d2076a626d9ae39f414e9adf90b (diff)
common component interface
Diffstat (limited to 'kvmd/plugins')
-rw-r--r--kvmd/plugins/atx/__init__.py2
-rw-r--r--kvmd/plugins/atx/disabled.py4
-rw-r--r--kvmd/plugins/atx/gpio.py15
3 files changed, 12 insertions, 9 deletions
diff --git a/kvmd/plugins/atx/__init__.py b/kvmd/plugins/atx/__init__.py
index b536ef87..bc0c2c41 100644
--- a/kvmd/plugins/atx/__init__.py
+++ b/kvmd/plugins/atx/__init__.py
@@ -47,7 +47,7 @@ class AtxIsBusyError(IsBusyError, AtxError):
# =====
class BaseAtx(BasePlugin):
- def get_state(self) -> Dict:
+ async def get_state(self) -> Dict:
raise NotImplementedError
async def poll_state(self) -> AsyncGenerator[Dict, None]:
diff --git a/kvmd/plugins/atx/disabled.py b/kvmd/plugins/atx/disabled.py
index d480a337..93cfbb5b 100644
--- a/kvmd/plugins/atx/disabled.py
+++ b/kvmd/plugins/atx/disabled.py
@@ -37,7 +37,7 @@ class AtxDisabledError(AtxOperationError):
# =====
class Plugin(BaseAtx):
- def get_state(self) -> Dict:
+ async def get_state(self) -> Dict:
return {
"enabled": False,
"busy": False,
@@ -49,7 +49,7 @@ class Plugin(BaseAtx):
async def poll_state(self) -> AsyncGenerator[Dict, None]:
while True:
- yield self.get_state()
+ yield (await self.get_state())
await aiotools.wait_infinite()
# =====
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(