test(ecobee): use timezone-aware now in switch tests (#181987)

This commit is contained in:
Evan Severson
2026-09-19 09:19:09 +02:00
committed by GitHub
parent e0008c39f8
commit d307d49dbf
+8 -3
View File
@@ -1,9 +1,10 @@
"""The test for the ecobee thermostat switch module."""
import copy
from datetime import datetime, timedelta
from datetime import timedelta
from unittest import mock
from unittest.mock import patch
from zoneinfo import ZoneInfo
import pytest
@@ -15,12 +16,16 @@ from homeassistant.components.switch import (
)
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant
from homeassistant.util import dt as dt_util
from . import GENERIC_THERMOSTAT_INFO_WITH_HEATPUMP
from .common import setup_platform
VENTILATOR_20MIN_ID = "switch.ecobee_ventilator_20m_timer"
THERMOSTAT_ID = 0
THERMOSTAT_TIMEZONE = ZoneInfo(
GENERIC_THERMOSTAT_INFO_WITH_HEATPUMP["location"]["timeZone"]
)
@pytest.fixture(name="data")
@@ -43,7 +48,7 @@ async def test_ventilator_20min_when_on(hass: HomeAssistant, data) -> None:
"""Test the ventilator switch goes on."""
data.return_value["settings"]["ventilatorOffDateTime"] = (
datetime.now() + timedelta(days=1) # pylint: disable=home-assistant-enforce-naive-now
dt_util.now(THERMOSTAT_TIMEZONE) + timedelta(days=1)
).strftime(DATE_FORMAT)
with mock.patch("pyecobee.Ecobee.get_thermostat", data):
await setup_platform(hass, SWITCH_DOMAIN)
@@ -58,7 +63,7 @@ async def test_ventilator_20min_when_off(hass: HomeAssistant, data) -> None:
"""Test the ventilator switch goes on."""
data.return_value["settings"]["ventilatorOffDateTime"] = (
datetime.now() - timedelta(days=1) # pylint: disable=home-assistant-enforce-naive-now
dt_util.now(THERMOSTAT_TIMEZONE) - timedelta(days=1)
).strftime(DATE_FORMAT)
with mock.patch("pyecobee.Ecobee.get_thermostat", data):
await setup_platform(hass, SWITCH_DOMAIN)