-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix currency format issue when page is loaded outside HA wrapper
- Loading branch information
1 parent
e117436
commit 605648b
Showing
1 changed file
with
14 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
|
||
TIME_FORMAT_DAILY = "%Y-%m-%d" | ||
|
||
|
||
class WebInterface: | ||
def __init__(self, base) -> None: | ||
self.abort = False | ||
|
@@ -73,7 +72,7 @@ def history_attribute(self, history, state_key="state", last_updated_key="last_u | |
try: | ||
state = float(state) * scale | ||
if pounds: | ||
state = dp2(state / 100) | ||
state = dp2(state/100) | ||
last_updated_time = item[last_updated_key] | ||
last_updated_stamp = str2time(last_updated_time) | ||
except (ValueError, TypeError): | ||
|
@@ -120,10 +119,10 @@ def history_update(self): | |
self.cost_yesterday_car_hist = self.history_attribute(self.base.get_history_wrapper(self.base.prefix + ".cost_yesterday_car", 28), daily=True, offset_days=-1, pounds=True) | ||
self.cost_yesterday_no_car = self.subtract_daily(self.cost_yesterday_hist, self.cost_yesterday_car_hist) | ||
|
||
compare_list = self.base.get_arg("compare_list", []) | ||
compare_list = self.base.get_arg('compare_list', []) | ||
for item in compare_list: | ||
id = item.get("id", None) | ||
if id and self.base.comparison: | ||
if id and self.base.comparison: | ||
self.compare_hist[id] = {} | ||
result = self.base.comparison.get_comparison(id) | ||
if result: | ||
|
@@ -230,7 +229,7 @@ def get_header(self, title, refresh=0): | |
""" | ||
Return the HTML header for a page | ||
""" | ||
text = "<!doctype html><html><head><title>Predbat Web Interface</title>" | ||
text = "<!doctype html><html><head><meta charset=\"utf-8\"><title>Predbat Web Interface</title>" | ||
|
||
text += """ | ||
<link href="https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css" rel="stylesheet"> | ||
|
@@ -344,7 +343,7 @@ def get_chart_series(self, name, results, chart_type, color): | |
text += " }\n" | ||
return text | ||
|
||
def render_chart(self, series_data, yaxis_name, chart_name, now_str, tagname="chart", daily_chart=True): | ||
def render_chart(self, series_data, yaxis_name, chart_name, now_str, tagname='chart', daily_chart=True): | ||
""" | ||
Render a chart | ||
""" | ||
|
@@ -405,7 +404,7 @@ def render_chart(self, series_data, yaxis_name, chart_name, now_str, tagname="ch | |
start: 'day' | ||
}, | ||
""" | ||
|
||
text += " series: [\n" | ||
first = True | ||
opacity = [] | ||
|
@@ -849,7 +848,7 @@ async def html_charts(self, request): | |
args = request.query | ||
chart = args.get("chart", "Battery") | ||
self.default_page = "./charts?chart={}".format(chart) | ||
text = self.get_header("Predbat Charts", refresh=60 * 5) | ||
text = self.get_header("Predbat Charts", refresh=60*5) | ||
text += "<body>\n" | ||
text += "<h2>{} Chart</h2>\n".format(chart) | ||
text += '- <a href="./charts?chart=Battery">Battery</a> ' | ||
|
@@ -870,7 +869,7 @@ async def html_apps(self, request): | |
Render apps.yaml as an HTML page | ||
""" | ||
self.default_page = "./apps" | ||
text = self.get_header("Predbat Apps.yaml", refresh=60 * 5) | ||
text = self.get_header("Predbat Apps.yaml", refresh=60*5) | ||
text += "<body>\n" | ||
text += "<a href='./debug_apps'>apps.yaml</a><br>\n" | ||
text += "<table>\n" | ||
|
@@ -991,7 +990,7 @@ async def html_compare(self, request): | |
""" | ||
self.default_page = "./compare" | ||
|
||
text = self.get_header("Predbat Compare", refresh=5 * 60) | ||
text = self.get_header("Predbat Compare", refresh=5*60) | ||
|
||
text += "<body>\n" | ||
text += '<form class="form-inline" action="./compare" method="post" enctype="multipart/form-data" id="compareform">\n' | ||
|
@@ -1013,7 +1012,7 @@ async def html_compare(self, request): | |
text += "<th>Carbon</th>" | ||
text += "<th>Result</th>\n" | ||
|
||
compare_list = self.base.get_arg("compare_list", []) | ||
compare_list = self.base.get_arg('compare_list', []) | ||
|
||
for compare in compare_list: | ||
name = compare.get("name", "") | ||
|
@@ -1050,7 +1049,7 @@ async def html_compare(self, request): | |
self.compare_hist[id]["metric"][stamp] = dp2(metric / 100) | ||
self.compare_hist[id]["cost"][stamp] = dp2(cost / 100.0) | ||
|
||
selected = '<font style="background-color:#FFaaaa;>"> Best </font>' if best else "" | ||
selected = '<font style="background-color:#FFaaaa;>"> Best </font>' if best else '' | ||
if existing_tariff: | ||
selected += '<font style="background-color:#aaFFaa;"> Existing </font>' | ||
|
||
|
@@ -1073,10 +1072,10 @@ async def html_compare(self, request): | |
for compare in compare_list: | ||
name = compare.get("name", "") | ||
id = compare.get("id", "") | ||
series_data.append({"name": name, "data": self.compare_hist.get(id, {}).get("metric", {}), "chart_type": "bar"}) | ||
series_data.append({"name": "Actual", "data": self.cost_yesterday_hist, "chart_type": "line", "stroke_width": "2"}) | ||
series_data.append({"name" : name, "data" : self.compare_hist.get(id, {}).get("metric", {}), "chart_type": "bar"}) | ||
series_data.append({"name" : "Actual", "data" : self.cost_yesterday_hist, "chart_type": "line", "stroke_width": "2"}) | ||
if self.base.car_charging_hold: | ||
series_data.append({"name": "Actual (no car)", "data": self.cost_yesterday_no_car, "chart_type": "line", "stroke_width": "2"}) | ||
series_data.append({"name" : "Actual (no car)", "data" : self.cost_yesterday_no_car, "chart_type": "line", "stroke_width": "2"}) | ||
|
||
now_str = self.base.now_utc.strftime(TIME_FORMAT) | ||
|
||
|