2016-06-02 06:38:19 +00:00
|
|
|
|
"""The tests for the Flux switch platform."""
|
2021-01-01 21:31:56 +00:00
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
2019-06-15 05:32:51 +00:00
|
|
|
|
import pytest
|
2016-06-02 06:38:19 +00:00
|
|
|
|
|
2019-12-09 13:14:40 +00:00
|
|
|
|
from homeassistant.components import light, switch
|
2018-10-31 08:10:28 +00:00
|
|
|
|
from homeassistant.const import (
|
2020-04-13 13:33:04 +00:00
|
|
|
|
ATTR_ENTITY_ID,
|
2019-07-31 19:25:30 +00:00
|
|
|
|
CONF_PLATFORM,
|
|
|
|
|
SERVICE_TURN_ON,
|
2019-12-09 13:14:40 +00:00
|
|
|
|
STATE_ON,
|
2019-07-31 19:25:30 +00:00
|
|
|
|
SUN_EVENT_SUNRISE,
|
|
|
|
|
)
|
2019-10-05 19:57:12 +00:00
|
|
|
|
from homeassistant.core import State
|
2019-12-09 13:14:40 +00:00
|
|
|
|
from homeassistant.setup import async_setup_component
|
2016-06-02 06:38:19 +00:00
|
|
|
|
import homeassistant.util.dt as dt_util
|
2016-10-08 18:27:35 +00:00
|
|
|
|
|
|
|
|
|
from tests.common import (
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert_setup_component,
|
|
|
|
|
async_fire_time_changed,
|
|
|
|
|
async_mock_service,
|
2019-10-05 19:57:12 +00:00
|
|
|
|
mock_restore_cache,
|
2019-07-31 19:25:30 +00:00
|
|
|
|
)
|
2016-06-02 06:38:19 +00:00
|
|
|
|
|
|
|
|
|
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async def test_valid_config(hass):
|
|
|
|
|
"""Test configuration."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
"switch",
|
|
|
|
|
{
|
|
|
|
|
"switch": {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
|
|
|
|
"lights": ["light.desk", "light.lamp"],
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-10-05 19:57:12 +00:00
|
|
|
|
state = hass.states.get("switch.flux")
|
|
|
|
|
assert state
|
|
|
|
|
assert state.state == "off"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_restore_state_last_on(hass):
|
|
|
|
|
"""Test restoring state when the last state is on."""
|
|
|
|
|
mock_restore_cache(hass, [State("switch.flux", "on")])
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
"switch",
|
|
|
|
|
{
|
|
|
|
|
"switch": {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
|
|
|
|
"lights": ["light.desk", "light.lamp"],
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-10-05 19:57:12 +00:00
|
|
|
|
|
|
|
|
|
state = hass.states.get("switch.flux")
|
|
|
|
|
assert state
|
|
|
|
|
assert state.state == "on"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_restore_state_last_off(hass):
|
|
|
|
|
"""Test restoring state when the last state is off."""
|
|
|
|
|
mock_restore_cache(hass, [State("switch.flux", "off")])
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
"switch",
|
|
|
|
|
{
|
|
|
|
|
"switch": {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
|
|
|
|
"lights": ["light.desk", "light.lamp"],
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-10-05 19:57:12 +00:00
|
|
|
|
|
|
|
|
|
state = hass.states.get("switch.flux")
|
|
|
|
|
assert state
|
|
|
|
|
assert state.state == "off"
|
|
|
|
|
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
async def test_valid_config_with_info(hass):
|
|
|
|
|
"""Test configuration."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
"switch",
|
|
|
|
|
{
|
|
|
|
|
"switch": {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
|
|
|
|
"lights": ["light.desk", "light.lamp"],
|
|
|
|
|
"stop_time": "22:59",
|
|
|
|
|
"start_time": "7:22",
|
|
|
|
|
"start_colortemp": "1000",
|
|
|
|
|
"sunset_colortemp": "2000",
|
|
|
|
|
"stop_colortemp": "4000",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_valid_config_no_name(hass):
|
|
|
|
|
"""Test configuration."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with assert_setup_component(1, "switch"):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
"switch",
|
|
|
|
|
{"switch": {"platform": "flux", "lights": ["light.desk", "light.lamp"]}},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2016-06-02 06:38:19 +00:00
|
|
|
|
|
|
|
|
|
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async def test_invalid_config_no_lights(hass):
|
|
|
|
|
"""Test configuration."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with assert_setup_component(0, "switch"):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, "switch", {"switch": {"platform": "flux", "name": "flux"}}
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2016-06-02 06:38:19 +00:00
|
|
|
|
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_when_switch_is_off(
|
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch when it is off."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
|
|
|
|
assert await async_setup_component(
|
2019-07-31 19:25:30 +00:00
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=10, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
|
assert not turn_on_calls
|
|
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_before_sunrise(
|
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch before sunrise."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=2, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=5)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 112
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
|
|
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_before_sunrise_known_location(
|
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch before sunrise."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
hass.config.latitude = 55.948372
|
|
|
|
|
hass.config.longitude = -3.199466
|
|
|
|
|
hass.config.elevation = 17
|
|
|
|
|
test_time = dt_util.utcnow().replace(
|
2019-07-31 19:25:30 +00:00
|
|
|
|
hour=2, minute=0, second=0, day=21, month=6, year=2019
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
# 'brightness': 255,
|
|
|
|
|
# 'disable_brightness_adjust': True,
|
|
|
|
|
# 'mode': 'rgb',
|
|
|
|
|
# 'interval': 120
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 112
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_after_sunrise_before_sunset(
|
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch after sunrise and before sunset."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=8, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 173
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.439, 0.37]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_after_sunset_before_stop(
|
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch after sunset and before stop."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=17, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
"stop_time": "22:00",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 146
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.506, 0.385]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_after_stop_before_sunrise(
|
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch after stop and before sunrise."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=23, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 112
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_with_custom_start_stop_times(
|
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux with custom start and stop times."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=17, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
"start_time": "6:00",
|
|
|
|
|
"stop_time": "23:30",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 147
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.504, 0.385]
|
|
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_before_sunrise_stop_next_day(
|
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch before sunrise.
|
|
|
|
|
|
|
|
|
|
This test has the stop_time on the next day (after midnight).
|
|
|
|
|
"""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=2, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
"stop_time": "01:00",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 112
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
2020-06-29 16:39:24 +00:00
|
|
|
|
async def test_flux_after_sunrise_before_sunset_stop_next_day(
|
2021-05-17 13:48:41 +00:00
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
2020-06-29 16:39:24 +00:00
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""
|
|
|
|
|
Test the flux switch after sunrise and before sunset.
|
|
|
|
|
|
|
|
|
|
This test has the stop_time on the next day (after midnight).
|
|
|
|
|
"""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=8, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
"stop_time": "01:00",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 173
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.439, 0.37]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
|
@pytest.mark.parametrize("x", [0, 1])
|
2020-06-29 16:39:24 +00:00
|
|
|
|
async def test_flux_after_sunset_before_midnight_stop_next_day(
|
2021-05-17 13:48:41 +00:00
|
|
|
|
hass, legacy_patchable_time, x, enable_custom_integrations
|
2020-06-29 16:39:24 +00:00
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch after sunset and before stop.
|
|
|
|
|
|
|
|
|
|
This test has the stop_time on the next day (after midnight).
|
|
|
|
|
"""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=23, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
"stop_time": "01:00",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 119
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.588, 0.386]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
2020-07-02 17:51:31 +00:00
|
|
|
|
async def test_flux_after_sunset_after_midnight_stop_next_day(
|
2021-05-17 13:48:41 +00:00
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
2020-07-02 17:51:31 +00:00
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch after sunset and before stop.
|
|
|
|
|
|
|
|
|
|
This test has the stop_time on the next day (after midnight).
|
|
|
|
|
"""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=00, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
"stop_time": "01:00",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 114
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.601, 0.382]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
2020-07-02 17:51:31 +00:00
|
|
|
|
async def test_flux_after_stop_before_sunrise_stop_next_day(
|
2021-05-17 13:48:41 +00:00
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
2020-07-02 17:51:31 +00:00
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch after stop and before sunrise.
|
|
|
|
|
|
|
|
|
|
This test has the stop_time on the next day (after midnight).
|
|
|
|
|
"""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=2, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
"stop_time": "01:00",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 112
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_with_custom_colortemps(
|
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux with custom start and stop colortemps."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=17, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
"start_colortemp": "1000",
|
|
|
|
|
"stop_colortemp": "6000",
|
|
|
|
|
"stop_time": "22:00",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 159
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.469, 0.378]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_with_custom_brightness(
|
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux with custom start and stop colortemps."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=17, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
"brightness": 255,
|
|
|
|
|
"stop_time": "22:00",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 255
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.506, 0.385]
|
|
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_with_multiple_lights(
|
|
|
|
|
hass, legacy_patchable_time, enable_custom_integrations
|
|
|
|
|
):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch with multiple light entities."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1, ent2, ent3 = platform.ENTITIES
|
2020-04-13 13:33:04 +00:00
|
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
light.DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ent2.entity_id}, blocking=True
|
|
|
|
|
)
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
light.DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ent3.entity_id}, blocking=True
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent2.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent3.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("xy_color") is None
|
|
|
|
|
assert state.attributes.get("brightness") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=12, minute=0, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
2020-02-25 01:54:20 +00:00
|
|
|
|
print(f"sunrise {sunrise_time}")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
return sunrise_time
|
2020-02-25 01:54:20 +00:00
|
|
|
|
print(f"sunset {sunset_time}")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id, ent2.entity_id, ent3.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 163
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.46, 0.376]
|
|
|
|
|
call = turn_on_calls[-2]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 163
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.46, 0.376]
|
|
|
|
|
call = turn_on_calls[-3]
|
|
|
|
|
assert call.data[light.ATTR_BRIGHTNESS] == 163
|
|
|
|
|
assert call.data[light.ATTR_XY_COLOR] == [0.46, 0.376]
|
|
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_with_mired(hass, legacy_patchable_time, enable_custom_integrations):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch´s mode mired."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("color_temp") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=8, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
"mode": "mired",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
assert call.data[light.ATTR_COLOR_TEMP] == 269
|
|
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
|
async def test_flux_with_rgb(hass, legacy_patchable_time, enable_custom_integrations):
|
2019-06-15 05:32:51 +00:00
|
|
|
|
"""Test the flux switch´s mode rgb."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
platform = getattr(hass.components, "test.light")
|
2019-06-15 05:32:51 +00:00
|
|
|
|
platform.init()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
2020-06-01 05:18:30 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
2019-09-15 07:50:17 +00:00
|
|
|
|
ent1 = platform.ENTITIES[0]
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
# Verify initial state of light
|
2019-09-15 07:50:17 +00:00
|
|
|
|
state = hass.states.get(ent1.entity_id)
|
2021-03-20 12:55:10 +00:00
|
|
|
|
assert state.state == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
|
assert state.attributes.get("color_temp") is None
|
2019-06-15 05:32:51 +00:00
|
|
|
|
|
|
|
|
|
test_time = dt_util.utcnow().replace(hour=8, minute=30, second=0)
|
|
|
|
|
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
|
|
|
|
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
|
|
|
|
|
|
|
|
|
def event_date(hass, event, now=None):
|
|
|
|
|
if event == SUN_EVENT_SUNRISE:
|
|
|
|
|
return sunrise_time
|
|
|
|
|
return sunset_time
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.flux.switch.dt_utcnow", return_value=test_time
|
|
|
|
|
), patch(
|
|
|
|
|
"homeassistant.components.flux.switch.get_astral_event_date",
|
|
|
|
|
side_effect=event_date,
|
|
|
|
|
):
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass,
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
{
|
|
|
|
|
switch.DOMAIN: {
|
|
|
|
|
"platform": "flux",
|
|
|
|
|
"name": "flux",
|
2019-09-15 07:50:17 +00:00
|
|
|
|
"lights": [ent1.entity_id],
|
2019-07-31 19:25:30 +00:00
|
|
|
|
"mode": "rgb",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
2020-09-30 09:07:51 +00:00
|
|
|
|
await hass.services.async_call(
|
|
|
|
|
switch.DOMAIN,
|
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
|
{ATTR_ENTITY_ID: "switch.flux"},
|
|
|
|
|
blocking=True,
|
|
|
|
|
)
|
2019-06-15 05:32:51 +00:00
|
|
|
|
async_fire_time_changed(hass, test_time)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
call = turn_on_calls[-1]
|
|
|
|
|
rgb = (255, 198, 152)
|
|
|
|
|
rounded_call = tuple(map(round, call.data[light.ATTR_RGB_COLOR]))
|
|
|
|
|
assert rounded_call == rgb
|