Skip to content

Commit e46e311

Browse files
committed
Fixes #104
1 parent b501acc commit e46e311

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

custom_components/dwd_weather/connector.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ def get_condition(self):
224224
now = datetime.now(timezone.utc)
225225
condition = self.dwd_weather.get_forecast_condition(now, False)
226226
if condition == "sunny" and (
227-
now.hour < self.sun.riseutc(now.day).hour
228-
or now.hour > self.sun.setutc(now.day).hour
227+
now.hour < self.sun.riseutc(now).hour
228+
or now.hour > self.sun.setutc(now).hour
229229
):
230230
condition = "clear-night"
231231
return condition
@@ -254,24 +254,25 @@ def get_weather_value(self, data_type: WeatherDataType):
254254
shouldUpdate=False,
255255
)
256256

257-
if self._config[CONF_INTERPOLATE]:
257+
if self._config[CONF_INTERPOLATE] and value is not None:
258258
now_time_actual = datetime.now(timezone.utc)
259259
next_value = self.dwd_weather.get_forecast_data(
260260
data_type,
261261
now_time_actual + timedelta(hours=1),
262262
shouldUpdate=False,
263263
)
264-
now_time_hour = self.dwd_weather.strip_to_hour(now_time_actual).replace(
265-
tzinfo=timezone.utc
266-
)
267-
value = round(
268-
value
269-
+ (
270-
(next_value - value)
271-
* ((now_time_actual - now_time_hour).seconds / 3600)
272-
),
273-
2,
274-
)
264+
if next_value is not None:
265+
now_time_hour = self.dwd_weather.strip_to_hour(now_time_actual).replace(
266+
tzinfo=timezone.utc
267+
)
268+
value = round(
269+
value
270+
+ (
271+
(next_value - value)
272+
* ((now_time_actual - now_time_hour).seconds / 3600)
273+
),
274+
2,
275+
)
275276

276277
data_type_mapping = {
277278
WeatherDataType.TEMPERATURE: lambda x: round(x - 273.1, 1),

0 commit comments

Comments
 (0)