Skip to content

Commit b9fef17

Browse files
Fix bug in peak consumption calc (#29)
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net> Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
1 parent a9070de commit b9fef17

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

custom_components/tibber_data/data_coordinator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def _async_update_data(self):
6969
now = dt_util.now(dt_util.DEFAULT_TIME_ZONE)
7070
data = {} if self.data is None else self.data
7171
for func, next_update in self._update_functions.copy().items():
72-
_LOGGER.debug("Updating Tibber data %s", next_update)
72+
_LOGGER.debug("Updating Tibber data %s %s", func, next_update)
7373
if now >= next_update:
7474
try:
7575
self._update_functions[func] = await func(data, now)
@@ -241,6 +241,8 @@ async def _get_data(self, data, now):
241241
cons = Consumption(date, _cons, _hour.get("unitPrice"), _hour.get("cost"))
242242
month_consumption.add(cons)
243243

244+
if cons.cons is None:
245+
continue
244246
if len(max_month) < 3 or cons > max_month[-1]:
245247
same_day = False
246248
for k, _cons in enumerate(max_month):
@@ -254,6 +256,7 @@ async def _get_data(self, data, now):
254256
max_month.sort(reverse=True)
255257
if len(max_month) > 3:
256258
del max_month[-1]
259+
257260
if max_month and sum(max_month) is not None:
258261
data["peak_consumption"] = sum(max_month) / len(max_month)
259262
data["peak_consumption_attrs"] = {

0 commit comments

Comments
 (0)