Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Environment Canada date being wrong after midnight #121850

Merged
merged 11 commits into from
Jul 16, 2024
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
gjohansson-ST committed Jul 13, 2024
commit 01aac99f96db26df6ecca35eed5972ba3f597901
4 changes: 3 additions & 1 deletion homeassistant/components/environment_canada/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,14 @@

# The previous half day forecast hangs around for ~5 hours into the following day
if now.hour < 6 and half_days[0]["temperature_class"] != "high":
now = now - datetime.timedelta(days=1)

Check warning on line 200 in homeassistant/components/environment_canada/weather.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/environment_canada/weather.py#L200

Added line #L200 was not covered by tests

def get_day_forecast(day: int, fcst: list[dict[str, str]]) -> Forecast:
high_temp = int(fcst[0]["temperature"]) if len(fcst) == 2 else None
return {
ATTR_FORECAST_TIME: (now + datetime.timedelta(days=day)).isoformat(),
ATTR_FORECAST_TIME: (
now.astimezone(dt_util.UTC) + datetime.timedelta(days=day)
).isoformat(),
ATTR_FORECAST_NATIVE_TEMP: high_temp,
ATTR_FORECAST_NATIVE_TEMP_LOW: int(fcst[-1]["temperature"]),
ATTR_FORECAST_PRECIPITATION_PROBABILITY: int(
Expand Down
22 changes: 11 additions & 11 deletions tests/components/environment_canada/snapshots/test_weather.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@
'forecast': list([
dict({
'condition': 'sunny',
'datetime': '2022-10-03T18:00:00-07:00',
'datetime': '2022-10-04T10:00:00+00:00',
'precipitation_probability': 0,
'temperature': 18.0,
'templow': 3.0,
}),
dict({
'condition': 'sunny',
'datetime': '2022-10-04T18:00:00-07:00',
'datetime': '2022-10-05T10:00:00+00:00',
'precipitation_probability': 0,
'temperature': 20.0,
'templow': 9.0,
}),
dict({
'condition': 'partlycloudy',
'datetime': '2022-10-05T18:00:00-07:00',
'datetime': '2022-10-06T10:00:00+00:00',
'precipitation_probability': 0,
'temperature': 20.0,
'templow': 7.0,
}),
dict({
'condition': 'rainy',
'datetime': '2022-10-06T18:00:00-07:00',
'datetime': '2022-10-07T10:00:00+00:00',
'precipitation_probability': 40,
'temperature': 13.0,
'templow': 1.0,
}),
dict({
'condition': 'partlycloudy',
'datetime': '2022-10-07T18:00:00-07:00',
'datetime': '2022-10-08T10:00:00+00:00',
'precipitation_probability': 0,
'temperature': 10.0,
'templow': 3.0,
Expand All @@ -48,42 +48,42 @@
'forecast': list([
dict({
'condition': 'clear-night',
'datetime': '2022-10-03T18:00:00-07:00',
'datetime': '2022-10-04T10:00:00+00:00',
'precipitation_probability': 0,
'temperature': None,
'templow': -1.0,
}),
dict({
'condition': 'sunny',
'datetime': '2022-10-04T18:00:00-07:00',
'datetime': '2022-10-05T10:00:00+00:00',
'precipitation_probability': 0,
'temperature': 18.0,
'templow': 3.0,
}),
dict({
'condition': 'sunny',
'datetime': '2022-10-05T18:00:00-07:00',
'datetime': '2022-10-06T10:00:00+00:00',
'precipitation_probability': 0,
'temperature': 20.0,
'templow': 9.0,
}),
dict({
'condition': 'partlycloudy',
'datetime': '2022-10-06T18:00:00-07:00',
'datetime': '2022-10-07T10:00:00+00:00',
'precipitation_probability': 0,
'temperature': 20.0,
'templow': 7.0,
}),
dict({
'condition': 'rainy',
'datetime': '2022-10-07T18:00:00-07:00',
'datetime': '2022-10-08T10:00:00+00:00',
'precipitation_probability': 40,
'temperature': 13.0,
'templow': 1.0,
}),
dict({
'condition': 'partlycloudy',
'datetime': '2022-10-08T18:00:00-07:00',
'datetime': '2022-10-09T10:00:00+00:00',
'precipitation_probability': 0,
'temperature': 10.0,
'templow': 3.0,
Expand Down
6 changes: 4 additions & 2 deletions tests/components/environment_canada/test_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
from tests.common import load_fixture


@freeze_time("2022-10-04 01:00:00")
@freeze_time("2022-10-04 06:00:00-04:00")
async def test_forecast_daily(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
) -> None:
"""Test basic forecast."""
await hass.config.async_set_time_zone("America/New_York")

ec_data = json.loads(
load_fixture("environment_canada/current_conditions_data.json")
Expand All @@ -42,12 +43,13 @@ async def test_forecast_daily(
assert response == snapshot


@freeze_time("2022-10-04 01:00:00")
@freeze_time("2022-10-04 06:00:00-04:00")
async def test_forecast_daily_with_some_previous_days_data(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
) -> None:
"""Test basic forecast."""
await hass.config.async_set_time_zone("America/New_York")

ec_data = json.loads(
load_fixture("environment_canada/current_conditions_data.json")
Expand Down