add parameter for dashboard grid width

This commit is contained in:
avollkopf 2023-11-19 08:47:16 +01:00
parent bb5efce0ae
commit dbffd8dd17
4 changed files with 57 additions and 2 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.2.0.rc2" __version__ = "4.2.0.rc3"
__codename__ = "Indian Summer" __codename__ = "Indian Summer"

View file

@ -60,11 +60,19 @@ class DashboardController:
async def get_current_dashboard(self): async def get_current_dashboard(self):
current_dashboard_number = self.cbpi.config.get("current_dashboard_number", 1) current_dashboard_number = self.cbpi.config.get("current_dashboard_number", 1)
return current_dashboard_number return current_dashboard_number
async def set_current_dashboard(self, dashboard_id=1): async def set_current_dashboard(self, dashboard_id=1):
await self.cbpi.config.set("current_dashboard_number", dashboard_id) await self.cbpi.config.set("current_dashboard_number", dashboard_id)
return {"status": "OK"} 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): async def get_slow_pipe_animation(self):
slow_pipe_animation = self.cbpi.config.get("slow_pipe_animation", "Yes") slow_pipe_animation = self.cbpi.config.get("slow_pipe_animation", "Yes")
return slow_pipe_animation return slow_pipe_animation

View file

@ -64,6 +64,7 @@ class ConfigUpdate(CBPiExtension):
BoilKettle = self.cbpi.config.get("BoilKettle", None) BoilKettle = self.cbpi.config.get("BoilKettle", None)
CONFIG_STATUS = self.cbpi.config.get("CONFIG_STATUS", None) CONFIG_STATUS = self.cbpi.config.get("CONFIG_STATUS", None)
self.version=__version__ self.version=__version__
current_grid = self.cbpi.config.get("current_grid", None)
if boil_temp is None: if boil_temp is None:
@ -491,6 +492,16 @@ class ConfigUpdate(CBPiExtension):
source="steps", source="steps",
options=[{"label": "Yes", "value": "Yes"}, options=[{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}]) {"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') logger.warning('Unable to update config')
def setup(cbpi): def setup(cbpi):
cbpi.plugin.register("ConfigUpdate", ConfigUpdate) cbpi.plugin.register("ConfigUpdate", ConfigUpdate)
pass pass

View file

@ -156,6 +156,40 @@ class DashBoardHttpEndpoints:
""" """
dashboard_id = int(request.match_info['id']) dashboard_id = int(request.match_info['id'])
return web.json_response(await self.cbpi.dashboard.set_current_dashboard(dashboard_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) @request_mapping(path="/slowPipeAnimation", method="GET", auth_required=False)
async def get_slow_pipe_animation(self, request): async def get_slow_pipe_animation(self, request):