diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 90f161049..1c9fdc818 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -38,7 +38,7 @@ import asyncio import json -THIS_VERSION = "v8.8.11" +THIS_VERSION = "v8.8.12" # fmt: off PREDBAT_FILES = ["predbat.py", "config.py", "prediction.py", "gecloud.py","utils.py", "inverter.py", "ha.py", "download.py", "unit_test.py", "web.py", "predheat.py", "futurerate.py", "octopus.py", "solcast.py","execute.py", "plan.py", "fetch.py", "output.py", "userinterface.py"] @@ -264,6 +264,7 @@ def reset(self): """ reset_prediction_globals() self.predheat = None + self.predbat_mode = "Monitor" self.soc_kwh_history = {} self.html_plan = "

Please wait calculating...

" self.unmatched_args = {} diff --git a/apps/predbat/userinterface.py b/apps/predbat/userinterface.py index 5422b13ab..67893d0e1 100644 --- a/apps/predbat/userinterface.py +++ b/apps/predbat/userinterface.py @@ -602,7 +602,7 @@ def read_debug_yaml(self, filename): current["value"] = item["value"] self.log("Restored debug settings - minutes now {}".format(self.minutes_now)) - def create_debug_yaml(self): + def create_debug_yaml(self, write_file=True): """ Write out a debug info yaml """ @@ -634,9 +634,14 @@ def create_debug_yaml(self): debug["inverters"] = inverters_debug debug["CONFIG_ITEMS"] = CONFIG_ITEMS - with open(filename, "w") as file: - yaml.dump(debug, file) - self.log("Wrote debug yaml to {}".format(filename_p)) + + if write_file: + with open(filename, "w") as file: + yaml.dump(debug, file) + self.log("Wrote debug yaml to {}".format(filename_p)) + else: + # Return the debug yaml as a string + return yaml.dump(debug) def create_entity_list(self): """ diff --git a/apps/predbat/web.py b/apps/predbat/web.py index f1b511fe9..1eeedb4d3 100644 --- a/apps/predbat/web.py +++ b/apps/predbat/web.py @@ -86,6 +86,10 @@ async def start(self): app.router.add_get("/config", self.html_config) app.router.add_post("/config", self.html_config_post) app.router.add_get("/dash", self.html_dash) + app.router.add_get("/debug_yaml", self.html_debug_yaml) + app.router.add_get("/debug_log", self.html_debug_log) + app.router.add_get("/debug_apps", self.html_debug_apps) + app.router.add_get("/debug_plan", self.html_debug_plan) runner = web.AppRunner(app) await runner.setup() site = web.TCPSite(runner, "0.0.0.0", 5052) @@ -122,7 +126,7 @@ def icon2html(self, icon): icon = ''.format(icon.replace("mdi:", "")) return icon - def get_status_html(self, level, status): + def get_status_html(self, level, status, debug_enable, read_only, mode): text = "" if not self.base.dashboard_index: text += "

Loading please wait...

" @@ -131,7 +135,14 @@ def get_status_html(self, level, status): text += "

Status

\n" text += "\n" text += "\n".format(status) + text += "\n".format(mode) text += "\n".format(level) + text += "\n".format(debug_enable) + text += "\n".format(read_only) + text += "\n" + text += "\n" + text += "\n" + text += "\n" text += "
Status{}
Mode{}
SOC{}%
Debug Enable{}
Set Read Only{}
Downloadapps.yaml
predbat_debug.yaml
predbat.log
predbat_plan.html
\n" text += "
\n" @@ -428,7 +439,8 @@ async def html_log(self, request): text += '- All ' text += 'Warnings ' - text += 'Errors
\n' + text += 'Errors ' + text += 'Download
\n' text += "\n" @@ -546,6 +558,41 @@ def render_type(self, arg, value): text = str(value) return text + async def html_file(self, filename, data): + if data is None: + return web.Response(content_type="text/html", text="{} not found".format(filename), status=404) + else: + return web.Response(content_type="application/octet-stream", body=data.encode("utf-8"), headers={"Content-Disposition": "attachment; filename={}".format(filename)}) # Convert text to binary if needed + + async def html_debug_yaml(self, request): + """ + Return the Predbat debug yaml data + """ + yaml_debug = self.base.create_debug_yaml(write_file=False) + return await self.html_file("predbat_debug.yaml", yaml_debug) + + async def html_file_load(self, filename): + """ + Load a file and serve it up + """ + data = None + if os.path.exists(filename): + with open(filename, "r") as f: + data = f.read() + return await self.html_file(filename, data) + + async def html_debug_log(self, request): + return await self.html_file_load("predbat.log") + + async def html_debug_apps(self, request): + return await self.html_file_load("apps.yaml") + + async def html_debug_plan(self, request): + html_plan = self.base.html_plan + if not html_plan: + html_plan = None + return await self.html_file("predbat_plan.html", html_plan) + async def html_dash(self, request): """ Render apps.yaml as an HTML page @@ -554,7 +601,7 @@ async def html_dash(self, request): text = self.get_header("Predbat Dashboard") text += "\n" soc_perc = calc_percent_limit(self.base.soc_kw, self.base.soc_max) - text += self.get_status_html(soc_perc, self.base.current_status) + text += self.get_status_html(soc_perc, self.base.current_status, self.base.debug_enable, self.base.set_read_only, self.base.predbat_mode) text += "\n" return web.Response(content_type="text/html", text=text) @@ -732,6 +779,7 @@ async def html_apps(self, request): self.default_page = "./apps" text = self.get_header("Predbat Config") text += "\n" + text += "apps.yaml
\n" text += "
\n" text += "
NameValue\n"