diff options
-rw-r--r-- | kvmd/apps/__init__.py | 1 | ||||
-rw-r--r-- | kvmd/apps/kvmd/info/fan.py | 16 |
2 files changed, 15 insertions, 2 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index 75600390..59490fc5 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -376,6 +376,7 @@ def _get_config_scheme() -> Dict: "state_poll": Option(10.0, type=valid_float_f01), }, "fan": { + "daemon": Option("kvmd-fan", type=valid_stripped_string), "unix": Option("", type=valid_abs_path, if_empty="", unpack_as="unix_path"), "timeout": Option(5.0, type=valid_float_f01), "state_poll": Option(5.0, type=valid_float_f01), diff --git a/kvmd/apps/kvmd/info/fan.py b/kvmd/apps/kvmd/info/fan.py index d4529150..1e323d04 100644 --- a/kvmd/apps/kvmd/info/fan.py +++ b/kvmd/apps/kvmd/info/fan.py @@ -34,6 +34,8 @@ from ....logging import get_logger from .... import aiotools from .... import htclient +from ..sysunit import get_service_status + from .base import BaseInfoSubmanager @@ -41,19 +43,22 @@ from .base import BaseInfoSubmanager class FanInfoSubmanager(BaseInfoSubmanager): def __init__( self, + daemon: str, unix_path: str, timeout: float, state_poll: float, ) -> None: + self.__daemon = daemon self.__unix_path = unix_path self.__timeout = timeout self.__state_poll = state_poll async def get_state(self) -> Dict: + monitored = await self.__get_monitored() return { - "monitored": bool(self.__unix_path), - "state": ((await self.__get_fan_state() if self.__unix_path else None)), + "monitored": monitored, + "state": ((await self.__get_fan_state() if monitored else None)), } async def poll_state(self) -> AsyncGenerator[Dict, None]: @@ -77,6 +82,13 @@ class FanInfoSubmanager(BaseInfoSubmanager): # ===== + async def __get_monitored(self) -> bool: + if self.__unix_path: + status = await aiotools.run_async(get_service_status, self.__daemon) + if status is not None: + return (status[0] or status[1]) + return False + async def __get_fan_state(self) -> Optional[Dict]: try: async with self.__make_http_session() as session: |