Skip to content

Commit 713c8c9

Browse files
Fix carbon component timeout (#2818)
1 parent cb19320 commit 713c8c9

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎apps/predbat/carbon.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self, postcode, automatic, base):
3535
self.stop_api = False
3636
self.failures_total = 0
3737
self.last_success_timestamp = None
38+
self.last_updated_timestamp = None
3839
self.carbon_data_points = []
3940

4041
def wait_api_started(self):
@@ -67,8 +68,9 @@ async def fetch_carbon_data(self):
6768
"""
6869
Fetch the latest carbon data, update only if data is at least 4 hours old
6970
"""
70-
last_updated = self.last_success_timestamp
71+
last_updated = self.last_updated_timestamp
7172
if last_updated is not None and datetime.now(timezone.utc) - last_updated < timedelta(hours=4):
73+
self.last_success_timestamp = datetime.now(timezone.utc)
7274
return
7375

7476
self.log("Carbon API: Fetching latest carbon data for postcode {}".format(self.postcode))
@@ -93,6 +95,7 @@ async def fetch_carbon_data(self):
9395
data_points = data.get("data", {}).get("data", [])
9496
if data_points:
9597
self.last_success_timestamp = datetime.now(timezone.utc)
98+
self.last_updated_timestamp = self.last_success_timestamp
9699
for point in data_points:
97100
from_time = point.get("from", None)
98101
to_time = point.get("to", None)

‎apps/predbat/predbat.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import requests
2626
import asyncio
2727

28-
THIS_VERSION = "v8.26.3"
28+
THIS_VERSION = "v8.26.4"
2929

3030
# fmt: off
3131
PREDBAT_FILES = ["predbat.py", "config.py", "prediction.py", "gecloud.py","utils.py", "inverter.py", "ha.py", "download.py", "unit_test.py", "web.py", "web_helper.py", "predheat.py", "futurerate.py", "octopus.py", "solcast.py","execute.py", "plan.py", "fetch.py", "output.py", "userinterface.py", "energydataservice.py", "alertfeed.py", "compare.py", "db_manager.py", "db_engine.py", "plugin_system.py", "ohme.py", "components.py", "fox.py", "carbon.py"]

‎apps/predbat/web.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def get_status_html(self, status, version):
504504
if status and (("Warn:" in status) or ("Error:" in status)):
505505
text += "<tr><td>Status</td><td bgcolor=#ff7777>{}</td></tr>\n".format(status)
506506
elif not is_running:
507-
text += "<tr><td colspan='2' bgcolor='#ff7777'>{} (with errors)</td></tr>\n".format(status)
507+
text += "<tr><td colspan='2' bgcolor='#ff7777'>{} (unhealthy)</td></tr>\n".format(status)
508508
else:
509509
text += "<tr><td>Status</td><td>{}</td></tr>\n".format(status)
510510
text += "<tr><td>Last Updated</td><td>{}</td></tr>\n".format(last_updated)

0 commit comments

Comments
 (0)