From d799b1aea6cce95d61c535bf9d6680b4e710fbae Mon Sep 17 00:00:00 2001 From: David Bonnes Date: Fri, 27 Sep 2024 12:44:47 +0100 Subject: [PATCH] Set the default time zone for evohome tests (#126679) --- tests/components/evohome/conftest.py | 16 +++++- .../evohome/snapshots/test_init.ambr | 54 +++++++++---------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/tests/components/evohome/conftest.py b/tests/components/evohome/conftest.py index 3192379f0a2b88..071e040d2a1d58 100644 --- a/tests/components/evohome/conftest.py +++ b/tests/components/evohome/conftest.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import AsyncGenerator, Callable -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from http import HTTPMethod from typing import TYPE_CHECKING, Any from unittest.mock import MagicMock, patch @@ -15,6 +15,7 @@ from homeassistant.components.evohome import CONF_PASSWORD, CONF_USERNAME, DOMAIN from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component +from homeassistant.util import dt as dt_util from homeassistant.util.json import JsonArrayType, JsonObjectType from .const import ACCESS_TOKEN, REFRESH_TOKEN, USERNAME @@ -121,6 +122,19 @@ async def setup_evohome( The class is mocked here to check the client was instantiated with the correct args. """ + # set the time zone as for the active evohome location + loc_idx: int = test_config.get("location_idx", 0) # type: ignore[assignment] + + try: + locn = user_locations_config_fixture(install)[loc_idx] + except IndexError: + if loc_idx == 0: + raise + locn = user_locations_config_fixture(install)[0] + + utc_offset: int = locn["locationInfo"]["timeZone"]["currentOffsetMinutes"] # type: ignore[assignment, call-overload, index] + dt_util.set_default_time_zone(timezone(timedelta(minutes=utc_offset))) + with ( patch("homeassistant.components.evohome.evo.EvohomeClient") as mock_client, patch("homeassistant.components.evohome.ev1.EvohomeClient", return_value=None), diff --git a/tests/components/evohome/snapshots/test_init.ambr b/tests/components/evohome/snapshots/test_init.ambr index 22be15f89f433e..53c04ac0667469 100644 --- a/tests/components/evohome/snapshots/test_init.ambr +++ b/tests/components/evohome/snapshots/test_init.ambr @@ -62,9 +62,9 @@ 'target_heat_temperature': 17.0, }), 'setpoints': dict({ - 'next_sp_from': '2024-07-10T14:10:00-07:00', + 'next_sp_from': '2024-07-10T22:10:00+01:00', 'next_sp_temp': 18.6, - 'this_sp_from': '2024-07-10T00:00:00-07:00', + 'this_sp_from': '2024-07-10T08:00:00+01:00', 'this_sp_temp': 16.0, }), 'temperature_status': dict({ @@ -110,9 +110,9 @@ 'target_heat_temperature': 17.0, }), 'setpoints': dict({ - 'next_sp_from': '2024-07-10T14:10:00-07:00', + 'next_sp_from': '2024-07-10T22:10:00+01:00', 'next_sp_temp': 18.6, - 'this_sp_from': '2024-07-10T00:00:00-07:00', + 'this_sp_from': '2024-07-10T08:00:00+01:00', 'this_sp_temp': 16.0, }), 'temperature_status': dict({ @@ -157,12 +157,12 @@ 'setpoint_status': dict({ 'setpoint_mode': 'TemporaryOverride', 'target_heat_temperature': 21.0, - 'until': '2022-03-07T11:00:00-08:00', + 'until': '2022-03-07T20:00:00+01:00', }), 'setpoints': dict({ - 'next_sp_from': '2024-07-10T14:10:00-07:00', + 'next_sp_from': '2024-07-10T22:10:00+01:00', 'next_sp_temp': 18.6, - 'this_sp_from': '2024-07-10T00:00:00-07:00', + 'this_sp_from': '2024-07-10T08:00:00+01:00', 'this_sp_temp': 16.0, }), 'temperature_status': dict({ @@ -205,9 +205,9 @@ 'target_heat_temperature': 17.0, }), 'setpoints': dict({ - 'next_sp_from': '2024-07-10T14:10:00-07:00', + 'next_sp_from': '2024-07-10T22:10:00+01:00', 'next_sp_temp': 18.6, - 'this_sp_from': '2024-07-10T00:00:00-07:00', + 'this_sp_from': '2024-07-10T08:00:00+01:00', 'this_sp_temp': 16.0, }), 'temperature_status': dict({ @@ -250,9 +250,9 @@ 'target_heat_temperature': 16.0, }), 'setpoints': dict({ - 'next_sp_from': '2024-07-10T14:10:00-07:00', + 'next_sp_from': '2024-07-10T22:10:00+01:00', 'next_sp_temp': 18.6, - 'this_sp_from': '2024-07-10T00:00:00-07:00', + 'this_sp_from': '2024-07-10T08:00:00+01:00', 'this_sp_temp': 16.0, }), 'temperature_status': dict({ @@ -295,9 +295,9 @@ 'target_heat_temperature': 16.0, }), 'setpoints': dict({ - 'next_sp_from': '2024-07-10T14:10:00-07:00', + 'next_sp_from': '2024-07-10T22:10:00+01:00', 'next_sp_temp': 18.6, - 'this_sp_from': '2024-07-10T00:00:00-07:00', + 'this_sp_from': '2024-07-10T08:00:00+01:00', 'this_sp_temp': 16.0, }), 'temperature_status': dict({ @@ -340,9 +340,9 @@ 'target_heat_temperature': 17.0, }), 'setpoints': dict({ - 'next_sp_from': '2024-07-10T14:10:00-07:00', + 'next_sp_from': '2024-07-10T22:10:00+01:00', 'next_sp_temp': 18.6, - 'this_sp_from': '2024-07-10T00:00:00-07:00', + 'this_sp_from': '2024-07-10T08:00:00+01:00', 'this_sp_temp': 16.0, }), 'temperature_status': dict({ @@ -380,9 +380,9 @@ ]), 'dhw_id': '3933910', 'setpoints': dict({ - 'next_sp_from': '2024-07-10T05:00:00-07:00', + 'next_sp_from': '2024-07-10T13:00:00+01:00', 'next_sp_state': 'Off', - 'this_sp_from': '2024-07-10T04:00:00-07:00', + 'this_sp_from': '2024-07-10T12:00:00+01:00', 'this_sp_state': 'On', }), 'state_status': dict({ @@ -909,9 +909,9 @@ 'target_heat_temperature': 21.5, }), 'setpoints': dict({ - 'next_sp_from': '2024-07-10T14:10:00-07:00', + 'next_sp_from': '2024-07-10T22:10:00+01:00', 'next_sp_temp': 18.6, - 'this_sp_from': '2024-07-10T00:00:00-07:00', + 'this_sp_from': '2024-07-10T08:00:00+01:00', 'this_sp_temp': 16.0, }), 'temperature_status': dict({ @@ -992,9 +992,9 @@ 'target_heat_temperature': 21.5, }), 'setpoints': dict({ - 'next_sp_from': '2024-07-10T12:10:00-07:00', + 'next_sp_from': '2024-07-10T22:10:00+03:00', 'next_sp_temp': 18.6, - 'this_sp_from': '2024-07-09T22:00:00-07:00', + 'this_sp_from': '2024-07-10T08:00:00+03:00', 'this_sp_temp': 16.0, }), 'temperature_status': dict({ @@ -1037,9 +1037,9 @@ 'target_heat_temperature': 21.5, }), 'setpoints': dict({ - 'next_sp_from': '2024-07-10T12:10:00-07:00', + 'next_sp_from': '2024-07-10T22:10:00+03:00', 'next_sp_temp': 18.6, - 'this_sp_from': '2024-07-09T22:00:00-07:00', + 'this_sp_from': '2024-07-10T08:00:00+03:00', 'this_sp_temp': 16.0, }), 'temperature_status': dict({ @@ -1123,9 +1123,9 @@ 'target_heat_temperature': 17.0, }), 'setpoints': dict({ - 'next_sp_from': '2024-07-10T14:10:00-07:00', + 'next_sp_from': '2024-07-10T22:10:00+01:00', 'next_sp_temp': 18.6, - 'this_sp_from': '2024-07-10T00:00:00-07:00', + 'this_sp_from': '2024-07-10T08:00:00+01:00', 'this_sp_temp': 16.0, }), 'temperature_status': dict({ @@ -1206,9 +1206,9 @@ 'target_heat_temperature': 15.0, }), 'setpoints': dict({ - 'next_sp_from': '2024-07-10T13:10:00-07:00', + 'next_sp_from': '2024-07-10T22:10:00+02:00', 'next_sp_temp': 18.6, - 'this_sp_from': '2024-07-09T23:00:00-07:00', + 'this_sp_from': '2024-07-10T08:00:00+02:00', 'this_sp_temp': 16.0, }), 'temperature_status': dict({