mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Migrate device_sun_light_trigger tests to use freezegun (#105520)
This commit is contained in:
parent
a66c9bb7b6
commit
319d6db55b
@ -2,6 +2,7 @@
|
||||
from datetime import datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import (
|
||||
@ -72,10 +73,12 @@ async def scanner(hass, enable_custom_integrations):
|
||||
return scanner
|
||||
|
||||
|
||||
async def test_lights_on_when_sun_sets(hass: HomeAssistant, scanner) -> None:
|
||||
async def test_lights_on_when_sun_sets(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, scanner
|
||||
) -> None:
|
||||
"""Test lights go on when there is someone home and the sun sets."""
|
||||
test_time = datetime(2017, 4, 5, 1, 2, 3, tzinfo=dt_util.UTC)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=test_time):
|
||||
freezer.move_to(test_time)
|
||||
assert await async_setup_component(
|
||||
hass, device_sun_light_trigger.DOMAIN, {device_sun_light_trigger.DOMAIN: {}}
|
||||
)
|
||||
@ -88,7 +91,7 @@ async def test_lights_on_when_sun_sets(hass: HomeAssistant, scanner) -> None:
|
||||
)
|
||||
|
||||
test_time = test_time.replace(hour=3)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=test_time):
|
||||
freezer.move_to(test_time)
|
||||
async_fire_time_changed(hass, test_time)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -128,11 +131,11 @@ async def test_lights_turn_off_when_everyone_leaves(
|
||||
|
||||
|
||||
async def test_lights_turn_on_when_coming_home_after_sun_set(
|
||||
hass: HomeAssistant, scanner
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, scanner
|
||||
) -> None:
|
||||
"""Test lights turn on when coming home after sun set."""
|
||||
test_time = datetime(2017, 4, 5, 3, 2, 3, tzinfo=dt_util.UTC)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=test_time):
|
||||
freezer.move_to(test_time)
|
||||
await hass.services.async_call(
|
||||
light.DOMAIN, light.SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "all"}, blocking=True
|
||||
)
|
||||
@ -152,14 +155,14 @@ async def test_lights_turn_on_when_coming_home_after_sun_set(
|
||||
|
||||
|
||||
async def test_lights_turn_on_when_coming_home_after_sun_set_person(
|
||||
hass: HomeAssistant, scanner
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, scanner
|
||||
) -> None:
|
||||
"""Test lights turn on when coming home after sun set."""
|
||||
device_1 = f"{DOMAIN}.device_1"
|
||||
device_2 = f"{DOMAIN}.device_2"
|
||||
|
||||
test_time = datetime(2017, 4, 5, 3, 2, 3, tzinfo=dt_util.UTC)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=test_time):
|
||||
freezer.move_to(test_time)
|
||||
await hass.services.async_call(
|
||||
light.DOMAIN, light.SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "all"}, blocking=True
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user