current dashboard information added

Added functions to store current dashboard info in settings
Info can be also retrieved from ui to start with the dashboard that was used last time
This commit is contained in:
avollkopf 2021-08-18 21:55:56 +02:00
parent 93be663a19
commit a7c9a5f0e6
3 changed files with 51 additions and 1 deletions

View file

@ -56,3 +56,11 @@ class DashboardController:
async def get_dashboard_numbers(self): async def get_dashboard_numbers(self):
max_dashboard_number = self.cbpi.config.get("max_dashboard_number", 4) max_dashboard_number = self.cbpi.config.get("max_dashboard_number", 4)
return max_dashboard_number return max_dashboard_number
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"}

View file

@ -34,7 +34,7 @@ class ConfigUpdate(CBPiExtension):
boil_step = self.cbpi.config.get("steps_boil", None) boil_step = self.cbpi.config.get("steps_boil", None)
cooldown_step = self.cbpi.config.get("steps_cooldown", None) cooldown_step = self.cbpi.config.get("steps_cooldown", None)
max_dashboard_number = self.cbpi.config.get("max_dashboard_number", None) max_dashboard_number = self.cbpi.config.get("max_dashboard_number", None)
current_dashboard_number = self.cbpi.config.get("current_dashboard_number", None)
if boil_temp is None: if boil_temp is None:
logger.info("INIT Boil Temp Setting") logger.info("INIT Boil Temp Setting")
@ -109,6 +109,13 @@ class ConfigUpdate(CBPiExtension):
except: except:
logger.warning('Unable to update database') logger.warning('Unable to update database')
if current_dashboard_number is None:
logger.info("INIT Current Dashboard Number")
try:
await self.cbpi.config.add("current_dashboard_number", 1, ConfigType.NUMBER, "Number of current Dashboard")
except:
logger.warning('Unable to update database')
## Check if AtuoMode for Steps is in config ## Check if AtuoMode for Steps is in config
AutoMode = self.cbpi.config.get("AutoMode", None) AutoMode = self.cbpi.config.get("AutoMode", None)
if AutoMode is None: if AutoMode is None:

View file

@ -122,3 +122,38 @@ class DashBoardHttpEndpoints:
description: successful operation description: successful operation
""" """
return web.json_response(await self.cbpi.dashboard.get_dashboard_numbers(), dumps=json_dumps) return web.json_response(await self.cbpi.dashboard.get_dashboard_numbers(), dumps=json_dumps)
@request_mapping(path="/current", method="GET", auth_required=False)
async def get_current_dashboard(self, request):
"""
---
description: Get Dashboard Numbers
tags:
- Dashboard
responses:
"200":
description: successful operation
"""
return web.json_response(await self.cbpi.dashboard.get_current_dashboard(), dumps=json_dumps)
@request_mapping(path="/{id}/current", method="POST", auth_required=False)
async def set_current_dashboard(self, request):
"""
---
description: Set Current Dashboard Number
tags:
- Dashboard
parameters:
- name: "id"
in: "path"
description: "Dashboard ID"
required: true
type: "integer"
format: "int64"
responses:
"200":
description: successful operation
"""
dashboard_id = int(request.match_info['id'])
return web.json_response(await self.cbpi.dashboard.set_current_dashboard(dashboard_id))