mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 09:23:17 -04:00
test(ecobee): use timezone-aware now in switch tests (#181987)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user