Skip to content

Commit c24a2b8

Browse files
Bug fix update time (#13)
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net> Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
1 parent be3679c commit c24a2b8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

custom_components/tibber_data/sensor.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ async def _get_data(self, data, now):
233233
cons_data = await get_historic_data(self.tibber_home, self.hass.data["tibber"])
234234

235235
consumption_yesterday_available = False
236-
consumption_today_available = False
236+
consumption_prev_hour_available = False
237237
month_consumption = set()
238238
max_month = []
239239

@@ -242,10 +242,11 @@ async def _get_data(self, data, now):
242242
date = dt_util.parse_datetime(_hour.get("from"))
243243
if not (date.month == now.month and date.year == now.year):
244244
continue
245-
if date.date() == now.date() - datetime.timedelta(days=1):
246-
consumption_yesterday_available = True
247-
if date == now - datetime.timedelta(hours=1):
248-
consumption_today_available = True
245+
if _cons is not None:
246+
if date.date() == now.date() - datetime.timedelta(days=1):
247+
consumption_yesterday_available = True
248+
if date == now - datetime.timedelta(hours=1):
249+
consumption_prev_hour_available = True
249250
cons = Consumption(date, _cons, _hour.get("unitPrice"), _hour.get("cost"))
250251
month_consumption.add(cons)
251252

@@ -273,7 +274,7 @@ async def _get_data(self, data, now):
273274
data["peak_consumption_attrs"] = None
274275

275276
if self.tibber_home.has_real_time_consumption:
276-
if consumption_today_available:
277+
if consumption_prev_hour_available:
277278
next_update = (now + datetime.timedelta(hours=1)).replace(
278279
minute=2, second=0, microsecond=0
279280
)

0 commit comments

Comments
 (0)