craftbeerpi4-pione/cbpi/controller/dashboard_controller.py

33 lines
1,011 B
Python
Raw Normal View History

2019-01-02 21:20:44 +01:00
import logging
import json
2021-01-17 22:49:18 +01:00
import os
2019-01-02 21:20:44 +01:00
2021-01-22 23:25:20 +01:00
class DashboardController():
2019-01-02 21:20:44 +01:00
def __init__(self, cbpi):
2019-08-16 21:36:55 +02:00
self.caching = False
2019-01-02 21:20:44 +01:00
self.cbpi = cbpi
self.logger = logging.getLogger(__name__)
self.cbpi.register(self)
2021-01-22 23:25:20 +01:00
async def init(self):
pass
2019-01-07 22:05:52 +01:00
2019-01-02 21:20:44 +01:00
async def get_content(self, dashboard_id):
2021-01-17 22:49:18 +01:00
try:
with open('./config/dashboard/cbpi_dashboard_%s.json' % dashboard_id) as json_file:
data = json.load(json_file)
return data
except:
return {}
2021-01-22 23:25:20 +01:00
async def add_content(self, dashboard_id, data):
with open('./config/dashboard/cbpi_dashboard_%s.json' % dashboard_id, 'w') as outfile:
json.dump(data, outfile, indent=4, sort_keys=True)
return {"status": "OK"}
2019-01-02 21:20:44 +01:00
2021-01-17 22:49:18 +01:00
async def delete_content(self, dashboard_id):
if os.path.exists('./config/dashboard/cbpi_dashboard_%s.json' % dashboard_id):
os.remove('./config/dashboard/cbpi_dashboard_%s.json' % dashboard_id)