I’m not sure how to format the datetime
object for an hourly forecast in the frontend weather card. I’m pretty sure the data is coming out right (and the daily forecast works correctly), but all of the hours are labelled with the day instead of the hour.
Here’s the data:
<hourlyForecast dateTimeUTC="201806121300">
<condition>Mainly sunny</condition>
<iconCode format="png">01</iconCode>
<temperature unitType="metric" units="C">17</temperature>
<lop category="Nil" units="%">0</lop>
<windChill unitType="metric"/>
<humidex unitType="metric"/>
<wind>
<speed unitType="metric" units="km/h">5</speed>
<direction windDirFull="Variable direction">VR</direction>
<gust unitType="metric" units="km/h"/>
</wind>
</hourlyForecast>
This is how I’m doing it right now:
forecast_array = []
if forecast_type == 'hourly':
hours = data_element.findall('./hourlyForecastGroup/hourlyForecast')
for h in range(0, 24):
forecast_array.append({
ATTR_FORECAST_TIME: datetime.datetime.strptime(
hours[h].attrib['dateTimeUTC'],
'%Y%m%d%H%M').astimezone().isoformat(),
ATTR_FORECAST_TEMP: int(hours[h].findtext('./temperature')),
ATTR_FORECAST_CONDITION: icon_code_to_condition(
int(hours[h].findtext('./iconCode')))
})
return forecast_array
And here’s what it looks like in the GUI:
Thanks for your help.