mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-09 17:07:43 +01:00
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:
parent
3a75036b19
commit
016c6d1adf
3 changed files with 47 additions and 4 deletions
|
@ -4,6 +4,8 @@ import json
|
|||
import os
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
from cbpi.api.base import CBPiBase
|
||||
from cbpi.api.config import ConfigType
|
||||
|
||||
from voluptuous.schema_builder import message
|
||||
|
||||
|
@ -23,24 +25,34 @@ class DashboardController:
|
|||
|
||||
async def get_content(self, dashboard_id):
|
||||
try:
|
||||
self.path = os.path.join(".", 'config', "cbpi_dashboard_"+ str(dashboard_id) +".json")
|
||||
logging.info(self.path)
|
||||
with open(self.path) as json_file:
|
||||
data = json.load(json_file)
|
||||
return data
|
||||
except:
|
||||
return {}
|
||||
return {'elements': [], 'pathes': []}
|
||||
|
||||
async def add_content(self, dashboard_id, data):
|
||||
print(data)
|
||||
self.path = os.path.join(".", 'config', "cbpi_dashboard_" + str(dashboard_id)+ ".json")
|
||||
with open(self.path, 'w') as outfile:
|
||||
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"}
|
||||
|
||||
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):
|
||||
os.remove(self.path)
|
||||
self.cbpi.notify(title="Dashboard {}".format(dashboard_id), message="Deleted Successfully", type=NotificationType.SUCCESS)
|
||||
|
||||
|
||||
async def get_custom_widgets(self):
|
||||
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")]
|
||||
return onlyfiles
|
||||
|
||||
async def get_dashboard_numbers(self):
|
||||
max_dashboard_number = self.cbpi.config.get("max_dashboard_number", 4)
|
||||
return max_dashboard_number
|
||||
|
|
|
@ -33,6 +33,8 @@ class ConfigUpdate(CBPiExtension):
|
|||
mashout_step = self.cbpi.config.get("steps_mashout", None)
|
||||
boil_step = self.cbpi.config.get("steps_boil", 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:
|
||||
logger.info("INIT Boil Temp Setting")
|
||||
|
@ -90,7 +92,24 @@ class ConfigUpdate(CBPiExtension):
|
|||
except:
|
||||
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)
|
||||
if AutoMode is None:
|
||||
logger.info("INIT AutoMode")
|
||||
|
|
|
@ -109,4 +109,16 @@ class DashBoardHttpEndpoints:
|
|||
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue