summaryrefslogtreecommitdiff
path: root/kvmd/apps
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2024-11-02 10:39:15 +0200
committerMaxim Devaev <[email protected]>2024-11-02 10:39:15 +0200
commitdeba110cdf1fbd68d455e3ce20d0dfdfcb9eeacb (patch)
tree7c8e15f4ba3a89e4e50b695c76f9402fb3312773 /kvmd/apps
parent936cc21c4031b8a014dc8a9820959410f3b6f12e (diff)
partial msd events
Diffstat (limited to 'kvmd/apps')
-rw-r--r--kvmd/apps/kvmd/api/msd.py6
-rw-r--r--kvmd/apps/kvmd/server.py17
2 files changed, 21 insertions, 2 deletions
diff --git a/kvmd/apps/kvmd/api/msd.py b/kvmd/apps/kvmd/api/msd.py
index 2fa2eb9b..98e85412 100644
--- a/kvmd/apps/kvmd/api/msd.py
+++ b/kvmd/apps/kvmd/api/msd.py
@@ -63,7 +63,11 @@ class MsdApi:
@exposed_http("GET", "/msd")
async def __state_handler(self, _: Request) -> Response:
- return make_json_response(await self.__msd.get_state())
+ state = await self.__msd.get_state()
+ if state["storage"] and state["storage"]["parts"]:
+ state["storage"]["size"] = state["storage"]["parts"][""]["size"] # Legacy API
+ state["storage"]["free"] = state["storage"]["parts"][""]["free"] # Legacy API
+ return make_json_response(state)
@exposed_http("POST", "/msd/set_params")
async def __set_params_handler(self, req: Request) -> Response:
diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py
index 4f5a10d3..d9e07484 100644
--- a/kvmd/apps/kvmd/server.py
+++ b/kvmd/apps/kvmd/server.py
@@ -153,6 +153,7 @@ class _Subsystem:
class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-instance-attributes
__EV_GPIO_STATE = "gpio_state"
__EV_ATX_STATE = "atx_state"
+ __EV_MSD_STATE = "msd_state"
__EV_STREAMER_STATE = "streamer_state"
__EV_OCR_STATE = "ocr_state"
__EV_INFO_STATE = "info_state"
@@ -208,7 +209,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
_Subsystem.make(user_gpio, "User-GPIO", self.__EV_GPIO_STATE),
_Subsystem.make(hid, "HID", "hid_state").add_source("hid_keymaps_state", self.__hid_api.get_keymaps, None, None),
_Subsystem.make(atx, "ATX", self.__EV_ATX_STATE),
- _Subsystem.make(msd, "MSD", "msd_state"),
+ _Subsystem.make(msd, "MSD", self.__EV_MSD_STATE),
_Subsystem.make(streamer, "Streamer", self.__EV_STREAMER_STATE),
_Subsystem.make(ocr, "OCR", self.__EV_OCR_STATE),
_Subsystem.make(info_manager, "Info manager", self.__EV_INFO_STATE),
@@ -378,6 +379,8 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
await self.__poll_gpio_state(poller)
case self.__EV_INFO_STATE:
await self.__poll_info_state(poller)
+ case self.__EV_MSD_STATE:
+ await self.__poll_msd_state(poller)
case self.__EV_STREAMER_STATE:
await self.__poll_streamer_state(poller)
case self.__EV_OCR_STATE:
@@ -404,6 +407,18 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
for (key, value) in state.items():
await self._broadcast_ws_event(f"info_{key}_state", value, legacy=True)
+ async def __poll_msd_state(self, poller: AsyncGenerator[dict, None]) -> None:
+ prev: dict = {"storage": None}
+ async for state in poller:
+ await self._broadcast_ws_event(self.__EV_MSD_STATE, state, legacy=False)
+ prev_storage = prev["storage"]
+ prev.update(state)
+ if prev["storage"] is not None and prev_storage is not None:
+ prev_storage.update(prev["storage"])
+ prev["storage"] = prev_storage
+ if "online" in prev: # Complete/Full
+ await self._broadcast_ws_event(self.__EV_MSD_STATE, prev, legacy=True)
+
async def __poll_streamer_state(self, poller: AsyncGenerator[dict, None]) -> None:
prev: dict = {}
async for state in poller: