This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

@@ -6,10 +6,10 @@ import pytest
from homeassistant.setup import async_setup_component
from homeassistant.const import CONF_PLATFORM, STATE_HOME, STATE_NOT_HOME
from homeassistant.components import (
device_tracker, light, device_sun_light_trigger)
from homeassistant.components import device_tracker, light, device_sun_light_trigger
from homeassistant.components.device_tracker.const import (
ENTITY_ID_FORMAT as DT_ENTITY_ID_FORMAT)
ENTITY_ID_FORMAT as DT_ENTITY_ID_FORMAT,
)
from homeassistant.util import dt as dt_util
from tests.common import async_fire_time_changed
@@ -19,42 +19,47 @@ from tests.components.light import common as common_light
@pytest.fixture
def scanner(hass):
"""Initialize components."""
scanner = getattr(
hass.components, 'test.device_tracker').get_scanner(None, None)
scanner = getattr(hass.components, "test.device_tracker").get_scanner(None, None)
scanner.reset()
scanner.come_home('DEV1')
scanner.come_home("DEV1")
getattr(hass.components, 'test.light').init()
getattr(hass.components, "test.light").init()
with patch(
'homeassistant.components.device_tracker.legacy.load_yaml_config_file',
"homeassistant.components.device_tracker.legacy.load_yaml_config_file",
return_value={
'device_1': {
'hide_if_away': False,
'mac': 'DEV1',
'name': 'Unnamed Device',
'picture': 'http://example.com/dev1.jpg',
'track': True,
'vendor': None
"device_1": {
"hide_if_away": False,
"mac": "DEV1",
"name": "Unnamed Device",
"picture": "http://example.com/dev1.jpg",
"track": True,
"vendor": None,
},
'device_2': {
'hide_if_away': False,
'mac': 'DEV2',
'name': 'Unnamed Device',
'picture': 'http://example.com/dev2.jpg',
'track': True,
'vendor': None}
}):
assert hass.loop.run_until_complete(async_setup_component(
hass, device_tracker.DOMAIN, {
device_tracker.DOMAIN: {CONF_PLATFORM: 'test'}
}))
"device_2": {
"hide_if_away": False,
"mac": "DEV2",
"name": "Unnamed Device",
"picture": "http://example.com/dev2.jpg",
"track": True,
"vendor": None,
},
},
):
assert hass.loop.run_until_complete(
async_setup_component(
hass,
device_tracker.DOMAIN,
{device_tracker.DOMAIN: {CONF_PLATFORM: "test"}},
)
)
assert hass.loop.run_until_complete(async_setup_component(
hass, light.DOMAIN, {
light.DOMAIN: {CONF_PLATFORM: 'test'}
}))
assert hass.loop.run_until_complete(
async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
)
return scanner
@@ -62,15 +67,15 @@ def scanner(hass):
async def test_lights_on_when_sun_sets(hass, scanner):
"""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):
with patch("homeassistant.util.dt.utcnow", return_value=test_time):
assert await async_setup_component(
hass, device_sun_light_trigger.DOMAIN, {
device_sun_light_trigger.DOMAIN: {}})
hass, device_sun_light_trigger.DOMAIN, {device_sun_light_trigger.DOMAIN: {}}
)
await common_light.async_turn_off(hass)
test_time = test_time.replace(hour=3)
with patch('homeassistant.util.dt.utcnow', return_value=test_time):
with patch("homeassistant.util.dt.utcnow", return_value=test_time):
async_fire_time_changed(hass, test_time)
await hass.async_block_till_done()
@@ -82,11 +87,10 @@ async def test_lights_turn_off_when_everyone_leaves(hass, scanner):
await common_light.async_turn_on(hass)
assert await async_setup_component(
hass, device_sun_light_trigger.DOMAIN, {
device_sun_light_trigger.DOMAIN: {}})
hass, device_sun_light_trigger.DOMAIN, {device_sun_light_trigger.DOMAIN: {}}
)
hass.states.async_set(device_tracker.ENTITY_ID_ALL_DEVICES,
STATE_NOT_HOME)
hass.states.async_set(device_tracker.ENTITY_ID_ALL_DEVICES, STATE_NOT_HOME)
await hass.async_block_till_done()
@@ -96,15 +100,14 @@ async def test_lights_turn_off_when_everyone_leaves(hass, scanner):
async def test_lights_turn_on_when_coming_home_after_sun_set(hass, scanner):
"""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):
with patch("homeassistant.util.dt.utcnow", return_value=test_time):
await common_light.async_turn_off(hass)
assert await async_setup_component(
hass, device_sun_light_trigger.DOMAIN, {
device_sun_light_trigger.DOMAIN: {}})
hass, device_sun_light_trigger.DOMAIN, {device_sun_light_trigger.DOMAIN: {}}
)
hass.states.async_set(
DT_ENTITY_ID_FORMAT.format('device_2'), STATE_HOME)
hass.states.async_set(DT_ENTITY_ID_FORMAT.format("device_2"), STATE_HOME)
await hass.async_block_till_done()
assert light.is_on(hass)