Skip to content

Commit f43834b

Browse files
committed
Open Meteo weather tweaks
1 parent c5257af commit f43834b

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

weather/openmeteo_com_weather.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,14 @@ def _get_data(self):
112112
f"{self.address}&daily=sunrise,sunset,weather_code,wind_direction_10m_dominant,relative_humidity_2m_mean,temperature_2m_mean,wind_speed_10m_mean&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m,wind_direction_10m,weather_code&timezone=auto&forecast_days=14&wind_speed_unit=ms&language={self._device['language']}"
113113
)
114114

115-
# Hourly overrules daily. The data will be sorted later on
116-
return_data["forecast"] = {
117-
**self.__process_hourly_data(json_data.get("hourly", [])),
118-
**self.__process_daily_data(json_data.get("daily", [])),
119-
}
115+
# Hourly overrules daily.
116+
return_data["forecast"] = self.__process_daily_data(
117+
json_data.get("daily", []),
118+
self.__process_hourly_data(
119+
json_data.get("hourly", [])
120+
)
121+
)
122+
120123

121124
# Get history data
122125
now = datetime.now()
@@ -151,11 +154,18 @@ def __process_hourly_data(self, data):
151154

152155
return hourly_data
153156

154-
def __process_daily_data(self, data):
155-
daily_data = {}
157+
def __process_daily_data(self, data, hourly):
158+
daily_data = hourly
156159
for counter, time in enumerate(data["time"]):
157160
time = datetime.fromisoformat(time).replace(microsecond=0)
158161

162+
if time.isoformat() in daily_data:
163+
daily_data[time.isoformat()]['sun'] = {
164+
"rise": datetime.fromisoformat(data["sunrise"][counter]),
165+
"set": datetime.fromisoformat(data["sunset"][counter]),
166+
}
167+
continue
168+
159169
daily_data[time.isoformat()] = {
160170
"timestamp": time,
161171
"temperature": data["temperature_2m_mean"][counter],

0 commit comments

Comments
 (0)