Allow Multiple Dashboards

- Up to 10 Dashboards possible
- Config parameter max_dashboard_number added
- Default is 4 dashboards
- Config parameter will be added automatically via extension if not in config.json
This commit is contained in:
avollkopf 2021-08-11 17:12:13 +02:00
parent 3a75036b19
commit 016c6d1adf
3 changed files with 47 additions and 4 deletions

View file

@ -4,6 +4,8 @@ import json
import os import os
from os import listdir from os import listdir
from os.path import isfile, join from os.path import isfile, join
from cbpi.api.base import CBPiBase
from cbpi.api.config import ConfigType
from voluptuous.schema_builder import message from voluptuous.schema_builder import message
@ -23,24 +25,34 @@ class DashboardController:
async def get_content(self, dashboard_id): async def get_content(self, dashboard_id):
try: try:
self.path = os.path.join(".", 'config', "cbpi_dashboard_"+ str(dashboard_id) +".json")
logging.info(self.path)
with open(self.path) as json_file: with open(self.path) as json_file:
data = json.load(json_file) data = json.load(json_file)
return data return data
except: except:
return {} return {'elements': [], 'pathes': []}
async def add_content(self, dashboard_id, data): async def add_content(self, dashboard_id, data):
print(data) print(data)
self.path = os.path.join(".", 'config', "cbpi_dashboard_" + str(dashboard_id)+ ".json")
with open(self.path, 'w') as outfile: with open(self.path, 'w') as outfile:
json.dump(data, outfile, indent=4, sort_keys=True) json.dump(data, outfile, indent=4, sort_keys=True)
self.cbpi.notify(title="Dashboard", message="Saved Successfully", type=NotificationType.SUCCESS) self.cbpi.notify(title="Dashboard {}".format(dashboard_id), message="Saved Successfully", type=NotificationType.SUCCESS)
return {"status": "OK"} return {"status": "OK"}
async def delete_content(self, dashboard_id): async def delete_content(self, dashboard_id):
self.path = os.path.join(".", 'config', "cbpi_dashboard_"+ str(dashboard_id)+ ".json")
if os.path.exists(self.path): if os.path.exists(self.path):
os.remove(self.path) os.remove(self.path)
self.cbpi.notify(title="Dashboard {}".format(dashboard_id), message="Deleted Successfully", type=NotificationType.SUCCESS)
async def get_custom_widgets(self): async def get_custom_widgets(self):
path = os.path.join(".", 'config', "dashboard", "widgets") path = os.path.join(".", 'config', "dashboard", "widgets")
onlyfiles = [os.path.splitext(f)[0] for f in listdir(path) if isfile(join(path, f)) and f.endswith(".svg")] onlyfiles = [os.path.splitext(f)[0] for f in listdir(path) if isfile(join(path, f)) and f.endswith(".svg")]
return onlyfiles return onlyfiles
async def get_dashboard_numbers(self):
max_dashboard_number = self.cbpi.config.get("max_dashboard_number", 4)
return max_dashboard_number

View file

@ -33,6 +33,8 @@ class ConfigUpdate(CBPiExtension):
mashout_step = self.cbpi.config.get("steps_mashout", None) mashout_step = self.cbpi.config.get("steps_mashout", None)
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)
if boil_temp is None: if boil_temp is None:
logger.info("INIT Boil Temp Setting") logger.info("INIT Boil Temp Setting")
@ -90,7 +92,24 @@ class ConfigUpdate(CBPiExtension):
except: except:
logger.warning('Unable to update database') logger.warning('Unable to update database')
## Check if AtuoMode for Steps is in config if max_dashboard_number is None:
logger.info("INIT Max Dashboard Numbers for multiple dashboards")
try:
await self.cbpi.config.add("max_dashboard_number", 4, ConfigType.SELECT, "Max Number of Dashboards",
[{"label": "1", "value": 1},
{"label": "2", "value": 2},
{"label": "3", "value": 3},
{"label": "4", "value": 4},
{"label": "5", "value": 5},
{"label": "6", "value": 6},
{"label": "7", "value": 7},
{"label": "8", "value": 8},
{"label": "9", "value": 9},
{"label": "10", "value": 10}])
except:
logger.warning('Unable to update database')
## 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:
logger.info("INIT AutoMode") logger.info("INIT AutoMode")

View file

@ -109,4 +109,16 @@ class DashBoardHttpEndpoints:
return web.json_response(await self.cbpi.dashboard.get_custom_widgets(), dumps=json_dumps) return web.json_response(await self.cbpi.dashboard.get_custom_widgets(), dumps=json_dumps)
@request_mapping(path="/numbers", method="GET", auth_required=False)
async def get_dashboard_numbers(self, request):
"""
---
description: Get Dashboard Numbers
tags:
- Dashboard
responses:
"200":
description: successful operation
"""
return web.json_response(await self.cbpi.dashboard.get_dashboard_numbers(), dumps=json_dumps)