Skip to content

Commit

Permalink
Fix statistic bug in Tibber sensor (home-assistant#116112)
Browse files Browse the repository at this point in the history
* Handle keyError in Tibber sensor

Signed-off-by: Daniel Hjelseth Høyer <[email protected]>

* Constant

Signed-off-by: Daniel Hjelseth Høyer <[email protected]>

---------

Signed-off-by: Daniel Hjelseth Høyer <[email protected]>
  • Loading branch information
Danielhiversen authored Apr 24, 2024
1 parent 67021be commit 830e8d7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions homeassistant/components/tibber/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@

from .const import DOMAIN as TIBBER_DOMAIN, MANUFACTURER

FIVE_YEARS = 5 * 365 * 24

_LOGGER = logging.getLogger(__name__)

ICON = "mdi:currency-usd"
Expand Down Expand Up @@ -724,9 +726,16 @@ async def _insert_statistics(self) -> None:
None,
{"sum"},
)
first_stat = stat[statistic_id][0]
_sum = cast(float, first_stat["sum"])
last_stats_time = first_stat["start"]
if statistic_id in stat:
first_stat = stat[statistic_id][0]
_sum = cast(float, first_stat["sum"])
last_stats_time = first_stat["start"]
else:
hourly_data = await home.get_historic_data(
FIVE_YEARS, production=is_production
)
_sum = 0.0
last_stats_time = None

statistics = []

Expand Down

0 comments on commit 830e8d7

Please sign in to comment.