mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add more tests
This commit is contained in:
parent
7f88813ba1
commit
c1c6e6d50e
@ -29,14 +29,13 @@ from homeassistant.components.light import (
|
||||
ATTR_WHITE,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
ColorMode,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
PERCENTAGE,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import CoreState, Event, HomeAssistant
|
||||
@ -57,7 +56,7 @@ async def test_light_basic(hass: HomeAssistant, hk_driver, events: list[Event])
|
||||
"""Test light with char state."""
|
||||
entity_id = "light.demo"
|
||||
|
||||
hass.states.async_set(entity_id, STATE_ON, {ATTR_SUPPORTED_FEATURES: 0})
|
||||
hass.states.async_set(entity_id, LightState.ON, {ATTR_SUPPORTED_FEATURES: 0})
|
||||
await hass.async_block_till_done()
|
||||
acc = Light(hass, hk_driver, "Light", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
@ -70,7 +69,7 @@ async def test_light_basic(hass: HomeAssistant, hk_driver, events: list[Event])
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_on.value == 1
|
||||
|
||||
hass.states.async_set(entity_id, STATE_OFF, {ATTR_SUPPORTED_FEATURES: 0})
|
||||
hass.states.async_set(entity_id, LightState.OFF, {ATTR_SUPPORTED_FEATURES: 0})
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_on.value == 0
|
||||
|
||||
@ -104,7 +103,7 @@ async def test_light_basic(hass: HomeAssistant, hk_driver, events: list[Event])
|
||||
assert len(events) == 1
|
||||
assert events[-1].data[ATTR_VALUE] == "Set state to 1"
|
||||
|
||||
hass.states.async_set(entity_id, STATE_ON)
|
||||
hass.states.async_set(entity_id, LightState.ON)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hk_driver.set_characteristics(
|
||||
@ -134,7 +133,7 @@ async def test_light_brightness(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 255},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -153,7 +152,7 @@ async def test_light_brightness(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 102},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -230,21 +229,21 @@ async def test_light_brightness(
|
||||
# in update_state
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 0},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_brightness.value == 1
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 255},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_brightness.value == 100
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 0},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -253,21 +252,21 @@ async def test_light_brightness(
|
||||
# Ensure floats are handled
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 55.66},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_brightness.value == 22
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 108.4},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_brightness.value == 43
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 0.0},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -282,7 +281,7 @@ async def test_light_color_temperature(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: ["color_temp"], ATTR_COLOR_TEMP_KELVIN: 5263},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -332,7 +331,7 @@ async def test_light_color_temperature_and_rgb_color(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{
|
||||
ATTR_SUPPORTED_COLOR_MODES: supported_color_modes,
|
||||
ATTR_COLOR_TEMP_KELVIN: 5263,
|
||||
@ -349,7 +348,7 @@ async def test_light_color_temperature_and_rgb_color(
|
||||
|
||||
assert hasattr(acc, "char_color_temp")
|
||||
|
||||
hass.states.async_set(entity_id, STATE_ON, {ATTR_COLOR_TEMP_KELVIN: 4464})
|
||||
hass.states.async_set(entity_id, LightState.ON, {ATTR_COLOR_TEMP_KELVIN: 4464})
|
||||
await hass.async_block_till_done()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
@ -357,7 +356,7 @@ async def test_light_color_temperature_and_rgb_color(
|
||||
assert acc.char_hue.value == 27
|
||||
assert acc.char_saturation.value == 27
|
||||
|
||||
hass.states.async_set(entity_id, STATE_ON, {ATTR_COLOR_TEMP_KELVIN: 2840})
|
||||
hass.states.async_set(entity_id, LightState.ON, {ATTR_COLOR_TEMP_KELVIN: 2840})
|
||||
await hass.async_block_till_done()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
@ -513,7 +512,7 @@ async def test_light_color_temperature_and_rgb_color(
|
||||
assert events[-1].data[ATTR_VALUE] == "set color at (80, 35)"
|
||||
|
||||
# Set from HASS
|
||||
hass.states.async_set(entity_id, STATE_ON, {ATTR_HS_COLOR: (100, 100)})
|
||||
hass.states.async_set(entity_id, LightState.ON, {ATTR_HS_COLOR: (100, 100)})
|
||||
await hass.async_block_till_done()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
@ -533,7 +532,7 @@ async def test_light_rgb_color(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_HS_COLOR: (260, 90)},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -654,7 +653,7 @@ async def test_light_rgb_with_color_temp(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, **state_props},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -774,7 +773,7 @@ async def test_light_rgbwx_with_color_temp_and_brightness(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, **state_props},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -833,7 +832,7 @@ async def test_light_rgb_or_w_lights(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGB, ColorMode.WHITE],
|
||||
ATTR_RGBW_COLOR: (128, 50, 0, 255),
|
||||
@ -917,7 +916,7 @@ async def test_light_rgb_or_w_lights(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGB, ColorMode.WHITE],
|
||||
ATTR_BRIGHTNESS: 255,
|
||||
@ -968,7 +967,7 @@ async def test_light_rgb_with_white_switch_to_temp(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, **state_props},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -1042,7 +1041,7 @@ async def test_light_rgb_with_hs_color_none(hass: HomeAssistant, hk_driver) -> N
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGB],
|
||||
ATTR_RGBWW_COLOR: (128, 50, 0, 255, 255),
|
||||
@ -1076,7 +1075,7 @@ async def test_light_rgbww_with_color_temp_conversion(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBWW],
|
||||
ATTR_RGBWW_COLOR: (128, 50, 0, 255, 255),
|
||||
@ -1154,7 +1153,7 @@ async def test_light_rgbww_with_color_temp_conversion(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBWW],
|
||||
ATTR_RGBWW_COLOR: (0, 0, 0, 128, 255),
|
||||
@ -1197,7 +1196,7 @@ async def test_light_rgbw_with_color_temp_conversion(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBW],
|
||||
ATTR_RGBWW_COLOR: (128, 50, 0, 255, 255),
|
||||
@ -1285,7 +1284,7 @@ async def test_light_set_brightness_and_color(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS],
|
||||
ATTR_BRIGHTNESS: 255,
|
||||
@ -1309,7 +1308,7 @@ async def test_light_set_brightness_and_color(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS], ATTR_BRIGHTNESS: 102},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -1317,7 +1316,7 @@ async def test_light_set_brightness_and_color(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS], ATTR_HS_COLOR: (4.5, 9.2)},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -1369,7 +1368,7 @@ async def test_light_min_max_mireds(hass: HomeAssistant, hk_driver) -> None:
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.COLOR_TEMP],
|
||||
ATTR_BRIGHTNESS: 255,
|
||||
@ -1391,7 +1390,7 @@ async def test_light_set_brightness_and_color_temp(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.COLOR_TEMP],
|
||||
ATTR_BRIGHTNESS: 255,
|
||||
@ -1414,7 +1413,7 @@ async def test_light_set_brightness_and_color_temp(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: [ColorMode.COLOR_TEMP], ATTR_BRIGHTNESS: 102},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -1422,7 +1421,7 @@ async def test_light_set_brightness_and_color_temp(
|
||||
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
{
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.COLOR_TEMP],
|
||||
ATTR_COLOR_TEMP_KELVIN: (4461),
|
||||
|
@ -11,8 +11,9 @@ from homeassistant.components.light import (
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
ColorMode,
|
||||
LightEntityFeature,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
|
||||
from homeassistant.const import ATTR_SUPPORTED_FEATURES
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@ -42,7 +43,7 @@ async def test_hmip_light(
|
||||
hass, mock_hap, entity_id, entity_name, device_model
|
||||
)
|
||||
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.state == LightState.ON
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.ONOFF
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.ONOFF]
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
@ -57,7 +58,7 @@ async def test_hmip_light(
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "on", False)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] is None
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.ONOFF]
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
@ -71,7 +72,7 @@ async def test_hmip_light(
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "on", True)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.state == LightState.ON
|
||||
|
||||
|
||||
async def test_hmip_notification_light(
|
||||
@ -89,7 +90,7 @@ async def test_hmip_notification_light(
|
||||
hass, mock_hap, entity_id, entity_name, device_model
|
||||
)
|
||||
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] is None
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.HS]
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == LightEntityFeature.TRANSITION
|
||||
@ -144,7 +145,7 @@ async def test_hmip_notification_light(
|
||||
hass, hmip_device, "simpleRGBColorState", RGBColorState.PURPLE, 2
|
||||
)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.state == LightState.ON
|
||||
assert ha_state.attributes[ATTR_COLOR_NAME] == RGBColorState.PURPLE
|
||||
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.HS
|
||||
@ -165,11 +166,11 @@ async def test_hmip_notification_light(
|
||||
}
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, 2)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", None, 2)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
assert not ha_state.attributes.get(ATTR_BRIGHTNESS)
|
||||
|
||||
|
||||
@ -188,7 +189,7 @@ async def test_hmip_dimmer(
|
||||
hass, mock_hap, entity_id, entity_name, device_model
|
||||
)
|
||||
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] is None
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
@ -211,7 +212,7 @@ async def test_hmip_dimmer(
|
||||
assert hmip_device.mock_calls[-1][1] == (1.0, 1)
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.state == LightState.ON
|
||||
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
|
||||
@ -225,11 +226,11 @@ async def test_hmip_dimmer(
|
||||
assert hmip_device.mock_calls[-1][1] == (0, 1)
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", None)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
assert not ha_state.attributes.get(ATTR_BRIGHTNESS)
|
||||
|
||||
|
||||
@ -248,7 +249,7 @@ async def test_hmip_light_measuring(
|
||||
hass, mock_hap, entity_id, entity_name, device_model
|
||||
)
|
||||
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] is None
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.ONOFF]
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
@ -263,7 +264,7 @@ async def test_hmip_light_measuring(
|
||||
await async_manipulate_test_data(hass, hmip_device, "on", True)
|
||||
await async_manipulate_test_data(hass, hmip_device, "currentPowerConsumption", 50)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.state == LightState.ON
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.ONOFF
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.ONOFF]
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
@ -276,7 +277,7 @@ async def test_hmip_light_measuring(
|
||||
assert hmip_device.mock_calls[-1][1] == ()
|
||||
await async_manipulate_test_data(hass, hmip_device, "on", False)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
|
||||
|
||||
async def test_hmip_wired_multi_dimmer(
|
||||
@ -294,7 +295,7 @@ async def test_hmip_wired_multi_dimmer(
|
||||
hass, mock_hap, entity_id, entity_name, device_model
|
||||
)
|
||||
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] is None
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
@ -317,7 +318,7 @@ async def test_hmip_wired_multi_dimmer(
|
||||
assert hmip_device.mock_calls[-1][1] == (0.39215686274509803, 1)
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, channel=1)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.state == LightState.ON
|
||||
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
|
||||
@ -331,11 +332,11 @@ async def test_hmip_wired_multi_dimmer(
|
||||
assert hmip_device.mock_calls[-1][1] == (0, 1)
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, channel=1)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", None, channel=1)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
assert not ha_state.attributes.get(ATTR_BRIGHTNESS)
|
||||
|
||||
|
||||
@ -354,7 +355,7 @@ async def test_hmip_din_rail_dimmer_3_channel1(
|
||||
hass, mock_hap, entity_id, entity_name, device_model
|
||||
)
|
||||
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.state == LightState.ON
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
service_call_counter = len(hmip_device.mock_calls)
|
||||
@ -376,7 +377,7 @@ async def test_hmip_din_rail_dimmer_3_channel1(
|
||||
assert hmip_device.mock_calls[-1][1] == (0.39215686274509803, 1)
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, channel=1)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.state == LightState.ON
|
||||
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
|
||||
@ -390,11 +391,11 @@ async def test_hmip_din_rail_dimmer_3_channel1(
|
||||
assert hmip_device.mock_calls[-1][1] == (0, 1)
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, channel=1)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", None, channel=1)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
assert not ha_state.attributes.get(ATTR_BRIGHTNESS)
|
||||
|
||||
|
||||
@ -413,7 +414,7 @@ async def test_hmip_din_rail_dimmer_3_channel2(
|
||||
hass, mock_hap, entity_id, entity_name, device_model
|
||||
)
|
||||
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.state == LightState.ON
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
service_call_counter = len(hmip_device.mock_calls)
|
||||
@ -435,7 +436,7 @@ async def test_hmip_din_rail_dimmer_3_channel2(
|
||||
assert hmip_device.mock_calls[-1][1] == (0.39215686274509803, 2)
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, channel=2)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.state == LightState.ON
|
||||
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
|
||||
@ -449,11 +450,11 @@ async def test_hmip_din_rail_dimmer_3_channel2(
|
||||
assert hmip_device.mock_calls[-1][1] == (0, 2)
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, channel=2)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", None, channel=2)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
assert not ha_state.attributes.get(ATTR_BRIGHTNESS)
|
||||
|
||||
|
||||
@ -472,7 +473,7 @@ async def test_hmip_din_rail_dimmer_3_channel3(
|
||||
hass, mock_hap, entity_id, entity_name, device_model
|
||||
)
|
||||
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.state == LightState.ON
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
service_call_counter = len(hmip_device.mock_calls)
|
||||
@ -494,7 +495,7 @@ async def test_hmip_din_rail_dimmer_3_channel3(
|
||||
assert hmip_device.mock_calls[-1][1] == (0.39215686274509803, 3)
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, channel=3)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.state == LightState.ON
|
||||
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
|
||||
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS
|
||||
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
|
||||
@ -508,9 +509,9 @@ async def test_hmip_din_rail_dimmer_3_channel3(
|
||||
assert hmip_device.mock_calls[-1][1] == (0, 3)
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, channel=3)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "dimLevel", None, channel=3)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert ha_state.state == LightState.OFF
|
||||
assert not ha_state.attributes.get(ATTR_BRIGHTNESS)
|
||||
|
@ -7,14 +7,12 @@ import pytest
|
||||
from pytest_unordered import unordered
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS, DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@ -44,13 +42,13 @@ async def test_light_attributes_state_update(
|
||||
assert hass.states.async_entity_ids("light") == unordered([entity_id])
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state == snapshot
|
||||
|
||||
hw_callback(HW_LIGHT_CHANGED, ["[02:08:01:01]", 50])
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state == snapshot
|
||||
|
||||
|
||||
@ -114,7 +112,7 @@ async def test_light_restore_brightness(
|
||||
hw_callback(HW_LIGHT_CHANGED, ["[02:08:01:01]", 50])
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 127
|
||||
|
||||
await hass.services.async_call(
|
||||
|
@ -18,8 +18,9 @@ from homeassistant.components.light import (
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_RGBW_COLOR,
|
||||
ColorMode,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.const import CONF_NAME, STATE_OFF, STATE_ON, EntityCategory
|
||||
from homeassistant.const import CONF_NAME, EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
@ -41,7 +42,7 @@ async def test_light_simple(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
}
|
||||
)
|
||||
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
# turn on light
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
@ -52,7 +53,7 @@ async def test_light_simple(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
await knx.assert_write(test_address, True)
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
color_mode=ColorMode.ONOFF,
|
||||
)
|
||||
# turn off light
|
||||
@ -63,14 +64,14 @@ async def test_light_simple(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_address, False)
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
# receive ON telegram
|
||||
await knx.receive_write(test_address, True)
|
||||
knx.assert_state("light.test", STATE_ON)
|
||||
knx.assert_state("light.test", LightState.ON)
|
||||
|
||||
# receive OFF telegram
|
||||
await knx.receive_write(test_address, False)
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
|
||||
# switch does not respond to read by default
|
||||
await knx.receive_read(test_address)
|
||||
@ -104,19 +105,19 @@ async def test_light_brightness(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
)
|
||||
await knx.assert_write(test_brightness, (80,))
|
||||
# state is still OFF until controller reports otherwise
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
await knx.receive_write(test_address, True)
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=80,
|
||||
color_mode=ColorMode.BRIGHTNESS,
|
||||
)
|
||||
# receive brightness changes from KNX
|
||||
await knx.receive_write(test_brightness_state, (255,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255)
|
||||
knx.assert_state("light.test", LightState.ON, brightness=255)
|
||||
await knx.receive_write(test_brightness, (128,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=128)
|
||||
knx.assert_state("light.test", LightState.ON, brightness=128)
|
||||
# turn off light via brightness
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
@ -125,7 +126,7 @@ async def test_light_brightness(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_address, False)
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
|
||||
|
||||
async def test_light_color_temp_absolute(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
@ -163,7 +164,7 @@ async def test_light_color_temp_absolute(hass: HomeAssistant, knx: KNXTestKit) -
|
||||
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=255,
|
||||
color_mode=ColorMode.COLOR_TEMP,
|
||||
color_temp=370,
|
||||
@ -177,12 +178,12 @@ async def test_light_color_temp_absolute(hass: HomeAssistant, knx: KNXTestKit) -
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_ct, (0x0F, 0xA0))
|
||||
knx.assert_state("light.test", STATE_ON, color_temp=250)
|
||||
knx.assert_state("light.test", LightState.ON, color_temp=250)
|
||||
# change color temperature from KNX
|
||||
await knx.receive_write(test_ct_state, (0x17, 0x70)) # 6000 Kelvin - 166 Mired
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
color_temp=166,
|
||||
color_temp_kelvin=6000,
|
||||
)
|
||||
@ -225,7 +226,7 @@ async def test_light_color_temp_relative(hass: HomeAssistant, knx: KNXTestKit) -
|
||||
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=255,
|
||||
color_mode=ColorMode.COLOR_TEMP,
|
||||
color_temp=250,
|
||||
@ -244,7 +245,7 @@ async def test_light_color_temp_relative(hass: HomeAssistant, knx: KNXTestKit) -
|
||||
await knx.assert_write(test_ct, (0x55,))
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
color_temp=300,
|
||||
color_temp_kelvin=3333,
|
||||
)
|
||||
@ -252,7 +253,7 @@ async def test_light_color_temp_relative(hass: HomeAssistant, knx: KNXTestKit) -
|
||||
await knx.receive_write(test_ct_state, (0xE6,)) # 3901 Kelvin - 90.1 % - 256 Mired
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
color_temp=256,
|
||||
color_temp_kelvin=3901,
|
||||
)
|
||||
@ -298,7 +299,7 @@ async def test_light_hs_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=255,
|
||||
color_mode=ColorMode.HS,
|
||||
hs_color=(360, 100),
|
||||
@ -311,7 +312,7 @@ async def test_light_hs_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_hue, (0xAA,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, hs_color=(240, 100))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=255, hs_color=(240, 100))
|
||||
|
||||
# change color from HA - only saturation
|
||||
await hass.services.async_call(
|
||||
@ -324,7 +325,7 @@ async def test_light_hs_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_sat, (0x80,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, hs_color=(240, 50))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=255, hs_color=(240, 50))
|
||||
|
||||
# change color from HA - hue and sat
|
||||
await hass.services.async_call(
|
||||
@ -335,15 +336,15 @@ async def test_light_hs_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
)
|
||||
await knx.assert_write(test_hue, (0xEA,))
|
||||
await knx.assert_write(test_sat, (0x96,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, hs_color=(330, 59))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=255, hs_color=(330, 59))
|
||||
|
||||
# change color and brightness from KNX
|
||||
await knx.receive_write(test_brightness, (0xB2,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=178, hs_color=(330, 59))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=178, hs_color=(330, 59))
|
||||
await knx.receive_write(test_hue, (0x7D,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=178, hs_color=(176, 59))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=178, hs_color=(176, 59))
|
||||
await knx.receive_write(test_sat, (0xD1,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=178, hs_color=(176, 82))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=178, hs_color=(176, 82))
|
||||
|
||||
|
||||
async def test_light_xyy_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
@ -373,7 +374,7 @@ async def test_light_xyy_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=204,
|
||||
color_mode=ColorMode.XY,
|
||||
xy_color=(0.8, 0.8),
|
||||
@ -386,7 +387,9 @@ async def test_light_xyy_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_xyy, (179, 116, 76, 139, 139, 3))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=139, xy_color=(0.701, 0.299))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=139, xy_color=(0.701, 0.299)
|
||||
)
|
||||
|
||||
# change brightness from HA
|
||||
await hass.services.async_call(
|
||||
@ -396,7 +399,9 @@ async def test_light_xyy_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_xyy, (0, 0, 0, 0, 255, 1))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, xy_color=(0.701, 0.299))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=255, xy_color=(0.701, 0.299)
|
||||
)
|
||||
|
||||
# change color from HA
|
||||
await hass.services.async_call(
|
||||
@ -406,17 +411,19 @@ async def test_light_xyy_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_xyy, (120, 16, 63, 59, 0, 2))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, xy_color=(0.469, 0.247))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=255, xy_color=(0.469, 0.247)
|
||||
)
|
||||
|
||||
# change color and brightness from KNX
|
||||
await knx.receive_write(test_xyy, (0x85, 0x1E, 0x4F, 0x5C, 0x19, 0x03))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=25, xy_color=(0.52, 0.31))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=25, xy_color=(0.52, 0.31))
|
||||
# change brightness from KNX
|
||||
await knx.receive_write(test_xyy, (0x00, 0x00, 0x00, 0x00, 0x80, 0x01))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=128, xy_color=(0.52, 0.31))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=128, xy_color=(0.52, 0.31))
|
||||
# change color from KNX
|
||||
await knx.receive_write(test_xyy, (0x2E, 0x14, 0x40, 0x00, 0x00, 0x02))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=128, xy_color=(0.18, 0.25))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=128, xy_color=(0.18, 0.25))
|
||||
|
||||
|
||||
async def test_light_xyy_color_with_brightness(
|
||||
@ -455,7 +462,7 @@ async def test_light_xyy_color_with_brightness(
|
||||
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=255, # brightness form xyy_color ignored when extra brightness GA is used
|
||||
color_mode=ColorMode.XY,
|
||||
xy_color=(0.8, 0.8),
|
||||
@ -468,7 +475,9 @@ async def test_light_xyy_color_with_brightness(
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_xyy, (179, 116, 76, 139, 0, 2))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, xy_color=(0.701, 0.299))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=255, xy_color=(0.701, 0.299)
|
||||
)
|
||||
|
||||
# change brightness from HA
|
||||
await hass.services.async_call(
|
||||
@ -478,7 +487,9 @@ async def test_light_xyy_color_with_brightness(
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_brightness, (0x8B,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=139, xy_color=(0.701, 0.299))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=139, xy_color=(0.701, 0.299)
|
||||
)
|
||||
|
||||
# change color and brightness from HA
|
||||
await hass.services.async_call(
|
||||
@ -490,13 +501,15 @@ async def test_light_xyy_color_with_brightness(
|
||||
await knx.assert_write(test_xyy, (120, 16, 63, 59, 255, 3))
|
||||
# brightness relies on brightness_state GA
|
||||
await knx.receive_write(test_brightness_state, (255,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, xy_color=(0.469, 0.247))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=255, xy_color=(0.469, 0.247)
|
||||
)
|
||||
|
||||
# change color and brightness from KNX
|
||||
await knx.receive_write(test_xyy, (0x85, 0x1E, 0x4F, 0x5C, 0x00, 0x02))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, xy_color=(0.52, 0.31))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=255, xy_color=(0.52, 0.31))
|
||||
await knx.receive_write(test_brightness, (21,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=21, xy_color=(0.52, 0.31))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=21, xy_color=(0.52, 0.31))
|
||||
|
||||
|
||||
async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
@ -541,7 +554,7 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
|
||||
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=255,
|
||||
color_mode=ColorMode.RGB,
|
||||
rgb_color=(255, 255, 255),
|
||||
@ -556,7 +569,7 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
|
||||
await knx.assert_write(test_red, (255,))
|
||||
await knx.assert_write(test_green, (0,))
|
||||
await knx.assert_write(test_blue, (0,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, rgb_color=(255, 0, 0))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=255, rgb_color=(255, 0, 0))
|
||||
|
||||
# change brightness from HA
|
||||
await hass.services.async_call(
|
||||
@ -568,7 +581,7 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
|
||||
await knx.assert_write(test_red, (200,))
|
||||
await knx.assert_write(test_green, (0,))
|
||||
await knx.assert_write(test_blue, (0,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=200, rgb_color=(255, 0, 0))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=200, rgb_color=(255, 0, 0))
|
||||
|
||||
# change only color, keep brightness from HA
|
||||
await hass.services.async_call(
|
||||
@ -580,7 +593,9 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
|
||||
await knx.assert_write(test_red, (200,))
|
||||
await knx.assert_write(test_green, (82,))
|
||||
await knx.assert_write(test_blue, (141,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=200, rgb_color=(255, 105, 180))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=200, rgb_color=(255, 105, 180)
|
||||
)
|
||||
|
||||
# change color and brightness from HA
|
||||
await hass.services.async_call(
|
||||
@ -592,18 +607,20 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
|
||||
await knx.assert_write(test_red, (100,))
|
||||
await knx.assert_write(test_green, (100,))
|
||||
await knx.assert_write(test_blue, (0,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=100, rgb_color=(255, 255, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=100, rgb_color=(255, 255, 0)
|
||||
)
|
||||
|
||||
# turn OFF from KNX
|
||||
await knx.receive_write(test_red, (0,))
|
||||
await knx.receive_write(test_green, (0,))
|
||||
await knx.receive_write(test_blue, (0,))
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
# turn ON from KNX
|
||||
await knx.receive_write(test_red, (0,))
|
||||
await knx.receive_write(test_green, (180,))
|
||||
await knx.receive_write(test_blue, (0,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=180, rgb_color=(0, 255, 0))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=180, rgb_color=(0, 255, 0))
|
||||
|
||||
# turn OFF from HA
|
||||
await hass.services.async_call(
|
||||
@ -615,7 +632,7 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
|
||||
await knx.assert_write(test_red, (0,))
|
||||
await knx.assert_write(test_green, (0,))
|
||||
await knx.assert_write(test_blue, (0,))
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
|
||||
# turn ON from HA
|
||||
await hass.services.async_call(
|
||||
@ -628,7 +645,9 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
|
||||
await knx.assert_write(test_red, (255,))
|
||||
await knx.assert_write(test_green, (255,))
|
||||
await knx.assert_write(test_blue, (255,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, rgb_color=(255, 255, 255))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=255, rgb_color=(255, 255, 255)
|
||||
)
|
||||
|
||||
# turn ON with brightness only from HA - defaults to white
|
||||
await knx.receive_write(test_red, (0,))
|
||||
@ -697,7 +716,7 @@ async def test_light_rgbw_individual(
|
||||
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=255,
|
||||
color_mode=ColorMode.RGBW,
|
||||
rgbw_color=(0, 0, 0, 255),
|
||||
@ -713,7 +732,9 @@ async def test_light_rgbw_individual(
|
||||
await knx.assert_write(test_green, (0,))
|
||||
await knx.assert_write(test_blue, (0,))
|
||||
await knx.assert_write(test_white, (0,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, rgbw_color=(255, 0, 0, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=255, rgbw_color=(255, 0, 0, 0)
|
||||
)
|
||||
|
||||
# change brightness from HA
|
||||
await hass.services.async_call(
|
||||
@ -726,7 +747,9 @@ async def test_light_rgbw_individual(
|
||||
await knx.assert_write(test_green, (0,))
|
||||
await knx.assert_write(test_blue, (0,))
|
||||
await knx.assert_write(test_white, (0,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=200, rgbw_color=(255, 0, 0, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=200, rgbw_color=(255, 0, 0, 0)
|
||||
)
|
||||
|
||||
# change only color, keep brightness from HA
|
||||
await hass.services.async_call(
|
||||
@ -741,7 +764,7 @@ async def test_light_rgbw_individual(
|
||||
await knx.assert_write(test_white, (139,))
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=200,
|
||||
rgb_color=(255, 104, 179), # minor rounding error - expected (255, 105, 180)
|
||||
rgbw_color=(255, 0, 127, 177), # expected (255, 0, 128, 178)
|
||||
@ -759,24 +782,26 @@ async def test_light_rgbw_individual(
|
||||
await knx.assert_write(test_blue, (0,))
|
||||
await knx.assert_write(test_white, (0,))
|
||||
knx.assert_state(
|
||||
"light.test", STATE_ON, brightness=100, rgbw_color=(255, 255, 0, 0)
|
||||
"light.test", LightState.ON, brightness=100, rgbw_color=(255, 255, 0, 0)
|
||||
)
|
||||
|
||||
# turn OFF from KNX
|
||||
await knx.receive_write(test_red, (0,))
|
||||
await knx.receive_write(test_green, (0,))
|
||||
# # individual color debounce takes 0.2 seconds if not all 4 addresses received
|
||||
knx.assert_state("light.test", STATE_ON)
|
||||
knx.assert_state("light.test", LightState.ON)
|
||||
freezer.tick(timedelta(seconds=XknxLight.DEBOUNCE_TIMEOUT))
|
||||
async_fire_time_changed(hass)
|
||||
await knx.xknx.task_registry.block_till_done()
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
# turn ON from KNX
|
||||
await knx.receive_write(test_red, (0,))
|
||||
await knx.receive_write(test_green, (180,))
|
||||
await knx.receive_write(test_blue, (0,))
|
||||
await knx.receive_write(test_white, (0,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=180, rgbw_color=(0, 255, 0, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=180, rgbw_color=(0, 255, 0, 0)
|
||||
)
|
||||
|
||||
# turn OFF from HA
|
||||
await hass.services.async_call(
|
||||
@ -789,7 +814,7 @@ async def test_light_rgbw_individual(
|
||||
await knx.assert_write(test_green, (0,))
|
||||
await knx.assert_write(test_blue, (0,))
|
||||
await knx.assert_write(test_white, (0,))
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
|
||||
# turn ON from HA
|
||||
await hass.services.async_call(
|
||||
@ -804,7 +829,7 @@ async def test_light_rgbw_individual(
|
||||
await knx.assert_write(test_blue, (255,))
|
||||
await knx.assert_write(test_white, (255,))
|
||||
knx.assert_state(
|
||||
"light.test", STATE_ON, brightness=255, rgbw_color=(255, 255, 255, 255)
|
||||
"light.test", LightState.ON, brightness=255, rgbw_color=(255, 255, 255, 255)
|
||||
)
|
||||
|
||||
# turn ON with brightness only from HA - defaults to white
|
||||
@ -851,7 +876,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=255,
|
||||
color_mode=ColorMode.RGB,
|
||||
rgb_color=(255, 255, 255),
|
||||
@ -864,7 +889,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_rgb, (255, 0, 0))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, rgb_color=(255, 0, 0))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=255, rgb_color=(255, 0, 0))
|
||||
|
||||
# change brightness from HA
|
||||
await hass.services.async_call(
|
||||
@ -874,7 +899,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_rgb, (200, 0, 0))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=200, rgb_color=(255, 0, 0))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=200, rgb_color=(255, 0, 0))
|
||||
|
||||
# change color, keep brightness from HA
|
||||
await hass.services.async_call(
|
||||
@ -886,7 +911,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
await knx.assert_write(test_rgb, (200, 82, 141))
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=200,
|
||||
rgb_color=(255, 105, 180),
|
||||
)
|
||||
@ -898,17 +923,19 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_rgb, (100, 100, 0))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=100, rgb_color=(255, 255, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=100, rgb_color=(255, 255, 0)
|
||||
)
|
||||
|
||||
# turn OFF from KNX
|
||||
await knx.receive_write(test_address_state, False)
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
# receive color update from KNX - still OFF
|
||||
await knx.receive_write(test_rgb, (0, 180, 0))
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
# turn ON from KNX - include color update
|
||||
await knx.receive_write(test_address_state, True)
|
||||
knx.assert_state("light.test", STATE_ON, brightness=180, rgb_color=(0, 255, 0))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=180, rgb_color=(0, 255, 0))
|
||||
|
||||
# turn OFF from HA
|
||||
await hass.services.async_call(
|
||||
@ -918,7 +945,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_address, False)
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
|
||||
# turn ON from HA
|
||||
await hass.services.async_call(
|
||||
@ -929,7 +956,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
)
|
||||
# color will be restored in no other state was received
|
||||
await knx.assert_write(test_address, True)
|
||||
knx.assert_state("light.test", STATE_ON, brightness=180, rgb_color=(0, 255, 0))
|
||||
knx.assert_state("light.test", LightState.ON, brightness=180, rgb_color=(0, 255, 0))
|
||||
|
||||
|
||||
async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
@ -959,7 +986,7 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=255,
|
||||
color_mode=ColorMode.RGBW,
|
||||
rgbw_color=(255, 101, 102, 103),
|
||||
@ -972,7 +999,9 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_rgbw, (0xFF, 0x00, 0x00, 0x00, 0x00, 0x0F))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, rgbw_color=(255, 0, 0, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=255, rgbw_color=(255, 0, 0, 0)
|
||||
)
|
||||
|
||||
# change brightness from HA
|
||||
await hass.services.async_call(
|
||||
@ -982,7 +1011,9 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_rgbw, (0xC8, 0x00, 0x00, 0x00, 0x00, 0x0F))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=200, rgbw_color=(255, 0, 0, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=200, rgbw_color=(255, 0, 0, 0)
|
||||
)
|
||||
|
||||
# change color, keep brightness from HA
|
||||
await hass.services.async_call(
|
||||
@ -994,7 +1025,7 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
await knx.assert_write(test_rgbw, (200, 0, 100, 139, 0x00, 0x0F))
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=200,
|
||||
rgb_color=(255, 104, 179), # minor rounding error - expected (255, 105, 180)
|
||||
rgbw_color=(255, 0, 127, 177), # expected (255, 0, 128, 178)
|
||||
@ -1008,18 +1039,20 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
)
|
||||
await knx.assert_write(test_rgbw, (100, 100, 0, 0, 0x00, 0x0F))
|
||||
knx.assert_state(
|
||||
"light.test", STATE_ON, brightness=100, rgbw_color=(255, 255, 0, 0)
|
||||
"light.test", LightState.ON, brightness=100, rgbw_color=(255, 255, 0, 0)
|
||||
)
|
||||
|
||||
# turn OFF from KNX
|
||||
await knx.receive_write(test_address_state, False)
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
# receive color update from KNX - still OFF
|
||||
await knx.receive_write(test_rgbw, (0, 180, 0, 0, 0x00, 0x0F))
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
# turn ON from KNX - include color update
|
||||
await knx.receive_write(test_address_state, True)
|
||||
knx.assert_state("light.test", STATE_ON, brightness=180, rgbw_color=(0, 255, 0, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=180, rgbw_color=(0, 255, 0, 0)
|
||||
)
|
||||
|
||||
# turn OFF from HA
|
||||
await hass.services.async_call(
|
||||
@ -1029,7 +1062,7 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_address, False)
|
||||
knx.assert_state("light.test", STATE_OFF)
|
||||
knx.assert_state("light.test", LightState.OFF)
|
||||
|
||||
# turn ON from HA
|
||||
await hass.services.async_call(
|
||||
@ -1040,7 +1073,9 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
)
|
||||
# color will be restored if no other state was received
|
||||
await knx.assert_write(test_address, True)
|
||||
knx.assert_state("light.test", STATE_ON, brightness=180, rgbw_color=(0, 255, 0, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=180, rgbw_color=(0, 255, 0, 0)
|
||||
)
|
||||
|
||||
|
||||
async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
@ -1076,7 +1111,7 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
|
||||
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=255,
|
||||
color_mode=ColorMode.RGBW,
|
||||
rgbw_color=(255, 101, 102, 103),
|
||||
@ -1089,10 +1124,14 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_rgbw, (0xFF, 0x00, 0x00, 0x00, 0x00, 0x0F))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=255, rgbw_color=(255, 0, 0, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=255, rgbw_color=(255, 0, 0, 0)
|
||||
)
|
||||
# # update from dedicated brightness state
|
||||
await knx.receive_write(test_brightness_state, (0xF0,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=240, rgbw_color=(255, 0, 0, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=240, rgbw_color=(255, 0, 0, 0)
|
||||
)
|
||||
|
||||
# single encoded brightness - at least one primary color = 255
|
||||
# # change brightness from HA
|
||||
@ -1103,7 +1142,9 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write(test_brightness, (128,))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=128, rgbw_color=(255, 0, 0, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=128, rgbw_color=(255, 0, 0, 0)
|
||||
)
|
||||
# # change color and brightness from HA
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
@ -1115,7 +1156,7 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
|
||||
await knx.assert_write(test_brightness, (128,))
|
||||
knx.assert_state(
|
||||
"light.test",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
brightness=128,
|
||||
rgb_color=(255, 105, 180),
|
||||
rgbw_color=(255, 0, 128, 178),
|
||||
@ -1125,7 +1166,9 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
|
||||
# brightness is handled by dedicated brightness address only
|
||||
# # from dedicated rgbw state
|
||||
await knx.receive_write(test_rgbw_state, (0xC8, 0x00, 0x00, 0x00, 0x00, 0x0F))
|
||||
knx.assert_state("light.test", STATE_ON, brightness=128, rgbw_color=(200, 0, 0, 0))
|
||||
knx.assert_state(
|
||||
"light.test", LightState.ON, brightness=128, rgbw_color=(200, 0, 0, 0)
|
||||
)
|
||||
# # from HA - only color
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
@ -1135,7 +1178,7 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
|
||||
)
|
||||
await knx.assert_write(test_rgbw, (20, 30, 40, 50, 0x00, 0x0F))
|
||||
knx.assert_state(
|
||||
"light.test", STATE_ON, brightness=128, rgbw_color=(20, 30, 40, 50)
|
||||
"light.test", LightState.ON, brightness=128, rgbw_color=(20, 30, 40, 50)
|
||||
)
|
||||
# # from HA - brightness and color
|
||||
await hass.services.async_call(
|
||||
@ -1151,7 +1194,7 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
|
||||
await knx.assert_write(test_rgbw, (100, 200, 55, 12, 0x00, 0x0F))
|
||||
await knx.assert_write(test_brightness, (50,))
|
||||
knx.assert_state(
|
||||
"light.test", STATE_ON, brightness=50, rgbw_color=(100, 200, 55, 12)
|
||||
"light.test", LightState.ON, brightness=50, rgbw_color=(100, 200, 55, 12)
|
||||
)
|
||||
|
||||
|
||||
@ -1175,7 +1218,7 @@ async def test_light_ui_create(
|
||||
await knx.assert_read("2/2/2")
|
||||
await knx.receive_response("2/2/2", True)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state is STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -1217,7 +1260,7 @@ async def test_light_ui_color_temp(
|
||||
)
|
||||
await knx.assert_write("3/3/3", raw_ct)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state is STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == pytest.approx(4200, abs=1)
|
||||
|
||||
|
||||
@ -1235,7 +1278,7 @@ async def test_light_ui_load(
|
||||
await knx.assert_read("1/0/45", response=True, ignore_order=True)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state is STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
entity = entity_registry.async_get("light.test")
|
||||
assert entity.entity_category is EntityCategory.CONFIG
|
||||
|
@ -21,13 +21,12 @@ from homeassistant.components.light import (
|
||||
ATTR_XY_COLOR,
|
||||
SCAN_INTERVAL,
|
||||
ColorMode,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -70,7 +69,7 @@ async def mock_light(
|
||||
async def test_init(hass: HomeAssistant, mock_light: MagicMock) -> None:
|
||||
"""Test platform setup."""
|
||||
state = hass.states.get("light.bedroom")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert dict(state.attributes) == {
|
||||
ATTR_FRIENDLY_NAME: "Bedroom",
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBW],
|
||||
@ -198,7 +197,7 @@ async def test_light_update(hass: HomeAssistant, mock_light: MagicMock) -> None:
|
||||
utcnow = dt_util.utcnow()
|
||||
|
||||
state = hass.states.get("light.bedroom")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert dict(state.attributes) == {
|
||||
ATTR_FRIENDLY_NAME: "Bedroom",
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBW],
|
||||
@ -232,7 +231,7 @@ async def test_light_update(hass: HomeAssistant, mock_light: MagicMock) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.bedroom")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert dict(state.attributes) == {
|
||||
ATTR_FRIENDLY_NAME: "Bedroom",
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBW],
|
||||
@ -252,7 +251,7 @@ async def test_light_update(hass: HomeAssistant, mock_light: MagicMock) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.bedroom")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert dict(state.attributes) == {
|
||||
ATTR_FRIENDLY_NAME: "Bedroom",
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBW],
|
||||
@ -272,7 +271,7 @@ async def test_light_update(hass: HomeAssistant, mock_light: MagicMock) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.bedroom")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert dict(state.attributes) == {
|
||||
ATTR_FRIENDLY_NAME: "Bedroom",
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBW],
|
||||
|
@ -12,13 +12,12 @@ from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_TRANSITION,
|
||||
DOMAIN as DOMAIN_LIGHT,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
Platform,
|
||||
)
|
||||
@ -66,7 +65,7 @@ async def test_output_turn_on(hass: HomeAssistant, entry: MockConfigEntry) -> No
|
||||
|
||||
state = hass.states.get(LIGHT_OUTPUT1)
|
||||
assert state is not None
|
||||
assert state.state != STATE_ON
|
||||
assert state.state != LightState.ON
|
||||
|
||||
# command success
|
||||
dim_output.reset_mock(return_value=True)
|
||||
@ -83,7 +82,7 @@ async def test_output_turn_on(hass: HomeAssistant, entry: MockConfigEntry) -> No
|
||||
|
||||
state = hass.states.get(LIGHT_OUTPUT1)
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
|
||||
async def test_output_turn_on_with_attributes(
|
||||
@ -110,7 +109,7 @@ async def test_output_turn_on_with_attributes(
|
||||
|
||||
state = hass.states.get(LIGHT_OUTPUT1)
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
|
||||
async def test_output_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> None:
|
||||
@ -119,7 +118,7 @@ async def test_output_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> N
|
||||
|
||||
with patch.object(MockModuleConnection, "dim_output") as dim_output:
|
||||
state = hass.states.get(LIGHT_OUTPUT1)
|
||||
state.state = STATE_ON
|
||||
state.state = LightState.ON
|
||||
|
||||
# command failed
|
||||
dim_output.return_value = False
|
||||
@ -135,7 +134,7 @@ async def test_output_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> N
|
||||
|
||||
state = hass.states.get(LIGHT_OUTPUT1)
|
||||
assert state is not None
|
||||
assert state.state != STATE_OFF
|
||||
assert state.state != LightState.OFF
|
||||
|
||||
# command success
|
||||
dim_output.reset_mock(return_value=True)
|
||||
@ -152,7 +151,7 @@ async def test_output_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> N
|
||||
|
||||
state = hass.states.get(LIGHT_OUTPUT1)
|
||||
assert state is not None
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
|
||||
async def test_output_turn_off_with_attributes(
|
||||
@ -165,7 +164,7 @@ async def test_output_turn_off_with_attributes(
|
||||
dim_output.return_value = True
|
||||
|
||||
state = hass.states.get(LIGHT_OUTPUT1)
|
||||
state.state = STATE_ON
|
||||
state.state = LightState.ON
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN_LIGHT,
|
||||
@ -181,7 +180,7 @@ async def test_output_turn_off_with_attributes(
|
||||
|
||||
state = hass.states.get(LIGHT_OUTPUT1)
|
||||
assert state is not None
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
|
||||
async def test_relay_turn_on(hass: HomeAssistant, entry: MockConfigEntry) -> None:
|
||||
@ -206,7 +205,7 @@ async def test_relay_turn_on(hass: HomeAssistant, entry: MockConfigEntry) -> Non
|
||||
|
||||
state = hass.states.get(LIGHT_RELAY1)
|
||||
assert state is not None
|
||||
assert state.state != STATE_ON
|
||||
assert state.state != LightState.ON
|
||||
|
||||
# command success
|
||||
control_relays.reset_mock(return_value=True)
|
||||
@ -223,7 +222,7 @@ async def test_relay_turn_on(hass: HomeAssistant, entry: MockConfigEntry) -> Non
|
||||
|
||||
state = hass.states.get(LIGHT_RELAY1)
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
|
||||
async def test_relay_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> None:
|
||||
@ -235,7 +234,7 @@ async def test_relay_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> No
|
||||
states[0] = RelayStateModifier.OFF
|
||||
|
||||
state = hass.states.get(LIGHT_RELAY1)
|
||||
state.state = STATE_ON
|
||||
state.state = LightState.ON
|
||||
|
||||
# command failed
|
||||
control_relays.return_value = False
|
||||
@ -251,7 +250,7 @@ async def test_relay_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> No
|
||||
|
||||
state = hass.states.get(LIGHT_RELAY1)
|
||||
assert state is not None
|
||||
assert state.state != STATE_OFF
|
||||
assert state.state != LightState.OFF
|
||||
|
||||
# command success
|
||||
control_relays.reset_mock(return_value=True)
|
||||
@ -268,7 +267,7 @@ async def test_relay_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> No
|
||||
|
||||
state = hass.states.get(LIGHT_RELAY1)
|
||||
assert state is not None
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
|
||||
async def test_pushed_output_status_change(
|
||||
@ -287,7 +286,7 @@ async def test_pushed_output_status_change(
|
||||
|
||||
state = hass.states.get(LIGHT_OUTPUT1)
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 127
|
||||
|
||||
# push status "off"
|
||||
@ -297,7 +296,7 @@ async def test_pushed_output_status_change(
|
||||
|
||||
state = hass.states.get(LIGHT_OUTPUT1)
|
||||
assert state is not None
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
|
||||
async def test_pushed_relay_status_change(
|
||||
@ -318,7 +317,7 @@ async def test_pushed_relay_status_change(
|
||||
|
||||
state = hass.states.get(LIGHT_RELAY1)
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
# push status "off"
|
||||
states[0] = False
|
||||
@ -328,7 +327,7 @@ async def test_pushed_relay_status_change(
|
||||
|
||||
state = hass.states.get(LIGHT_RELAY1)
|
||||
assert state is not None
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
|
||||
async def test_unload_config_entry(hass: HomeAssistant, entry: MockConfigEntry) -> None:
|
||||
|
@ -43,14 +43,9 @@ from homeassistant.components.light import (
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
ColorMode,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_HOST,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
@ -732,7 +727,7 @@ async def test_matrix_flame_morph_effects(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
assert len(bulb.set_power.calls) == 1
|
||||
assert len(bulb.set_tile_effect.calls) == 1
|
||||
@ -791,7 +786,7 @@ async def test_matrix_flame_morph_effects(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
assert len(bulb.set_power.calls) == 1
|
||||
assert len(bulb.set_tile_effect.calls) == 1
|
||||
@ -864,7 +859,7 @@ async def test_sky_effect(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
assert len(bulb.set_power.calls) == 1
|
||||
assert len(bulb.set_tile_effect.calls) == 1
|
||||
@ -922,7 +917,7 @@ async def test_sky_effect(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
assert len(bulb.set_power.calls) == 1
|
||||
assert len(bulb.set_tile_effect.calls) == 1
|
||||
@ -1010,7 +1005,7 @@ async def test_lightstrip_move_effect(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
assert len(bulb.set_power.calls) == 1
|
||||
assert len(bulb.set_extended_color_zones.calls) == 1
|
||||
@ -1308,7 +1303,7 @@ async def test_config_zoned_light_strip_fails(
|
||||
await async_setup_component(hass, lifx.DOMAIN, {lifx.DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
assert entity_registry.async_get(entity_id).unique_id == SERIAL
|
||||
assert hass.states.get(entity_id).state == STATE_OFF
|
||||
assert hass.states.get(entity_id).state == LightState.OFF
|
||||
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=30))
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
@ -1356,14 +1351,14 @@ async def test_legacy_zoned_light_strip(
|
||||
await async_setup_component(hass, lifx.DOMAIN, {lifx.DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
assert entity_registry.async_get(entity_id).unique_id == SERIAL
|
||||
assert hass.states.get(entity_id).state == STATE_OFF
|
||||
assert hass.states.get(entity_id).state == LightState.OFF
|
||||
# 1 to get the number of zones
|
||||
# 2 get populate the zones
|
||||
assert get_color_zones_mock.call_count == 3
|
||||
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=30))
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(entity_id).state == STATE_OFF
|
||||
assert hass.states.get(entity_id).state == LightState.OFF
|
||||
# 2 get populate the zones
|
||||
assert get_color_zones_mock.call_count == 5
|
||||
|
||||
@ -1385,7 +1380,7 @@ async def test_white_light_fails(
|
||||
await async_setup_component(hass, lifx.DOMAIN, {lifx.DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
assert entity_registry.async_get(entity_id).unique_id == SERIAL
|
||||
assert hass.states.get(entity_id).state == STATE_OFF
|
||||
assert hass.states.get(entity_id).state == LightState.OFF
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
|
||||
@ -2013,4 +2008,4 @@ async def test_light_strip_zones_not_populated_yet(hass: HomeAssistant) -> None:
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=30))
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
@ -8,8 +8,8 @@ from pytest_unordered import unordered
|
||||
|
||||
from homeassistant.components import automation
|
||||
from homeassistant.components.device_automation import DeviceAutomationType
|
||||
from homeassistant.components.light import DOMAIN
|
||||
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON, EntityCategory
|
||||
from homeassistant.components.light import DOMAIN, LightState
|
||||
from homeassistant.const import CONF_PLATFORM, EntityCategory
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
||||
@ -192,7 +192,7 @@ async def test_if_state(
|
||||
DOMAIN, "test", "5678", device_id=device_entry.id
|
||||
)
|
||||
|
||||
hass.states.async_set(entry.entity_id, STATE_ON)
|
||||
hass.states.async_set(entry.entity_id, LightState.ON)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@ -253,7 +253,7 @@ async def test_if_state(
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data["some"] == "is_on event - test_event1"
|
||||
|
||||
hass.states.async_set(entry.entity_id, STATE_OFF)
|
||||
hass.states.async_set(entry.entity_id, LightState.OFF)
|
||||
hass.bus.async_fire("test_event1")
|
||||
hass.bus.async_fire("test_event2")
|
||||
await hass.async_block_till_done()
|
||||
@ -279,7 +279,7 @@ async def test_if_state_legacy(
|
||||
DOMAIN, "test", "5678", device_id=device_entry.id
|
||||
)
|
||||
|
||||
hass.states.async_set(entry.entity_id, STATE_ON)
|
||||
hass.states.async_set(entry.entity_id, LightState.ON)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@ -338,7 +338,7 @@ async def test_if_fires_on_for_condition(
|
||||
DOMAIN, "test", "5678", device_id=device_entry.id
|
||||
)
|
||||
|
||||
hass.states.async_set(entry.entity_id, STATE_ON)
|
||||
hass.states.async_set(entry.entity_id, LightState.ON)
|
||||
|
||||
point1 = dt_util.utcnow()
|
||||
point2 = point1 + timedelta(seconds=10)
|
||||
@ -390,7 +390,7 @@ async def test_if_fires_on_for_condition(
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == 0
|
||||
|
||||
hass.states.async_set(entry.entity_id, STATE_OFF)
|
||||
hass.states.async_set(entry.entity_id, LightState.OFF)
|
||||
hass.bus.async_fire("test_event1")
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == 0
|
||||
|
@ -7,8 +7,8 @@ from pytest_unordered import unordered
|
||||
|
||||
from homeassistant.components import automation
|
||||
from homeassistant.components.device_automation import DeviceAutomationType
|
||||
from homeassistant.components.light import DOMAIN
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, EntityCategory
|
||||
from homeassistant.components.light import DOMAIN, LightState
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
||||
@ -195,7 +195,7 @@ async def test_if_fires_on_state_change(
|
||||
DOMAIN, "test", "5678", device_id=device_entry.id
|
||||
)
|
||||
|
||||
hass.states.async_set(entry.entity_id, STATE_ON)
|
||||
hass.states.async_set(entry.entity_id, LightState.ON)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@ -253,7 +253,7 @@ async def test_if_fires_on_state_change(
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == 0
|
||||
|
||||
hass.states.async_set(entry.entity_id, STATE_OFF)
|
||||
hass.states.async_set(entry.entity_id, LightState.OFF)
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == 2
|
||||
assert {service_calls[0].data["some"], service_calls[1].data["some"]} == {
|
||||
@ -261,7 +261,7 @@ async def test_if_fires_on_state_change(
|
||||
f"turn_on_or_off device - {entry.entity_id} - on - off - None",
|
||||
}
|
||||
|
||||
hass.states.async_set(entry.entity_id, STATE_ON)
|
||||
hass.states.async_set(entry.entity_id, LightState.ON)
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == 4
|
||||
assert {service_calls[2].data["some"], service_calls[3].data["some"]} == {
|
||||
@ -288,7 +288,7 @@ async def test_if_fires_on_state_change_legacy(
|
||||
DOMAIN, "test", "5678", device_id=device_entry.id
|
||||
)
|
||||
|
||||
hass.states.async_set(entry.entity_id, STATE_ON)
|
||||
hass.states.async_set(entry.entity_id, LightState.ON)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@ -316,7 +316,7 @@ async def test_if_fires_on_state_change_legacy(
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == 0
|
||||
|
||||
hass.states.async_set(entry.entity_id, STATE_OFF)
|
||||
hass.states.async_set(entry.entity_id, LightState.OFF)
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == 1
|
||||
assert (
|
||||
@ -343,7 +343,7 @@ async def test_if_fires_on_state_change_with_for(
|
||||
DOMAIN, "test", "5678", device_id=device_entry.id
|
||||
)
|
||||
|
||||
hass.states.async_set(entry.entity_id, STATE_ON)
|
||||
hass.states.async_set(entry.entity_id, LightState.ON)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@ -372,7 +372,7 @@ async def test_if_fires_on_state_change_with_for(
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == 0
|
||||
|
||||
hass.states.async_set(entry.entity_id, STATE_OFF)
|
||||
hass.states.async_set(entry.entity_id, LightState.OFF)
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == 0
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||
|
@ -15,8 +15,6 @@ from homeassistant.const import (
|
||||
SERVICE_TOGGLE,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError, Unauthorized
|
||||
@ -38,10 +36,10 @@ orig_Profiles = light.Profiles
|
||||
async def test_methods(hass: HomeAssistant) -> None:
|
||||
"""Test if methods call the services as expected."""
|
||||
# Test is_on
|
||||
hass.states.async_set("light.test", STATE_ON)
|
||||
hass.states.async_set("light.test", light.LightState.ON)
|
||||
assert light.is_on(hass, "light.test")
|
||||
|
||||
hass.states.async_set("light.test", STATE_OFF)
|
||||
hass.states.async_set("light.test", light.LightState.OFF)
|
||||
assert not light.is_on(hass, "light.test")
|
||||
|
||||
# Test turn_on
|
||||
@ -914,8 +912,8 @@ async def test_light_turn_on_auth(
|
||||
async def test_light_brightness_step(hass: HomeAssistant) -> None:
|
||||
"""Test that light context works."""
|
||||
entities = [
|
||||
MockLight("Test_0", STATE_ON),
|
||||
MockLight("Test_1", STATE_ON),
|
||||
MockLight("Test_0", light.LightState.ON),
|
||||
MockLight("Test_1", light.LightState.ON),
|
||||
]
|
||||
|
||||
setup_test_component_platform(hass, light.DOMAIN, entities)
|
||||
@ -1143,7 +1141,7 @@ invalid_no_brightness_no_color_no_transition,,,
|
||||
assert invalid_profile_name not in profiles.data
|
||||
|
||||
|
||||
@pytest.mark.parametrize("light_state", [STATE_ON, STATE_OFF])
|
||||
@pytest.mark.parametrize("light_state", [light.LightState.ON, light.LightState.OFF])
|
||||
async def test_light_backwards_compatibility_supported_color_modes(
|
||||
hass: HomeAssistant, light_state: Literal["on", "off"]
|
||||
) -> None:
|
||||
@ -1191,28 +1189,28 @@ async def test_light_backwards_compatibility_supported_color_modes(
|
||||
|
||||
state = hass.states.get(entity0.entity_id)
|
||||
assert state.attributes["supported_color_modes"] == [light.ColorMode.ONOFF]
|
||||
if light_state == STATE_OFF:
|
||||
if light_state == light.LightState.OFF:
|
||||
assert state.attributes["color_mode"] is None
|
||||
else:
|
||||
assert state.attributes["color_mode"] == light.ColorMode.ONOFF
|
||||
|
||||
state = hass.states.get(entity1.entity_id)
|
||||
assert state.attributes["supported_color_modes"] == [light.ColorMode.BRIGHTNESS]
|
||||
if light_state == STATE_OFF:
|
||||
if light_state == light.LightState.OFF:
|
||||
assert state.attributes["color_mode"] is None
|
||||
else:
|
||||
assert state.attributes["color_mode"] == light.ColorMode.UNKNOWN
|
||||
|
||||
state = hass.states.get(entity2.entity_id)
|
||||
assert state.attributes["supported_color_modes"] == [light.ColorMode.COLOR_TEMP]
|
||||
if light_state == STATE_OFF:
|
||||
if light_state == light.LightState.OFF:
|
||||
assert state.attributes["color_mode"] is None
|
||||
else:
|
||||
assert state.attributes["color_mode"] == light.ColorMode.UNKNOWN
|
||||
|
||||
state = hass.states.get(entity3.entity_id)
|
||||
assert state.attributes["supported_color_modes"] == [light.ColorMode.HS]
|
||||
if light_state == STATE_OFF:
|
||||
if light_state == light.LightState.OFF:
|
||||
assert state.attributes["color_mode"] is None
|
||||
else:
|
||||
assert state.attributes["color_mode"] == light.ColorMode.UNKNOWN
|
||||
@ -1222,7 +1220,7 @@ async def test_light_backwards_compatibility_supported_color_modes(
|
||||
light.ColorMode.COLOR_TEMP,
|
||||
light.ColorMode.HS,
|
||||
]
|
||||
if light_state == STATE_OFF:
|
||||
if light_state == light.LightState.OFF:
|
||||
assert state.attributes["color_mode"] is None
|
||||
else:
|
||||
assert state.attributes["color_mode"] == light.ColorMode.UNKNOWN
|
||||
@ -1231,11 +1229,11 @@ async def test_light_backwards_compatibility_supported_color_modes(
|
||||
async def test_light_backwards_compatibility_color_mode(hass: HomeAssistant) -> None:
|
||||
"""Test color_mode if not implemented by the entity."""
|
||||
entities = [
|
||||
MockLight("Test_0", STATE_ON),
|
||||
MockLight("Test_1", STATE_ON),
|
||||
MockLight("Test_2", STATE_ON),
|
||||
MockLight("Test_3", STATE_ON),
|
||||
MockLight("Test_4", STATE_ON),
|
||||
MockLight("Test_0", light.LightState.ON),
|
||||
MockLight("Test_1", light.LightState.ON),
|
||||
MockLight("Test_2", light.LightState.ON),
|
||||
MockLight("Test_3", light.LightState.ON),
|
||||
MockLight("Test_4", light.LightState.ON),
|
||||
]
|
||||
|
||||
entity0 = entities[0]
|
||||
@ -1306,7 +1304,7 @@ async def test_light_backwards_compatibility_color_mode(hass: HomeAssistant) ->
|
||||
|
||||
async def test_light_service_call_rgbw(hass: HomeAssistant) -> None:
|
||||
"""Test rgbw functionality in service calls."""
|
||||
entity0 = MockLight("Test_rgbw", STATE_ON)
|
||||
entity0 = MockLight("Test_rgbw", light.LightState.ON)
|
||||
entity0.supported_color_modes = {light.ColorMode.RGBW}
|
||||
|
||||
setup_test_component_platform(hass, light.DOMAIN, [entity0])
|
||||
@ -1335,10 +1333,10 @@ async def test_light_service_call_rgbw(hass: HomeAssistant) -> None:
|
||||
async def test_light_state_off(hass: HomeAssistant) -> None:
|
||||
"""Test rgbw color conversion in state updates."""
|
||||
entities = [
|
||||
MockLight("Test_onoff", STATE_OFF),
|
||||
MockLight("Test_brightness", STATE_OFF),
|
||||
MockLight("Test_ct", STATE_OFF),
|
||||
MockLight("Test_rgbw", STATE_OFF),
|
||||
MockLight("Test_onoff", light.LightState.OFF),
|
||||
MockLight("Test_brightness", light.LightState.OFF),
|
||||
MockLight("Test_ct", light.LightState.OFF),
|
||||
MockLight("Test_rgbw", light.LightState.OFF),
|
||||
]
|
||||
setup_test_component_platform(hass, light.DOMAIN, entities)
|
||||
|
||||
@ -1405,7 +1403,7 @@ async def test_light_state_off(hass: HomeAssistant) -> None:
|
||||
|
||||
async def test_light_state_rgbw(hass: HomeAssistant) -> None:
|
||||
"""Test rgbw color conversion in state updates."""
|
||||
entity0 = MockLight("Test_rgbw", STATE_ON)
|
||||
entity0 = MockLight("Test_rgbw", light.LightState.ON)
|
||||
setup_test_component_platform(hass, light.DOMAIN, [entity0])
|
||||
|
||||
entity0.brightness = 255
|
||||
@ -1436,7 +1434,7 @@ async def test_light_state_rgbw(hass: HomeAssistant) -> None:
|
||||
|
||||
async def test_light_state_rgbww(hass: HomeAssistant) -> None:
|
||||
"""Test rgbww color conversion in state updates."""
|
||||
entity0 = MockLight("Test_rgbww", STATE_ON)
|
||||
entity0 = MockLight("Test_rgbww", light.LightState.ON)
|
||||
setup_test_component_platform(hass, light.DOMAIN, [entity0])
|
||||
|
||||
entity0.supported_color_modes = {light.ColorMode.RGBWW}
|
||||
@ -1468,14 +1466,14 @@ async def test_light_state_rgbww(hass: HomeAssistant) -> None:
|
||||
async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None:
|
||||
"""Test color conversion in service calls."""
|
||||
entities = [
|
||||
MockLight("Test_hs", STATE_ON),
|
||||
MockLight("Test_rgb", STATE_ON),
|
||||
MockLight("Test_xy", STATE_ON),
|
||||
MockLight("Test_all", STATE_ON),
|
||||
MockLight("Test_legacy", STATE_ON),
|
||||
MockLight("Test_rgbw", STATE_ON),
|
||||
MockLight("Test_rgbww", STATE_ON),
|
||||
MockLight("Test_temperature", STATE_ON),
|
||||
MockLight("Test_hs", light.LightState.ON),
|
||||
MockLight("Test_rgb", light.LightState.ON),
|
||||
MockLight("Test_xy", light.LightState.ON),
|
||||
MockLight("Test_all", light.LightState.ON),
|
||||
MockLight("Test_legacy", light.LightState.ON),
|
||||
MockLight("Test_rgbw", light.LightState.ON),
|
||||
MockLight("Test_rgbww", light.LightState.ON),
|
||||
MockLight("Test_temperature", light.LightState.ON),
|
||||
]
|
||||
setup_test_component_platform(hass, light.DOMAIN, entities)
|
||||
|
||||
@ -1913,13 +1911,13 @@ async def test_light_service_call_color_conversion_named_tuple(
|
||||
) -> None:
|
||||
"""Test a named tuple (RGBColor) is handled correctly."""
|
||||
entities = [
|
||||
MockLight("Test_hs", STATE_ON),
|
||||
MockLight("Test_rgb", STATE_ON),
|
||||
MockLight("Test_xy", STATE_ON),
|
||||
MockLight("Test_all", STATE_ON),
|
||||
MockLight("Test_legacy", STATE_ON),
|
||||
MockLight("Test_rgbw", STATE_ON),
|
||||
MockLight("Test_rgbww", STATE_ON),
|
||||
MockLight("Test_hs", light.LightState.ON),
|
||||
MockLight("Test_rgb", light.LightState.ON),
|
||||
MockLight("Test_xy", light.LightState.ON),
|
||||
MockLight("Test_all", light.LightState.ON),
|
||||
MockLight("Test_legacy", light.LightState.ON),
|
||||
MockLight("Test_rgbw", light.LightState.ON),
|
||||
MockLight("Test_rgbww", light.LightState.ON),
|
||||
]
|
||||
setup_test_component_platform(hass, light.DOMAIN, entities)
|
||||
|
||||
@ -1991,9 +1989,9 @@ async def test_light_service_call_color_conversion_named_tuple(
|
||||
async def test_light_service_call_color_temp_emulation(hass: HomeAssistant) -> None:
|
||||
"""Test color conversion in service calls."""
|
||||
entities = [
|
||||
MockLight("Test_hs_ct", STATE_ON),
|
||||
MockLight("Test_hs", STATE_ON),
|
||||
MockLight("Test_hs_white", STATE_ON),
|
||||
MockLight("Test_hs_ct", light.LightState.ON),
|
||||
MockLight("Test_hs", light.LightState.ON),
|
||||
MockLight("Test_hs_white", light.LightState.ON),
|
||||
]
|
||||
setup_test_component_platform(hass, light.DOMAIN, entities)
|
||||
|
||||
@ -2049,8 +2047,8 @@ async def test_light_service_call_color_temp_emulation(hass: HomeAssistant) -> N
|
||||
async def test_light_service_call_color_temp_conversion(hass: HomeAssistant) -> None:
|
||||
"""Test color temp conversion in service calls."""
|
||||
entities = [
|
||||
MockLight("Test_rgbww_ct", STATE_ON),
|
||||
MockLight("Test_rgbww", STATE_ON),
|
||||
MockLight("Test_rgbww_ct", light.LightState.ON),
|
||||
MockLight("Test_rgbww", light.LightState.ON),
|
||||
]
|
||||
setup_test_component_platform(hass, light.DOMAIN, entities)
|
||||
|
||||
@ -2180,8 +2178,8 @@ async def test_light_service_call_color_temp_conversion(hass: HomeAssistant) ->
|
||||
async def test_light_mired_color_temp_conversion(hass: HomeAssistant) -> None:
|
||||
"""Test color temp conversion from K to legacy mired."""
|
||||
entities = [
|
||||
MockLight("Test_rgbww_ct", STATE_ON),
|
||||
MockLight("Test_rgbww", STATE_ON),
|
||||
MockLight("Test_rgbww_ct", light.LightState.ON),
|
||||
MockLight("Test_rgbww", light.LightState.ON),
|
||||
]
|
||||
setup_test_component_platform(hass, light.DOMAIN, entities)
|
||||
|
||||
@ -2225,7 +2223,7 @@ async def test_light_mired_color_temp_conversion(hass: HomeAssistant) -> None:
|
||||
|
||||
async def test_light_service_call_white_mode(hass: HomeAssistant) -> None:
|
||||
"""Test color_mode white in service calls."""
|
||||
entity0 = MockLight("Test_white", STATE_ON)
|
||||
entity0 = MockLight("Test_white", light.LightState.ON)
|
||||
entity0.supported_color_modes = {light.ColorMode.HS, light.ColorMode.WHITE}
|
||||
setup_test_component_platform(hass, light.DOMAIN, [entity0])
|
||||
|
||||
@ -2325,10 +2323,10 @@ async def test_light_service_call_white_mode(hass: HomeAssistant) -> None:
|
||||
async def test_light_state_color_conversion(hass: HomeAssistant) -> None:
|
||||
"""Test color conversion in state updates."""
|
||||
entities = [
|
||||
MockLight("Test_hs", STATE_ON),
|
||||
MockLight("Test_rgb", STATE_ON),
|
||||
MockLight("Test_xy", STATE_ON),
|
||||
MockLight("Test_legacy", STATE_ON),
|
||||
MockLight("Test_hs", light.LightState.ON),
|
||||
MockLight("Test_rgb", light.LightState.ON),
|
||||
MockLight("Test_xy", light.LightState.ON),
|
||||
MockLight("Test_legacy", light.LightState.ON),
|
||||
]
|
||||
setup_test_component_platform(hass, light.DOMAIN, entities)
|
||||
|
||||
|
@ -10,15 +10,10 @@ from homeassistant.components.light import (
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.components.linear_garage_door import DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_BRIGHTNESS,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_BRIGHTNESS, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
@ -109,8 +104,8 @@ async def test_update_light_state(
|
||||
|
||||
await setup_integration(hass, mock_config_entry, [Platform.LIGHT])
|
||||
|
||||
assert hass.states.get("light.test_garage_1_light").state == STATE_ON
|
||||
assert hass.states.get("light.test_garage_2_light").state == STATE_OFF
|
||||
assert hass.states.get("light.test_garage_1_light").state == LightState.ON
|
||||
assert hass.states.get("light.test_garage_2_light").state == LightState.OFF
|
||||
|
||||
device_states = load_json_object_fixture("get_device_state_1.json", DOMAIN)
|
||||
mock_linear.get_device_state.side_effect = lambda device_id: device_states[
|
||||
@ -120,5 +115,5 @@ async def test_update_light_state(
|
||||
freezer.tick(timedelta(seconds=60))
|
||||
async_fire_time_changed(hass)
|
||||
|
||||
assert hass.states.get("light.test_garage_1_light").state == STATE_OFF
|
||||
assert hass.states.get("light.test_garage_2_light").state == STATE_ON
|
||||
assert hass.states.get("light.test_garage_1_light").state == LightState.OFF
|
||||
assert hass.states.get("light.test_garage_2_light").state == LightState.ON
|
||||
|
@ -1,6 +1,6 @@
|
||||
"""Tests for the Lutron Caseta integration."""
|
||||
|
||||
from homeassistant.const import STATE_ON
|
||||
from homeassistant.components.light import LightState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
@ -23,4 +23,4 @@ async def test_light_unique_id(
|
||||
assert entity_registry.async_get(caseta_entity_id).unique_id == "5442321"
|
||||
|
||||
state = hass.states.get(ra3_entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
@ -3,7 +3,7 @@
|
||||
from pymodbus.exceptions import ModbusException
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN, LightState
|
||||
from homeassistant.components.modbus.const import (
|
||||
CALL_TYPE_COIL,
|
||||
CALL_TYPE_DISCRETE,
|
||||
@ -25,8 +25,6 @@ from homeassistant.const import (
|
||||
CONF_NAME,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_SLAVE,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
@ -177,19 +175,19 @@ async def test_config_light(hass: HomeAssistant, mock_modbus) -> None:
|
||||
[0x00],
|
||||
False,
|
||||
{CONF_VERIFY: {}},
|
||||
STATE_OFF,
|
||||
LightState.OFF,
|
||||
),
|
||||
(
|
||||
[0x01],
|
||||
False,
|
||||
{CONF_VERIFY: {}},
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
),
|
||||
(
|
||||
[0xFE],
|
||||
False,
|
||||
{CONF_VERIFY: {}},
|
||||
STATE_OFF,
|
||||
LightState.OFF,
|
||||
),
|
||||
(
|
||||
[0x00],
|
||||
@ -201,7 +199,7 @@ async def test_config_light(hass: HomeAssistant, mock_modbus) -> None:
|
||||
[0x00],
|
||||
True,
|
||||
None,
|
||||
STATE_OFF,
|
||||
LightState.OFF,
|
||||
),
|
||||
],
|
||||
)
|
||||
@ -212,7 +210,7 @@ async def test_all_light(hass: HomeAssistant, mock_do_cycle, expected) -> None:
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mock_test_state",
|
||||
[(State(ENTITY_ID, STATE_ON),)],
|
||||
[(State(ENTITY_ID, LightState.ON),)],
|
||||
indirect=True,
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
@ -267,31 +265,31 @@ async def test_light_service_turn(
|
||||
|
||||
assert MODBUS_DOMAIN in hass.config.components
|
||||
|
||||
assert hass.states.get(ENTITY_ID).state == STATE_OFF
|
||||
assert hass.states.get(ENTITY_ID).state == LightState.OFF
|
||||
await hass.services.async_call(
|
||||
"light", "turn_on", service_data={"entity_id": ENTITY_ID}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(ENTITY_ID).state == STATE_ON
|
||||
assert hass.states.get(ENTITY_ID).state == LightState.ON
|
||||
await hass.services.async_call(
|
||||
"light", "turn_off", service_data={"entity_id": ENTITY_ID}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(ENTITY_ID).state == STATE_OFF
|
||||
assert hass.states.get(ENTITY_ID).state == LightState.OFF
|
||||
|
||||
mock_modbus.read_holding_registers.return_value = ReadResult([0x01])
|
||||
assert hass.states.get(ENTITY_ID2).state == STATE_OFF
|
||||
assert hass.states.get(ENTITY_ID2).state == LightState.OFF
|
||||
await hass.services.async_call(
|
||||
"light", "turn_on", service_data={"entity_id": ENTITY_ID2}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(ENTITY_ID2).state == STATE_ON
|
||||
assert hass.states.get(ENTITY_ID2).state == LightState.ON
|
||||
mock_modbus.read_holding_registers.return_value = ReadResult([0x00])
|
||||
await hass.services.async_call(
|
||||
"light", "turn_off", service_data={"entity_id": ENTITY_ID2}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(ENTITY_ID2).state == STATE_OFF
|
||||
assert hass.states.get(ENTITY_ID2).state == LightState.OFF
|
||||
|
||||
mock_modbus.write_register.side_effect = ModbusException("fail write_")
|
||||
await hass.services.async_call(
|
||||
@ -321,12 +319,12 @@ async def test_service_light_update(hass: HomeAssistant, mock_modbus_ha) -> None
|
||||
await hass.services.async_call(
|
||||
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
|
||||
)
|
||||
assert hass.states.get(ENTITY_ID).state == STATE_OFF
|
||||
assert hass.states.get(ENTITY_ID).state == LightState.OFF
|
||||
mock_modbus_ha.read_coils.return_value = ReadResult([0x01])
|
||||
await hass.services.async_call(
|
||||
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
|
||||
)
|
||||
assert hass.states.get(ENTITY_ID).state == STATE_ON
|
||||
assert hass.states.get(ENTITY_ID).state == LightState.ON
|
||||
|
||||
|
||||
async def test_no_discovery_info_light(
|
||||
|
@ -5,7 +5,11 @@ from unittest.mock import patch
|
||||
from aiomodernforms import ModernFormsConnectionError
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS, DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.components.modern_forms.const import (
|
||||
ATTR_SLEEP_TIME,
|
||||
DOMAIN,
|
||||
@ -17,7 +21,6 @@ from homeassistant.const import (
|
||||
ATTR_FRIENDLY_NAME,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -40,7 +43,7 @@ async def test_light_state(
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_BRIGHTNESS) == 128
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "ModernFormsFan Light"
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
entry = entity_registry.async_get("light.modernformsfan_light")
|
||||
assert entry
|
||||
@ -130,7 +133,7 @@ async def test_light_error(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.modernformsfan_light")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert "Invalid response from API" in caplog.text
|
||||
|
||||
|
||||
|
@ -190,7 +190,7 @@ from homeassistant.components.mqtt.light.schema_basic import (
|
||||
VALUE_TEMPLATE_KEYS,
|
||||
)
|
||||
from homeassistant.components.mqtt.models import PublishPayloadType
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON, STATE_UNKNOWN
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
|
||||
from .test_common import (
|
||||
@ -282,7 +282,7 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "ON")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("brightness") is None
|
||||
assert state.attributes.get("color_temp") is None
|
||||
@ -297,7 +297,7 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "OFF")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "None")
|
||||
|
||||
@ -363,7 +363,7 @@ async def test_controlling_state_via_topic(
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("brightness") is None
|
||||
assert state.attributes.get("color_temp") is None
|
||||
@ -378,7 +378,7 @@ async def test_controlling_state_via_topic(
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "0")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/brightness/status", "100")
|
||||
@ -662,7 +662,7 @@ async def test_invalid_state_via_topic(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/effect/status", "none")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (255, 255, 255)
|
||||
assert state.attributes.get("brightness") == 255
|
||||
assert state.attributes.get("color_temp") is None
|
||||
@ -673,7 +673,7 @@ async def test_invalid_state_via_topic(
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "")
|
||||
light_state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/brightness/status", "")
|
||||
light_state = hass.states.get("light.test")
|
||||
@ -720,7 +720,7 @@ async def test_invalid_state_via_topic(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/color_mode/status", "color_temp")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (255, 254, 250)
|
||||
assert state.attributes.get("brightness") == 255
|
||||
assert state.attributes.get("color_temp") == 153
|
||||
@ -767,13 +767,13 @@ async def test_brightness_controlling_scale(
|
||||
async_fire_mqtt_message(hass, "test_scale/status", "on")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") is None
|
||||
|
||||
async_fire_mqtt_message(hass, "test_scale/status", "off")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
async_fire_mqtt_message(hass, "test_scale/status", "on")
|
||||
|
||||
@ -910,7 +910,7 @@ async def test_controlling_state_via_topic_with_templates(
|
||||
hass, "test_light_rgb/effect/status", '{"hello": "rainbow"}'
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 50
|
||||
assert state.attributes.get("rgb_color") == (1, 2, 3)
|
||||
assert state.attributes.get("effect") == "rainbow"
|
||||
@ -921,7 +921,7 @@ async def test_controlling_state_via_topic_with_templates(
|
||||
hass, "test_light_rgb/rgbw/status", '{"hello": [1, 2, 3, 4]}'
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgbw_color") == (1, 2, 3, 4)
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "rgbw"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
@ -930,7 +930,7 @@ async def test_controlling_state_via_topic_with_templates(
|
||||
hass, "test_light_rgb/rgbww/status", '{"hello": [1, 2, 3, 4, 5]}'
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgbww_color") == (1, 2, 3, 4, 5)
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "rgbww"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
@ -1017,7 +1017,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 95
|
||||
assert state.attributes.get("hs_color") == (100, 100)
|
||||
assert state.attributes.get("effect") == "random"
|
||||
@ -1037,7 +1037,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
assert mqtt_mock.async_publish.call_count == 2
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("effect") == "colorloop"
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "hs"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
@ -1048,7 +1048,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) is None
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
@ -1066,7 +1066,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
assert mqtt_mock.async_publish.call_count == 3
|
||||
mqtt_mock.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 10
|
||||
assert state.attributes.get("rgb_color") == (80, 40, 20)
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "rgb"
|
||||
@ -1086,7 +1086,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
assert mqtt_mock.async_publish.call_count == 3
|
||||
mqtt_mock.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 20
|
||||
assert state.attributes.get("rgbw_color") == (80, 40, 20, 10)
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "rgbw"
|
||||
@ -1106,7 +1106,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
assert mqtt_mock.async_publish.call_count == 3
|
||||
mqtt_mock.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 40
|
||||
assert state.attributes.get("rgbww_color") == (80, 40, 20, 10, 8)
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "rgbww"
|
||||
@ -1124,7 +1124,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
assert mqtt_mock.async_publish.call_count == 3
|
||||
mqtt_mock.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 50
|
||||
assert state.attributes.get("hs_color") == (359.0, 78.0)
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "hs"
|
||||
@ -1142,7 +1142,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
assert mqtt_mock.async_publish.call_count == 3
|
||||
mqtt_mock.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 60
|
||||
assert state.attributes.get("xy_color") == (0.2, 0.3)
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "xy"
|
||||
@ -1158,7 +1158,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
assert mqtt_mock.async_publish.call_count == 2
|
||||
mqtt_mock.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 60
|
||||
assert state.attributes.get("color_temp") == 125
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "color_temp"
|
||||
@ -1204,7 +1204,7 @@ async def test_sending_mqtt_rgb_command_with_template(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["rgb_color"] == (255, 128, 64)
|
||||
|
||||
|
||||
@ -1247,7 +1247,7 @@ async def test_sending_mqtt_rgbw_command_with_template(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["rgbw_color"] == (255, 128, 64, 32)
|
||||
|
||||
|
||||
@ -1290,7 +1290,7 @@ async def test_sending_mqtt_rgbww_command_with_template(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["rgbww_color"] == (255, 128, 64, 32, 16)
|
||||
|
||||
|
||||
@ -1332,7 +1332,7 @@ async def test_sending_mqtt_color_temp_command_with_template(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["color_temp"] == 100
|
||||
|
||||
|
||||
@ -2116,7 +2116,7 @@ async def test_explicit_color_mode(
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("brightness") is None
|
||||
assert state.attributes.get("color_temp") is None
|
||||
@ -2131,7 +2131,7 @@ async def test_explicit_color_mode(
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "0")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/brightness/status", "100")
|
||||
@ -2256,7 +2256,7 @@ async def test_explicit_color_mode_templated(
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") is None
|
||||
assert state.attributes.get("color_temp") is None
|
||||
assert state.attributes.get("hs_color") is None
|
||||
@ -2265,7 +2265,7 @@ async def test_explicit_color_mode_templated(
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "0")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/brightness/status", "100")
|
||||
@ -2354,7 +2354,7 @@ async def test_white_state_update(
|
||||
'{"POWER":"ON","Dimmer":50,"Color":"0,0,0,128","White":50}',
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 128
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "white"
|
||||
@ -2366,7 +2366,7 @@ async def test_white_state_update(
|
||||
'{"POWER":"ON","Dimmer":50,"Color":"128,64,32,0","White":0}',
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 128
|
||||
assert state.attributes.get("rgb_color") == (128, 64, 32)
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "rgb"
|
||||
@ -3428,7 +3428,7 @@ async def test_sending_mqtt_brightness_command_with_template(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["brightness"] == 100
|
||||
|
||||
|
||||
@ -3476,7 +3476,7 @@ async def test_sending_mqtt_effect_command_with_template(
|
||||
any_order=True,
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("effect") == "colorloop"
|
||||
|
||||
|
||||
@ -3516,7 +3516,7 @@ async def test_sending_mqtt_hs_command_with_template(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["hs_color"] == (30, 100)
|
||||
|
||||
|
||||
@ -3559,7 +3559,7 @@ async def test_sending_mqtt_xy_command_with_template(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["xy_color"] == (0.151, 0.343)
|
||||
|
||||
|
||||
|
@ -93,8 +93,6 @@ from homeassistant.components.mqtt.models import PublishPayloadType
|
||||
from homeassistant.const import (
|
||||
ATTR_ASSUMED_STATE,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
@ -432,7 +430,7 @@ async def test_single_color_mode(
|
||||
)
|
||||
color_modes = [light.ColorMode.COLOR_TEMP]
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
assert state.attributes.get(light.ATTR_COLOR_TEMP) == 192
|
||||
@ -455,7 +453,7 @@ async def test_turn_on_with_unknown_color_mode_optimistic(
|
||||
assert state.attributes.get("color_mode") == light.ColorMode.UNKNOWN
|
||||
assert state.attributes.get("brightness") is None
|
||||
assert state.attributes.get("color_temp") is None
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
# Turn on the light with brightness or color_temp attributes
|
||||
await common.async_turn_on(hass, "light.test", brightness=50, color_temp=192)
|
||||
@ -463,7 +461,7 @@ async def test_turn_on_with_unknown_color_mode_optimistic(
|
||||
assert state.attributes.get("color_mode") == light.ColorMode.COLOR_TEMP
|
||||
assert state.attributes.get("brightness") == 50
|
||||
assert state.attributes.get("color_temp") == 192
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -493,7 +491,7 @@ async def test_controlling_state_with_unknown_color_mode(
|
||||
'{"state": "ON"}',
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get(light.ATTR_COLOR_TEMP) is None
|
||||
assert state.attributes.get(light.ATTR_BRIGHTNESS) is None
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == light.ColorMode.UNKNOWN
|
||||
@ -505,7 +503,7 @@ async def test_controlling_state_with_unknown_color_mode(
|
||||
'{"state": "ON", "brightness": 50, "color_mode": "color_temp", "color_temp": 192}',
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
assert state.attributes.get(light.ATTR_COLOR_TEMP) == 192
|
||||
assert state.attributes.get(light.ATTR_BRIGHTNESS) == 50
|
||||
@ -575,7 +573,7 @@ async def test_no_color_brightness_color_temp_if_no_topics(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", '{"state":"ON"}')
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("brightness") is None
|
||||
assert state.attributes.get("color_temp") is None
|
||||
@ -586,7 +584,7 @@ async def test_no_color_brightness_color_temp_if_no_topics(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", '{"state":"OFF"}')
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", '{"state": null}')
|
||||
|
||||
@ -650,7 +648,7 @@ async def test_controlling_state_via_topic(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (255, 255, 255)
|
||||
assert state.attributes.get("brightness") == 255
|
||||
assert state.attributes.get("color_temp") is None # rgb color has priority
|
||||
@ -670,7 +668,7 @@ async def test_controlling_state_via_topic(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (
|
||||
255,
|
||||
253,
|
||||
@ -686,7 +684,7 @@ async def test_controlling_state_via_topic(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", '{"state":"OFF"}')
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", '{"state":"ON", "brightness":100}')
|
||||
|
||||
@ -747,7 +745,7 @@ async def test_controlling_state_via_topic(
|
||||
'"effect":"colorloop"}',
|
||||
)
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.state == STATE_ON
|
||||
assert light_state.state == light.LightState.ON
|
||||
assert light_state.attributes.get("brightness") == 128
|
||||
|
||||
async_fire_mqtt_message(
|
||||
@ -756,7 +754,7 @@ async def test_controlling_state_via_topic(
|
||||
'{"state":"OFF","brightness":0}',
|
||||
)
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.state == STATE_OFF
|
||||
assert light_state.state == light.LightState.OFF
|
||||
assert light_state.attributes.get("brightness") is None
|
||||
|
||||
# test previous zero brightness received was ignored and brightness is restored
|
||||
@ -817,7 +815,7 @@ async def test_controlling_state_via_topic2(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 255
|
||||
assert state.attributes.get("color_mode") == "rgbww"
|
||||
assert state.attributes.get("color_temp") is None
|
||||
@ -831,7 +829,7 @@ async def test_controlling_state_via_topic2(
|
||||
# Light turned off
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", '{"state":"OFF"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
# Light turned on, brightness 100
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", '{"state":"ON", "brightness":100}')
|
||||
@ -987,7 +985,7 @@ async def test_controlling_the_state_with_legacy_color_handling(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 255
|
||||
assert state.attributes.get("color_mode") == "hs"
|
||||
assert state.attributes.get("color_temp") is None
|
||||
@ -1009,7 +1007,7 @@ async def test_controlling_the_state_with_legacy_color_handling(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 255
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
assert state.attributes.get("color_temp") == 353
|
||||
@ -1061,7 +1059,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 95
|
||||
assert state.attributes.get("hs_color") == (100, 100)
|
||||
assert state.attributes.get("effect") == "random"
|
||||
@ -1081,7 +1079,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
await common.async_turn_on(hass, "light.test", color_temp=90)
|
||||
|
||||
@ -1093,7 +1091,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("color_mode") == light.ColorMode.COLOR_TEMP
|
||||
assert state.attributes.get("color_temp") == 90
|
||||
|
||||
@ -1104,7 +1102,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
mqtt_mock.reset_mock()
|
||||
await common.async_turn_on(
|
||||
@ -1141,7 +1139,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("color_mode") == light.ColorMode.HS
|
||||
assert state.attributes["brightness"] == 50
|
||||
assert state.attributes["hs_color"] == (359.0, 78.0)
|
||||
@ -1160,7 +1158,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("color_mode") == light.ColorMode.HS
|
||||
assert state.attributes["brightness"] == 50
|
||||
assert state.attributes["hs_color"] == (30.118, 100)
|
||||
@ -1216,7 +1214,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
expected_features = (
|
||||
light.SUPPORT_EFFECT | light.SUPPORT_FLASH | light.SUPPORT_TRANSITION
|
||||
)
|
||||
@ -1241,7 +1239,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
# Turn the light on with color temperature
|
||||
await common.async_turn_on(hass, "light.test", color_temp=90)
|
||||
@ -1253,7 +1251,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
# Turn the light off
|
||||
await common.async_turn_off(hass, "light.test")
|
||||
@ -1262,12 +1260,12 @@ async def test_sending_mqtt_commands_and_optimistic2(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
# Set hs color
|
||||
await common.async_turn_on(hass, "light.test", brightness=75, hs_color=[359, 78])
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["brightness"] == 75
|
||||
assert state.attributes["color_mode"] == "hs"
|
||||
assert state.attributes["hs_color"] == (359, 78)
|
||||
@ -1288,7 +1286,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
|
||||
# Set rgb color
|
||||
await common.async_turn_on(hass, "light.test", rgb_color=[255, 128, 0])
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["brightness"] == 75
|
||||
assert state.attributes["color_mode"] == "rgb"
|
||||
assert state.attributes["hs_color"] == (30.118, 100.0)
|
||||
@ -1307,7 +1305,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
|
||||
# Set rgbw color
|
||||
await common.async_turn_on(hass, "light.test", rgbw_color=[255, 128, 0, 123])
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["brightness"] == 75
|
||||
assert state.attributes["color_mode"] == "rgbw"
|
||||
assert state.attributes["rgbw_color"] == (255, 128, 0, 123)
|
||||
@ -1328,7 +1326,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
|
||||
# Set rgbww color
|
||||
await common.async_turn_on(hass, "light.test", rgbww_color=[255, 128, 0, 45, 32])
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["brightness"] == 75
|
||||
assert state.attributes["color_mode"] == "rgbww"
|
||||
assert state.attributes["rgbww_color"] == (255, 128, 0, 45, 32)
|
||||
@ -1351,7 +1349,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
|
||||
hass, "light.test", brightness=50, xy_color=[0.123, 0.223]
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["brightness"] == 50
|
||||
assert state.attributes["color_mode"] == "xy"
|
||||
assert state.attributes["hs_color"] == (196.471, 100.0)
|
||||
@ -1372,7 +1370,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
|
||||
# Set to white
|
||||
await common.async_turn_on(hass, "light.test", white=75)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["brightness"] == 75
|
||||
assert state.attributes["color_mode"] == "white"
|
||||
assert state.attributes["hs_color"] is None
|
||||
@ -1391,7 +1389,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
|
||||
# Set to white, brightness also present in turn_on
|
||||
await common.async_turn_on(hass, "light.test", brightness=60, white=80)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes["brightness"] == 60
|
||||
assert state.attributes["color_mode"] == "white"
|
||||
assert state.attributes["hs_color"] is None
|
||||
@ -1892,7 +1890,7 @@ async def test_effect(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("effect") is None
|
||||
|
||||
await common.async_turn_on(hass, "light.test", effect="rainbow")
|
||||
@ -1905,7 +1903,7 @@ async def test_effect(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("effect") == "rainbow"
|
||||
|
||||
await common.async_turn_on(hass, "light.test", effect="colorloop")
|
||||
@ -1918,7 +1916,7 @@ async def test_effect(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("effect") == "colorloop"
|
||||
|
||||
|
||||
@ -1957,7 +1955,7 @@ async def test_flash_short_and_long(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
await common.async_turn_on(hass, "light.test", flash="long")
|
||||
|
||||
@ -1966,7 +1964,7 @@ async def test_flash_short_and_long(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
await common.async_turn_off(hass, "light.test", flash="short")
|
||||
|
||||
@ -1975,7 +1973,7 @@ async def test_flash_short_and_long(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
await common.async_turn_off(hass, "light.test", flash="long")
|
||||
|
||||
@ -1984,7 +1982,7 @@ async def test_flash_short_and_long(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -2022,7 +2020,7 @@ async def test_transition(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
await common.async_turn_off(hass, "light.test", transition=30)
|
||||
|
||||
@ -2034,7 +2032,7 @@ async def test_transition(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -2069,7 +2067,7 @@ async def test_brightness_scale(
|
||||
async_fire_mqtt_message(hass, "test_light_bright_scale", '{"state":"ON"}')
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") is None
|
||||
|
||||
# Turn on the light with brightness
|
||||
@ -2078,7 +2076,7 @@ async def test_brightness_scale(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 255
|
||||
|
||||
# Turn on the light with half brightness
|
||||
@ -2087,7 +2085,7 @@ async def test_brightness_scale(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 129
|
||||
|
||||
# Test limmiting max brightness
|
||||
@ -2096,7 +2094,7 @@ async def test_brightness_scale(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 255
|
||||
|
||||
|
||||
@ -2135,7 +2133,7 @@ async def test_white_scale(
|
||||
async_fire_mqtt_message(hass, "test_light_bright_scale", '{"state":"ON"}')
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") is None
|
||||
|
||||
# Turn on the light with brightness
|
||||
@ -2146,7 +2144,7 @@ async def test_white_scale(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 255
|
||||
|
||||
# Turn on the light with white - white_scale is NOT used
|
||||
@ -2157,7 +2155,7 @@ async def test_white_scale(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 129
|
||||
|
||||
|
||||
@ -2209,7 +2207,7 @@ async def test_invalid_values(
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (255, 255, 255)
|
||||
assert state.attributes.get("brightness") == 255
|
||||
assert state.attributes.get("color_temp") is None
|
||||
@ -2222,7 +2220,7 @@ async def test_invalid_values(
|
||||
|
||||
# Color should not have changed
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (255, 255, 255)
|
||||
|
||||
# Bad HS color values
|
||||
@ -2234,7 +2232,7 @@ async def test_invalid_values(
|
||||
|
||||
# Color should not have changed
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (255, 255, 255)
|
||||
|
||||
# Bad RGB color values
|
||||
@ -2246,7 +2244,7 @@ async def test_invalid_values(
|
||||
|
||||
# Color should not have changed
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (255, 255, 255)
|
||||
|
||||
# Bad XY color values
|
||||
@ -2258,7 +2256,7 @@ async def test_invalid_values(
|
||||
|
||||
# Color should not have changed
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (255, 255, 255)
|
||||
|
||||
# Bad brightness values
|
||||
@ -2268,7 +2266,7 @@ async def test_invalid_values(
|
||||
|
||||
# Brightness should not have changed
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 255
|
||||
|
||||
# Unset color and set a valid color temperature
|
||||
@ -2276,7 +2274,7 @@ async def test_invalid_values(
|
||||
hass, "test_light_rgb", '{"state":"ON", "color": null, "color_temp": 100}'
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("color_temp") == 100
|
||||
|
||||
# Bad color temperature
|
||||
@ -2286,7 +2284,7 @@ async def test_invalid_values(
|
||||
|
||||
# Color temperature should not have changed
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("color_temp") == 100
|
||||
|
||||
|
||||
|
@ -39,8 +39,6 @@ from homeassistant.components.mqtt.models import PublishPayloadType
|
||||
from homeassistant.const import (
|
||||
ATTR_ASSUMED_STATE,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
@ -209,7 +207,7 @@ async def test_single_color_mode(
|
||||
async_fire_mqtt_message(hass, "test_light", "on,50,192")
|
||||
color_modes = [light.ColorMode.COLOR_TEMP]
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
assert state.attributes.get(light.ATTR_COLOR_TEMP) == 192
|
||||
@ -256,7 +254,7 @@ async def test_state_change_via_topic(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", "on")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("brightness") is None
|
||||
assert state.attributes.get("color_temp") is None
|
||||
@ -264,7 +262,7 @@ async def test_state_change_via_topic(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", "off")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", "None")
|
||||
|
||||
@ -321,7 +319,7 @@ async def test_state_brightness_color_effect_temp_change_via_topic(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", "on,255,145,255-128-64,")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (255, 128, 63)
|
||||
assert state.attributes.get("brightness") == 255
|
||||
assert state.attributes.get("color_temp") is None # rgb color has priority
|
||||
@ -331,7 +329,7 @@ async def test_state_brightness_color_effect_temp_change_via_topic(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", "on,255,145,None-None-None,")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (
|
||||
246,
|
||||
244,
|
||||
@ -356,7 +354,7 @@ async def test_state_brightness_color_effect_temp_change_via_topic(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", "off")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
# lower the brightness
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", "on,100")
|
||||
@ -440,7 +438,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("hs_color") == (100, 100)
|
||||
assert state.attributes.get("effect") == "random"
|
||||
assert state.attributes.get("color_temp") is None # hs_color has priority
|
||||
@ -452,7 +450,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
await common.async_turn_on(hass, "light.test")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
@ -460,7 +458,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
# Set color_temp
|
||||
await common.async_turn_on(hass, "light.test", color_temp=70)
|
||||
@ -469,7 +467,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("color_temp") == 70
|
||||
|
||||
# Set full brightness
|
||||
@ -479,7 +477,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
# Full brightness - no scaling of RGB values sent over MQTT
|
||||
await common.async_turn_on(hass, "light.test", rgb_color=[255, 128, 0])
|
||||
@ -488,7 +486,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (255, 128, 0)
|
||||
|
||||
# Full brightness - normalization of RGB values sent over MQTT
|
||||
@ -498,7 +496,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (255, 127, 0)
|
||||
|
||||
# Set half brightness
|
||||
@ -508,7 +506,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
# Half brightness - scaling of RGB values sent over MQTT
|
||||
await common.async_turn_on(hass, "light.test", rgb_color=[0, 255, 128])
|
||||
@ -517,7 +515,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (0, 255, 128)
|
||||
|
||||
# Half brightness - normalization+scaling of RGB values sent over MQTT
|
||||
@ -527,7 +525,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("rgb_color") == (0, 255, 127)
|
||||
|
||||
|
||||
@ -688,7 +686,7 @@ async def test_effect(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert not state.attributes.get("effect")
|
||||
|
||||
await common.async_turn_on(hass, "light.test", effect="rainbow")
|
||||
@ -697,7 +695,7 @@ async def test_effect(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("effect") == "rainbow"
|
||||
|
||||
await common.async_turn_on(hass, "light.test", effect="colorloop")
|
||||
@ -705,7 +703,7 @@ async def test_effect(
|
||||
"test_light_rgb/set", "on,colorloop", 0, False
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("effect") == "colorloop"
|
||||
|
||||
|
||||
@ -742,7 +740,7 @@ async def test_flash(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
await common.async_turn_on(hass, "light.test", flash="short")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
@ -750,14 +748,14 @@ async def test_flash(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
await common.async_turn_on(hass, "light.test", flash="long")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"test_light_rgb/set", "on,long", 0, False
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -794,14 +792,14 @@ async def test_transition(
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
await common.async_turn_off(hass, "light.test", transition=20.0)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"test_light_rgb/set", "off,20", 1, False
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == light.LightState.OFF
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -854,7 +852,7 @@ async def test_invalid_values(
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", "on,255,215,255-255-255,rainbow")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("brightness") == 255
|
||||
assert state.attributes.get("color_temp") is None # hs_color has priority
|
||||
assert state.attributes.get("rgb_color") == (255, 255, 255)
|
||||
@ -865,7 +863,7 @@ async def test_invalid_values(
|
||||
|
||||
# state should not have changed
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
|
||||
# bad brightness values
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", "on,off,255-255-255")
|
||||
@ -884,7 +882,7 @@ async def test_invalid_values(
|
||||
# Unset color and set a valid color temperature
|
||||
async_fire_mqtt_message(hass, "test_light_rgb", "on,,215,None-None-None")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == light.LightState.ON
|
||||
assert state.attributes.get("color_temp") == 215
|
||||
|
||||
# bad color temp values
|
||||
|
Loading…
x
Reference in New Issue
Block a user