From dbffd8dd17f58439f35a067621503345ff0a4a66 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sun, 19 Nov 2023 08:47:16 +0100 Subject: [PATCH] add parameter for dashboard grid width --- cbpi/__init__.py | 2 +- cbpi/controller/dashboard_controller.py | 10 +++++++- cbpi/extension/ConfigUpdate/__init__.py | 13 ++++++++++ cbpi/http_endpoints/http_dashboard.py | 34 +++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index c9b2907..ae9ec3a 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.rc2" +__version__ = "4.2.0.rc3" __codename__ = "Indian Summer" diff --git a/cbpi/controller/dashboard_controller.py b/cbpi/controller/dashboard_controller.py index 2bb77b3..bb7fe44 100644 --- a/cbpi/controller/dashboard_controller.py +++ b/cbpi/controller/dashboard_controller.py @@ -60,11 +60,19 @@ class DashboardController: async def get_current_dashboard(self): current_dashboard_number = self.cbpi.config.get("current_dashboard_number", 1) return current_dashboard_number - + async def set_current_dashboard(self, dashboard_id=1): await self.cbpi.config.set("current_dashboard_number", dashboard_id) return {"status": "OK"} + async def get_current_grid(self): + current_grid = self.cbpi.config.get("current_grid", 5) + return current_grid + + async def set_current_grid(self, grid_width=5): + await self.cbpi.config.set("current_grid", grid_width) + return {"status": "OK"} + async def get_slow_pipe_animation(self): slow_pipe_animation = self.cbpi.config.get("slow_pipe_animation", "Yes") return slow_pipe_animation \ No newline at end of file diff --git a/cbpi/extension/ConfigUpdate/__init__.py b/cbpi/extension/ConfigUpdate/__init__.py index 39f3213..cecb22f 100644 --- a/cbpi/extension/ConfigUpdate/__init__.py +++ b/cbpi/extension/ConfigUpdate/__init__.py @@ -64,6 +64,7 @@ class ConfigUpdate(CBPiExtension): BoilKettle = self.cbpi.config.get("BoilKettle", None) CONFIG_STATUS = self.cbpi.config.get("CONFIG_STATUS", None) self.version=__version__ + current_grid = self.cbpi.config.get("current_grid", None) if boil_temp is None: @@ -491,6 +492,16 @@ class ConfigUpdate(CBPiExtension): source="steps", options=[{"label": "Yes", "value": "Yes"}, {"label": "No", "value": "No"}]) + + if current_grid is None: + logger.info("INIT Current Dashboard Number") + try: + await self.cbpi.config.add("current_grid", 5, type=ConfigType.NUMBER, description="Dashboard Grid Width",source="hidden") + except: + logger.warning('Unable to update database') + else: + if CONFIG_STATUS is None or CONFIG_STATUS != self.version: + await self.cbpi.config.add("current_grid", current_grid, type=ConfigType.NUMBER, description="Dashboard Grid Width",source="hidden") @@ -503,6 +514,8 @@ class ConfigUpdate(CBPiExtension): logger.warning('Unable to update config') + + def setup(cbpi): cbpi.plugin.register("ConfigUpdate", ConfigUpdate) pass diff --git a/cbpi/http_endpoints/http_dashboard.py b/cbpi/http_endpoints/http_dashboard.py index 38073cf..d6142d8 100644 --- a/cbpi/http_endpoints/http_dashboard.py +++ b/cbpi/http_endpoints/http_dashboard.py @@ -156,6 +156,40 @@ class DashBoardHttpEndpoints: """ dashboard_id = int(request.match_info['id']) return web.json_response(await self.cbpi.dashboard.set_current_dashboard(dashboard_id)) + + @request_mapping(path="/currentgrid", method="GET", auth_required=False) + async def get_current_grid(self, request): + """ + --- + description: Get Dashboard Numbers + tags: + - Dashboard + responses: + "200": + description: successful operation + """ + return web.json_response(await self.cbpi.dashboard.get_current_grid(), dumps=json_dumps) + + @request_mapping(path="/{width}/currentgrid", method="POST", auth_required=False) + async def set_current_grid(self, request): + """ + --- + description: Set Current Grid Width + tags: + - Dashboard + parameters: + - name: "width" + in: "path" + description: "Grid Width" + required: true + type: "integer" + format: "int64" + responses: + "200": + description: successful operation + """ + grid_width = int(request.match_info['width']) + return web.json_response(await self.cbpi.dashboard.set_current_grid(grid_width)) @request_mapping(path="/slowPipeAnimation", method="GET", auth_required=False) async def get_slow_pipe_animation(self, request):