Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templated UI #1476

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/predbat/environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def is_package_installed(package_name: str) -> bool:
try:
import importlib

module = importlib.import_module(package_name)
return True
except ImportError:
return False


def is_jinja2_installed() -> bool:
return is_package_installed("jinja2")


def is_appdaemon_environment() -> bool:
if is_package_installed("appdaemon"):
return True
else:
return False
8 changes: 5 additions & 3 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from datetime import datetime, timedelta
import hashlib
import traceback
from environment import is_appdaemon_environment
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to add environment.py to the file list for Predbat to download

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, sorry this has been stuck for a bit - been busy with other stuff @springfall2008


# Import AppDaemon or our standalone wrapper
try:
Expand Down Expand Up @@ -10994,9 +10995,10 @@ def initialize(self):
self.ha_interface = HAInterface(self)
self.web_interface = None
self.web_interface_task = None
self.log("Starting web interface")
self.web_interface = WebInterface(self)
self.web_interface_task = self.create_task(self.web_interface.start())
if not is_appdaemon_environment():
self.log("Starting web interface")
self.web_interface = WebInterface(self)
self.web_interface_task = self.create_task(self.web_interface.start())

# Printable config root
self.config_root_p = self.config_root
Expand Down
13 changes: 13 additions & 0 deletions apps/predbat/templates/apps.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "layout.html" %}

{% block title %}Home{% endblock %}

{% block content %}
<h2>Predbat Apps.yaml</h2>

<div id="apps">
{% autoescape false %}
{{ apps_html }}
{% endautoescape %}
</div>
{% endblock %}
19 changes: 19 additions & 0 deletions apps/predbat/templates/charts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "layout.html" %}

{% block title %}Home{% endblock %}

{% block content %}
<h2>{{ chart_title }} Chart</h2>
- <a href="./charts?chart=Battery">Battery</a>
<a href="./charts?chart=Power">Power</a>
<a href="./charts?chart=Cost">Cost</a>
<a href="./charts?chart=Rates">Rates</a>
<a href="./charts?chart=InDay">InDay</a>
<a href="./charts?chart=PV">PV</a>
<a href="./charts?chart=PV7">PV7</a>
<div id="chart">
{% autoescape false %}
{{ chart_html }}
{% endautoescape %}
</div>
{% endblock %}
13 changes: 13 additions & 0 deletions apps/predbat/templates/config.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "layout.html" %}

{% block title %}Home{% endblock %}

{% block content %}
<h2>Predbat Config</h2>

<div id="apps">
{% autoescape false %}
{{ config_html }}
{% endautoescape %}
</div>
{% endblock %}
10 changes: 10 additions & 0 deletions apps/predbat/templates/dash.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "layout.html" %}

{% block title %}Home{% endblock %}


{% block content %}
{% autoescape false %}
{{ dash_html }}
{% endautoescape %}
{% endblock %}
9 changes: 9 additions & 0 deletions apps/predbat/templates/docs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "layout.html" %}

{% block title %}Home{% endblock %}

{% block content %}
<div class="iframe-container">
<iframe src="https://springfall2008.github.io/batpred/" class="main-frame" name="main_frame"></iframe>
</div>
{% endblock %}
89 changes: 89 additions & 0 deletions apps/predbat/templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!doctype html>
<html>
<head>
<title>Predbat Web Interface</title>
<link href="https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
}
.iframe-container {
display: flex;
flex-direction: column;
height: 90vh;
}
/* Style for the top menu iframe */
.menu-frame {
height: 80px; /* Adjust the height of the menu bar */
width: 100%;
border: none;
overflow: hidden;
}
/* Style for the full height iframe */
.main-frame {
flex-grow: 1;
width: 100%;
border: none;
}
body {
font-family: Arial, sans-serif;
text-align: left;
margin: 5px;
background-color: #ffffff;
color: #333;
}
h1 {
color: #4CAF50;
}
h2 {
color: #4CAF50;
display: inline
}
table {
border-collapse: collapse;
padding: 1px;
border: 1px solid blue;
}
th,
td {
text-align: left;
padding: 5px;
vertical-align: top;
}
th {
background-color: #4CAF50;
color: white;
}
.default {
background-color: #FFFFFF;
}
.modified {
background-color: #FFCCCC;
}
</style>
{% if refresh is defined %}
<meta http-equiv="refresh" content="{{ refresh }}" >
{% endif %}

</head>
<body>
<div>
<table>
<tr>
<td><h2>Predbat</h2></td><td><img src="https://github-production-user-asset-6210df.s3.amazonaws.com/48591903/249456079-e98a0720-d2cf-4b71-94ab-97fe09b3cee1.png" width="50" height="50"></td>
<td><a href="./">Dash</a></td>
<td><a href="./plan">Plan</a></td>
<td><a href="./charts">Charts</a></td>
<td><a href="./config">Config</a></td>
<td><a href="./apps">apps.yaml</a></td>
<td><a href="./log?warnings">Log</a></td>
<td><a href="./docs">Docs</a></td>
</tr>
</table>
</div>
{% block content %}{% endblock %}
</body>
</html>
16 changes: 16 additions & 0 deletions apps/predbat/templates/logs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends "layout.html" %}

{% block title %}Home{% endblock %}


{% block content %}
<h2>Logfile ({% if errors %}Errors{% elif warnings %}Warnings{% else %}All{% endif %})</h2>
- <a href="./log">All</a> <a href="./log?warnings">Warnings</a> <a href="./log?errors">Errors</a><br>
<table width=100%>
{% for line in lines %}
<tr><td>{{ line.line_no}}</td><td nowrap><font color="#{% if "error" in line.rest_line.lower() %}ff3333{% elif not errors and "warn" in line.rest_line.lower()%}ffA500{% else %}33cc33{% endif %}">{{ line.start_line }}</font> {{ line.rest_line }}</td></tr>
{% endfor %}
</table>
{% autoescape false %}
{% endautoescape %}
{% endblock %}
11 changes: 11 additions & 0 deletions apps/predbat/templates/plan.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "layout.html" %}

{% block title %}Home{% endblock %}


{% block content %}
Plan
{% autoescape false %}
{{ plan_html }}
{% endautoescape %}
{% endblock %}
Loading
Loading