From 93e843d492717047fabe5c9b7f6199a8c2a43b9e Mon Sep 17 00:00:00 2001 From: Ernst Klamer Date: Mon, 19 Feb 2024 11:45:58 +0100 Subject: [PATCH] fix KeyError --- .../degree_days/knmi/__init__.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/custom_components/degree_days/knmi/__init__.py b/custom_components/degree_days/knmi/__init__.py index 2e8179d..e0a60d6 100644 --- a/custom_components/degree_days/knmi/__init__.py +++ b/custom_components/degree_days/knmi/__init__.py @@ -24,19 +24,11 @@ def __init__(self, startdate, station, T_indoor, T_heatinglimit, total_consumpti self.total_degree_days_this_year = data["total_degree_days_this_year"] self.weighted_degree_days_year = data["weighted_degree_days_year"] if self.heatpump: - if self.total_consumption: - self.energy_consumption_per_weighted_degree_day = data["consumption_per_weighted_degree_day"] - self.energy_consumption_prognose = data["consumption_prognose"] - else: - self.energy_consumption_per_weighted_degree_day = None - self.energy_consumption_prognose = None + self.energy_consumption_per_weighted_degree_day = data["consumption_per_weighted_degree_day"] + self.energy_consumption_prognose = data["consumption_prognose"] else: - if self.total_consumption: - self.gas_per_weighted_degree_day = data["consumption_per_weighted_degree_day"] - self.gas_prognose = data["consumption_prognose"] - else: - self.gas_per_weighted_degree_day = None - self.gas_prognose = None + self.gas_per_weighted_degree_day = data["consumption_per_weighted_degree_day"] + self.gas_prognose = data["consumption_prognose"] def get_degree_days(self): """Calculate degree days.""" @@ -105,6 +97,9 @@ def get_degree_days(self): data["consumption_per_weighted_degree_day"] = consumption_per_weighted_degree_day data["consumption_prognose"] = consumption_prognose + else: + data["consumption_per_weighted_degree_day"] = None + data["consumption_prognose"] = None return data