mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add more
This commit is contained in:
parent
c1c6e6d50e
commit
0999f61079
@ -11,9 +11,10 @@ from homeassistant.components.light import (
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.components.nice_go.const import DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@ -80,8 +81,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
|
||||
assert hass.states.get("light.test_garage_3_light") is None
|
||||
|
||||
device_update = load_json_object_fixture("device_state_update.json", DOMAIN)
|
||||
@ -89,8 +90,8 @@ async def test_update_light_state(
|
||||
device_update_1 = load_json_object_fixture("device_state_update_1.json", DOMAIN)
|
||||
await mock_config_entry.runtime_data.on_data(device_update_1)
|
||||
|
||||
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
|
||||
assert hass.states.get("light.test_garage_3_light") is None
|
||||
|
||||
|
||||
|
@ -5,13 +5,16 @@ from unittest.mock import MagicMock, call, patch
|
||||
import pytest
|
||||
from reolink_aio.exceptions import InvalidParameterError, ReolinkError
|
||||
|
||||
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.config_entries import ConfigEntryState
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_ON,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -39,7 +42,7 @@ async def test_light_state(
|
||||
entity_id = f"{Platform.LIGHT}.{TEST_NVR_NAME}_floodlight"
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["brightness"] == 255
|
||||
|
||||
|
||||
@ -60,7 +63,7 @@ async def test_light_brightness_none(
|
||||
entity_id = f"{Platform.LIGHT}.{TEST_NVR_NAME}_floodlight"
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["brightness"] is None
|
||||
|
||||
|
||||
@ -166,7 +169,7 @@ async def test_host_light_state(
|
||||
entity_id = f"{Platform.LIGHT}.{TEST_NVR_NAME}_status_led"
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
|
||||
async def test_host_light_turn_off(
|
||||
|
@ -7,15 +7,9 @@ control of RFLink switch devices.
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS, LightState
|
||||
from homeassistant.components.rflink.entity import EVENT_BUTTON_PRESSED
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||
from homeassistant.core import CoreState, HomeAssistant, State, callback
|
||||
|
||||
from .test_init import mock_rflink
|
||||
@ -387,14 +381,14 @@ async def test_set_level_command(
|
||||
# should affect state
|
||||
state = hass.states.get(f"{DOMAIN}.l1")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 170
|
||||
# turn off
|
||||
event_callback({"id": "newkaku_12345678_0", "command": "off"})
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(f"{DOMAIN}.l1")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
# off light shouldn't have brightness
|
||||
assert not state.attributes.get(ATTR_BRIGHTNESS)
|
||||
# turn on
|
||||
@ -402,7 +396,7 @@ async def test_set_level_command(
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(f"{DOMAIN}.l1")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 170
|
||||
|
||||
# test sending command to a no dimmable device
|
||||
@ -411,7 +405,7 @@ async def test_set_level_command(
|
||||
# should NOT affect state
|
||||
state = hass.states.get(f"{DOMAIN}.l2")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert not state.attributes.get(ATTR_BRIGHTNESS)
|
||||
|
||||
# test sending command to a dimmable device
|
||||
@ -420,7 +414,7 @@ async def test_set_level_command(
|
||||
# should affect state
|
||||
state = hass.states.get(f"{DOMAIN}.l3")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 85
|
||||
|
||||
# test sending command to a hybrid device
|
||||
@ -429,7 +423,7 @@ async def test_set_level_command(
|
||||
# should affect state
|
||||
state = hass.states.get(f"{DOMAIN}.l4")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 255
|
||||
|
||||
event_callback({"id": "test_hybrid", "command": "off"})
|
||||
@ -437,7 +431,7 @@ async def test_set_level_command(
|
||||
# should affect state
|
||||
state = hass.states.get(f"{DOMAIN}.l4")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
# off light shouldn't have brightness
|
||||
assert not state.attributes.get(ATTR_BRIGHTNESS)
|
||||
|
||||
@ -446,7 +440,7 @@ async def test_set_level_command(
|
||||
# should affect state
|
||||
state = hass.states.get(f"{DOMAIN}.l4")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 0
|
||||
|
||||
|
||||
@ -595,10 +589,10 @@ async def test_restore_state(
|
||||
mock_restore_cache(
|
||||
hass,
|
||||
(
|
||||
State(f"{DOMAIN}.l1", STATE_ON, {ATTR_BRIGHTNESS: "123"}),
|
||||
State(f"{DOMAIN}.l2", STATE_ON, {ATTR_BRIGHTNESS: "321"}),
|
||||
State(f"{DOMAIN}.l3", STATE_OFF),
|
||||
State(f"{DOMAIN}.l5", STATE_ON, {ATTR_BRIGHTNESS: "222"}),
|
||||
State(f"{DOMAIN}.l1", LightState.ON, {ATTR_BRIGHTNESS: "123"}),
|
||||
State(f"{DOMAIN}.l2", LightState.ON, {ATTR_BRIGHTNESS: "321"}),
|
||||
State(f"{DOMAIN}.l3", LightState.OFF),
|
||||
State(f"{DOMAIN}.l5", LightState.ON, {ATTR_BRIGHTNESS: "222"}),
|
||||
),
|
||||
)
|
||||
|
||||
@ -610,24 +604,24 @@ async def test_restore_state(
|
||||
# hybrid light must restore brightness
|
||||
state = hass.states.get(f"{DOMAIN}.l1")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 123
|
||||
|
||||
# normal light do NOT must restore brightness
|
||||
state = hass.states.get(f"{DOMAIN}.l2")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert not state.attributes.get(ATTR_BRIGHTNESS)
|
||||
|
||||
# OFF state also restores (or not)
|
||||
state = hass.states.get(f"{DOMAIN}.l3")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# not cached light must default values
|
||||
state = hass.states.get(f"{DOMAIN}.l4")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
# off light shouldn't have brightness
|
||||
assert not state.attributes.get(ATTR_BRIGHTNESS)
|
||||
assert state.attributes["assumed_state"]
|
||||
@ -635,5 +629,5 @@ async def test_restore_state(
|
||||
# test coverage for dimmable light
|
||||
state = hass.states.get(f"{DOMAIN}.l5")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 222
|
||||
|
@ -28,14 +28,10 @@ from homeassistant.components.light import (
|
||||
SERVICE_TURN_ON,
|
||||
ColorMode,
|
||||
LightEntityFeature,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.components.shelly.const import SHELLY_PLUS_RGBW_CHANNELS
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_SUPPORTED_FEATURES
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
@ -56,7 +52,7 @@ async def test_block_device_rgbw_bulb(
|
||||
# Test initial
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_RGBW_COLOR] == (45, 55, 65, 70)
|
||||
assert attributes[ATTR_BRIGHTNESS] == 48
|
||||
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == [
|
||||
@ -79,7 +75,7 @@ async def test_block_device_rgbw_bulb(
|
||||
turn="off"
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn on, RGBW = [70, 80, 90, 20], brightness = 33, effect = Flash
|
||||
mock_block_device.blocks[LIGHT_BLOCK_ID].set_state.reset_mock()
|
||||
@ -99,7 +95,7 @@ async def test_block_device_rgbw_bulb(
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_COLOR_MODE] == ColorMode.RGBW
|
||||
assert attributes[ATTR_RGBW_COLOR] == (70, 80, 90, 30)
|
||||
assert attributes[ATTR_BRIGHTNESS] == 33
|
||||
@ -118,7 +114,7 @@ async def test_block_device_rgbw_bulb(
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_COLOR_MODE] == ColorMode.COLOR_TEMP
|
||||
assert attributes[ATTR_COLOR_TEMP_KELVIN] == 3500
|
||||
|
||||
@ -145,7 +141,7 @@ async def test_block_device_rgb_bulb(
|
||||
# Test initial
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_RGB_COLOR] == (45, 55, 65)
|
||||
assert attributes[ATTR_BRIGHTNESS] == 48
|
||||
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == [
|
||||
@ -171,7 +167,7 @@ async def test_block_device_rgb_bulb(
|
||||
turn="off"
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn on, RGB = [70, 80, 90], brightness = 33, effect = Flash
|
||||
mock_block_device.blocks[LIGHT_BLOCK_ID].set_state.reset_mock()
|
||||
@ -191,7 +187,7 @@ async def test_block_device_rgb_bulb(
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_COLOR_MODE] == ColorMode.RGB
|
||||
assert attributes[ATTR_RGB_COLOR] == (70, 80, 90)
|
||||
assert attributes[ATTR_BRIGHTNESS] == 33
|
||||
@ -210,7 +206,7 @@ async def test_block_device_rgb_bulb(
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_COLOR_MODE] == ColorMode.COLOR_TEMP
|
||||
assert attributes[ATTR_COLOR_TEMP_KELVIN] == 3500
|
||||
|
||||
@ -227,7 +223,7 @@ async def test_block_device_rgb_bulb(
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_EFFECT] == "Off"
|
||||
assert "Effect 'Breath' not supported" in caplog.text
|
||||
|
||||
@ -263,7 +259,7 @@ async def test_block_device_white_bulb(
|
||||
# Test initial
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_BRIGHTNESS] == 128
|
||||
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
|
||||
assert attributes[ATTR_SUPPORTED_FEATURES] == LightEntityFeature.TRANSITION
|
||||
@ -280,7 +276,7 @@ async def test_block_device_white_bulb(
|
||||
turn="off"
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn on, brightness = 33
|
||||
mock_block_device.blocks[LIGHT_BLOCK_ID].set_state.reset_mock()
|
||||
@ -295,7 +291,7 @@ async def test_block_device_white_bulb(
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_BRIGHTNESS] == 33
|
||||
|
||||
entry = entity_registry.async_get(entity_id)
|
||||
@ -348,7 +344,7 @@ async def test_block_device_support_transition(
|
||||
turn="on", transition=4000
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
# Turn off, TRANSITION = 6, limit to 5000ms
|
||||
mock_block_device.blocks[LIGHT_BLOCK_ID].set_state.reset_mock()
|
||||
@ -362,7 +358,7 @@ async def test_block_device_support_transition(
|
||||
turn="off", transition=5000
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
entry = entity_registry.async_get(entity_id)
|
||||
assert entry
|
||||
@ -397,7 +393,7 @@ async def test_block_device_relay_app_type_light(
|
||||
# Test initial
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.ONOFF]
|
||||
assert attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
|
||||
@ -413,7 +409,7 @@ async def test_block_device_relay_app_type_light(
|
||||
turn="off"
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn on
|
||||
mock_block_device.blocks[RELAY_BLOCK_ID].set_state.reset_mock()
|
||||
@ -427,7 +423,7 @@ async def test_block_device_relay_app_type_light(
|
||||
turn="on"
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
entry = entity_registry.async_get(entity_id)
|
||||
assert entry
|
||||
@ -462,7 +458,7 @@ async def test_rpc_device_switch_type_lights_mode(
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
assert hass.states.get(entity_id).state == LightState.ON
|
||||
|
||||
mutate_rpc_device_status(monkeypatch, mock_rpc_device, "switch:0", "output", False)
|
||||
await hass.services.async_call(
|
||||
@ -472,7 +468,7 @@ async def test_rpc_device_switch_type_lights_mode(
|
||||
blocking=True,
|
||||
)
|
||||
mock_rpc_device.mock_update()
|
||||
assert hass.states.get(entity_id).state == STATE_OFF
|
||||
assert hass.states.get(entity_id).state == LightState.OFF
|
||||
|
||||
entry = entity_registry.async_get(entity_id)
|
||||
assert entry
|
||||
@ -500,7 +496,7 @@ async def test_rpc_light(
|
||||
|
||||
mock_rpc_device.call_rpc.assert_called_once_with("Light.Set", {"id": 0, "on": True})
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 135
|
||||
|
||||
# Turn off
|
||||
@ -518,7 +514,7 @@ async def test_rpc_light(
|
||||
"Light.Set", {"id": 0, "on": False}
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn on, brightness = 33
|
||||
mock_rpc_device.call_rpc.reset_mock()
|
||||
@ -537,7 +533,7 @@ async def test_rpc_light(
|
||||
"Light.Set", {"id": 0, "on": True, "brightness": 13}
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 33
|
||||
|
||||
# Turn on, transition = 10.1
|
||||
@ -555,7 +551,7 @@ async def test_rpc_light(
|
||||
"Light.Set", {"id": 0, "on": True, "transition_duration": 10.1}
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
# Turn off, transition = 0.4, should be limited to 0.5
|
||||
mock_rpc_device.call_rpc.reset_mock()
|
||||
@ -574,7 +570,7 @@ async def test_rpc_light(
|
||||
)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
entry = entity_registry.async_get(entity_id)
|
||||
assert entry
|
||||
@ -597,7 +593,7 @@ async def test_rpc_device_rgb_profile(
|
||||
# Test initial
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_RGB_COLOR] == (45, 55, 65)
|
||||
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.RGB]
|
||||
assert attributes[ATTR_SUPPORTED_FEATURES] == LightEntityFeature.TRANSITION
|
||||
@ -619,7 +615,7 @@ async def test_rpc_device_rgb_profile(
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_COLOR_MODE] == ColorMode.RGB
|
||||
assert attributes[ATTR_RGB_COLOR] == (70, 80, 90)
|
||||
|
||||
@ -644,7 +640,7 @@ async def test_rpc_device_rgbw_profile(
|
||||
# Test initial
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_RGBW_COLOR] == (21, 22, 23, 120)
|
||||
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.RGBW]
|
||||
assert attributes[ATTR_SUPPORTED_FEATURES] == LightEntityFeature.TRANSITION
|
||||
@ -669,7 +665,7 @@ async def test_rpc_device_rgbw_profile(
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
attributes = state.attributes
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert attributes[ATTR_COLOR_MODE] == ColorMode.RGBW
|
||||
assert attributes[ATTR_RGBW_COLOR] == (72, 82, 92, 128)
|
||||
|
||||
@ -701,7 +697,7 @@ async def test_rpc_rgbw_device_light_mode_remove_others(
|
||||
# verify we have 4 lights
|
||||
for i in range(SHELLY_PLUS_RGBW_CHANNELS):
|
||||
entity_id = f"light.test_light_{i}"
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
assert hass.states.get(entity_id).state == LightState.ON
|
||||
entry = entity_registry.async_get(entity_id)
|
||||
assert entry
|
||||
assert entry.unique_id == f"123456789ABC-light:{i}"
|
||||
@ -746,7 +742,7 @@ async def test_rpc_rgbw_device_rgb_w_modes_remove_others(
|
||||
|
||||
# verify we have RGB/w light
|
||||
entity_id = f"light.test_{active_mode}_0"
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
assert hass.states.get(entity_id).state == LightState.ON
|
||||
entry = entity_registry.async_get(entity_id)
|
||||
assert entry
|
||||
assert entry.unique_id == f"123456789ABC-{active_mode}:0"
|
||||
|
@ -1,8 +1,8 @@
|
||||
"""The tests for SleepIQ light platform."""
|
||||
|
||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN, LightState
|
||||
from homeassistant.components.sleepiq.coordinator import LONGER_UPDATE_INTERVAL
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.util.dt import utcnow
|
||||
@ -60,7 +60,7 @@ async def test_switch_get_states(hass: HomeAssistant, mock_asyncsleepiq) -> None
|
||||
|
||||
assert (
|
||||
hass.states.get(f"light.sleepnumber_{BED_NAME_LOWER}_light_1").state
|
||||
== STATE_OFF
|
||||
== LightState.OFF
|
||||
)
|
||||
mock_asyncsleepiq.beds[BED_ID].foundation.lights[0].is_on = True
|
||||
|
||||
@ -68,5 +68,6 @@ async def test_switch_get_states(hass: HomeAssistant, mock_asyncsleepiq) -> None
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
assert (
|
||||
hass.states.get(f"light.sleepnumber_{BED_NAME_LOWER}_light_1").state == STATE_ON
|
||||
hass.states.get(f"light.sleepnumber_{BED_NAME_LOWER}_light_1").state
|
||||
== LightState.ON
|
||||
)
|
||||
|
@ -10,6 +10,7 @@ from homeassistant.components.light import (
|
||||
ATTR_SUPPORTED_COLOR_MODES,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
ColorMode,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.components.switch_as_x.config_flow import SwitchAsXConfigFlowHandler
|
||||
@ -84,7 +85,7 @@ async def test_light_service_calls(hass: HomeAssistant) -> None:
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_ON
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.ON
|
||||
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
@ -94,7 +95,7 @@ async def test_light_service_calls(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
assert hass.states.get("switch.decorative_lights").state == STATE_OFF
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_OFF
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.OFF
|
||||
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
@ -104,7 +105,7 @@ async def test_light_service_calls(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
assert hass.states.get("switch.decorative_lights").state == STATE_ON
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_ON
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.ON
|
||||
assert (
|
||||
hass.states.get("light.decorative_lights").attributes.get(ATTR_COLOR_MODE)
|
||||
== ColorMode.ONOFF
|
||||
@ -118,7 +119,7 @@ async def test_light_service_calls(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
assert hass.states.get("switch.decorative_lights").state == STATE_OFF
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_OFF
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.OFF
|
||||
|
||||
|
||||
async def test_switch_service_calls(hass: HomeAssistant) -> None:
|
||||
@ -141,7 +142,7 @@ async def test_switch_service_calls(hass: HomeAssistant) -> None:
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_ON
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.ON
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
@ -151,7 +152,7 @@ async def test_switch_service_calls(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
assert hass.states.get("switch.decorative_lights").state == STATE_OFF
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_OFF
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.OFF
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
@ -161,7 +162,7 @@ async def test_switch_service_calls(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
assert hass.states.get("switch.decorative_lights").state == STATE_ON
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_ON
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.ON
|
||||
|
||||
|
||||
async def test_light_service_calls_inverted(hass: HomeAssistant) -> None:
|
||||
@ -184,7 +185,7 @@ async def test_light_service_calls_inverted(hass: HomeAssistant) -> None:
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_ON
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.ON
|
||||
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
@ -194,7 +195,7 @@ async def test_light_service_calls_inverted(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
assert hass.states.get("switch.decorative_lights").state == STATE_OFF
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_OFF
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.OFF
|
||||
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
@ -204,7 +205,7 @@ async def test_light_service_calls_inverted(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
assert hass.states.get("switch.decorative_lights").state == STATE_ON
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_ON
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.ON
|
||||
assert (
|
||||
hass.states.get("light.decorative_lights").attributes.get(ATTR_COLOR_MODE)
|
||||
== ColorMode.ONOFF
|
||||
@ -218,7 +219,7 @@ async def test_light_service_calls_inverted(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
assert hass.states.get("switch.decorative_lights").state == STATE_OFF
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_OFF
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.OFF
|
||||
|
||||
|
||||
async def test_switch_service_calls_inverted(hass: HomeAssistant) -> None:
|
||||
@ -241,7 +242,7 @@ async def test_switch_service_calls_inverted(hass: HomeAssistant) -> None:
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_ON
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.ON
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
@ -251,7 +252,7 @@ async def test_switch_service_calls_inverted(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
assert hass.states.get("switch.decorative_lights").state == STATE_OFF
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_OFF
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.OFF
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
@ -261,4 +262,4 @@ async def test_switch_service_calls_inverted(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
assert hass.states.get("switch.decorative_lights").state == STATE_ON
|
||||
assert hass.states.get("light.decorative_lights").state == STATE_ON
|
||||
assert hass.states.get("light.decorative_lights").state == LightState.ON
|
||||
|
@ -13,9 +13,9 @@ from hatasmota.utils import (
|
||||
)
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.light import LightEntityFeature
|
||||
from homeassistant.components.light import LightEntityFeature, LightState
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .test_common import (
|
||||
@ -353,30 +353,30 @@ async def test_controlling_state_via_mqtt_on_off(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert not state.attributes["color_mode"]
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON"}')
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("color_mode") == "onoff"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"OFF"}')
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert not state.attributes["color_mode"]
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"ON"}')
|
||||
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("color_mode") == "onoff"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"OFF"}')
|
||||
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert not state.attributes["color_mode"]
|
||||
|
||||
|
||||
@ -404,25 +404,25 @@ async def test_controlling_state_via_mqtt_ct(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert not state.attributes["color_mode"]
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON"}')
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"OFF"}')
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert not state.attributes["color_mode"]
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 128
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
@ -430,7 +430,7 @@ async def test_controlling_state_via_mqtt_ct(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","CT":300}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("color_temp") == 300
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
@ -439,7 +439,7 @@ async def test_controlling_state_via_mqtt_ct(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Color":"255,128"}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("color_temp") == 300
|
||||
assert state.attributes.get("brightness") == 128
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
@ -469,25 +469,25 @@ async def test_controlling_state_via_mqtt_rgbw(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert not state.attributes["color_mode"]
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON"}')
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("color_mode") == "hs"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"OFF"}')
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert not state.attributes["color_mode"]
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50,"White":0}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 128
|
||||
assert state.attributes.get("color_mode") == "hs"
|
||||
|
||||
@ -495,7 +495,7 @@ async def test_controlling_state_via_mqtt_rgbw(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":75,"White":75}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 191
|
||||
assert state.attributes.get("color_mode") == "white"
|
||||
|
||||
@ -505,7 +505,7 @@ async def test_controlling_state_via_mqtt_rgbw(
|
||||
'{"POWER":"ON","Dimmer":50,"HSBColor":"30,100,50","White":0}',
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 128
|
||||
assert state.attributes.get("hs_color") == (30, 100)
|
||||
assert state.attributes.get("color_mode") == "hs"
|
||||
@ -514,7 +514,7 @@ async def test_controlling_state_via_mqtt_rgbw(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":50}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 128
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("color_mode") == "white"
|
||||
@ -523,7 +523,7 @@ async def test_controlling_state_via_mqtt_rgbw(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":0}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 0
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("color_mode") == "white"
|
||||
@ -532,18 +532,18 @@ async def test_controlling_state_via_mqtt_rgbw(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Scheme":3}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("effect") == "Cycle down"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"ON"}')
|
||||
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"OFF"}')
|
||||
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_rgbww(
|
||||
@ -570,25 +570,25 @@ async def test_controlling_state_via_mqtt_rgbww(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert not state.attributes["color_mode"]
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON"}')
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"OFF"}')
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert not state.attributes["color_mode"]
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 128
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
@ -598,7 +598,7 @@ async def test_controlling_state_via_mqtt_rgbww(
|
||||
'{"POWER":"ON","Dimmer":50,"HSBColor":"30,100,50","White":0}',
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("hs_color") == (30, 100)
|
||||
assert state.attributes.get("color_mode") == "hs"
|
||||
|
||||
@ -606,7 +606,7 @@ async def test_controlling_state_via_mqtt_rgbww(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":50}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
# Setting white > 0 should clear the color
|
||||
assert not state.attributes.get("hs_color")
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
@ -615,7 +615,7 @@ async def test_controlling_state_via_mqtt_rgbww(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","CT":300}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("color_temp") == 300
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
@ -623,7 +623,7 @@ async def test_controlling_state_via_mqtt_rgbww(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":0}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
# Setting white to 0 should clear the color_temp
|
||||
assert not state.attributes.get("color_temp")
|
||||
assert state.attributes.get("hs_color") == (30, 100)
|
||||
@ -633,18 +633,18 @@ async def test_controlling_state_via_mqtt_rgbww(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Scheme":3}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("effect") == "Cycle down"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"ON"}')
|
||||
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"OFF"}')
|
||||
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_rgbww_tuya(
|
||||
@ -672,25 +672,25 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert not state.attributes["color_mode"]
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON"}')
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"OFF"}')
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert not state.attributes["color_mode"]
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 128
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
@ -700,7 +700,7 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(
|
||||
'{"POWER":"ON","HSBColor":"30,100,0","White":0}',
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("hs_color") == (30, 100)
|
||||
assert state.attributes.get("color_mode") == "hs"
|
||||
|
||||
@ -710,7 +710,7 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(
|
||||
'{"POWER":"ON","Dimmer":0}',
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("hs_color") == (30, 100)
|
||||
assert state.attributes.get("color_mode") == "hs"
|
||||
|
||||
@ -718,7 +718,7 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50,"White":50}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
# Setting white > 0 should clear the color
|
||||
assert not state.attributes.get("hs_color")
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
@ -727,7 +727,7 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","CT":300}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("color_temp") == 300
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
@ -735,7 +735,7 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":0}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
# Setting white to 0 should clear the color_temp
|
||||
assert not state.attributes.get("color_temp")
|
||||
assert state.attributes.get("color_mode") == "hs"
|
||||
@ -744,18 +744,18 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Scheme":3}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("effect") == "Cycle down"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"ON"}')
|
||||
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"OFF"}')
|
||||
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_on_off(
|
||||
@ -777,7 +777,7 @@ async def test_sending_mqtt_commands_on_off(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@ -791,7 +791,7 @@ async def test_sending_mqtt_commands_on_off(
|
||||
|
||||
# Tasmota is not optimistic, the state should still be off
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn the light off and verify MQTT message is sent
|
||||
await common.async_turn_off(hass, "light.tasmota_test")
|
||||
@ -821,7 +821,7 @@ async def test_sending_mqtt_commands_rgbww_tuya(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@ -835,7 +835,7 @@ async def test_sending_mqtt_commands_rgbww_tuya(
|
||||
|
||||
# Tasmota is not optimistic, the state should still be off
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn the light off and verify MQTT message is sent
|
||||
await common.async_turn_off(hass, "light.tasmota_test")
|
||||
@ -871,7 +871,7 @@ async def test_sending_mqtt_commands_rgbw_legacy(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@ -885,7 +885,7 @@ async def test_sending_mqtt_commands_rgbw_legacy(
|
||||
|
||||
# Tasmota is not optimistic, the state should still be off
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn the light off and verify MQTT message is sent
|
||||
await common.async_turn_off(hass, "light.tasmota_test")
|
||||
@ -970,7 +970,7 @@ async def test_sending_mqtt_commands_rgbw(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@ -984,7 +984,7 @@ async def test_sending_mqtt_commands_rgbw(
|
||||
|
||||
# Tasmota is not optimistic, the state should still be off
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn the light off and verify MQTT message is sent
|
||||
await common.async_turn_off(hass, "light.tasmota_test")
|
||||
@ -1069,7 +1069,7 @@ async def test_sending_mqtt_commands_rgbww(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@ -1083,7 +1083,7 @@ async def test_sending_mqtt_commands_rgbww(
|
||||
|
||||
# Tasmota is not optimistic, the state should still be off
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn the light off and verify MQTT message is sent
|
||||
await common.async_turn_off(hass, "light.tasmota_test")
|
||||
@ -1147,7 +1147,7 @@ async def test_sending_mqtt_commands_power_unlinked(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@ -1161,7 +1161,7 @@ async def test_sending_mqtt_commands_power_unlinked(
|
||||
|
||||
# Tasmota is not optimistic, the state should still be off
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn the light off and verify MQTT message is sent
|
||||
await common.async_turn_off(hass, "light.tasmota_test")
|
||||
@ -1200,7 +1200,7 @@ async def test_transition(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@ -1252,7 +1252,7 @@ async def test_transition(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 128
|
||||
|
||||
# Dim the light from 50->0: Speed should be 6*2*2=24
|
||||
@ -1270,7 +1270,7 @@ async def test_transition(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":100}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 255
|
||||
|
||||
# Dim the light from 100->0: Speed should be 0
|
||||
@ -1293,7 +1293,7 @@ async def test_transition(
|
||||
),
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 128
|
||||
assert state.attributes.get("rgb_color") == (0, 255, 0)
|
||||
|
||||
@ -1319,7 +1319,7 @@ async def test_transition(
|
||||
'{"POWER":"ON","Dimmer":100, "Color":"0,255,0","HSBColor":"120,100,50"}',
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 255
|
||||
assert state.attributes.get("rgb_color") == (0, 255, 0)
|
||||
|
||||
@ -1345,7 +1345,7 @@ async def test_transition(
|
||||
'{"POWER":"ON","Dimmer":50, "CT":153, "White":50}',
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 128
|
||||
assert state.attributes.get("color_temp") == 153
|
||||
|
||||
@ -1364,7 +1364,7 @@ async def test_transition(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50, "CT":500}'
|
||||
)
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get("brightness") == 128
|
||||
assert state.attributes.get("color_temp") == 500
|
||||
|
||||
@ -1399,7 +1399,7 @@ async def test_transition_fixed(
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.tasmota_test")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
@ -16,13 +16,12 @@ from homeassistant.components.light import (
|
||||
ATTR_TRANSITION,
|
||||
ColorMode,
|
||||
LightEntityFeature,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
@ -201,7 +200,7 @@ async def test_template_state_invalid(
|
||||
) -> None:
|
||||
"""Test template state with render error."""
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes["color_mode"] is None
|
||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
||||
assert state.attributes["supported_features"] == supported_features
|
||||
@ -221,7 +220,7 @@ async def test_template_state_invalid(
|
||||
)
|
||||
async def test_template_state_text(hass: HomeAssistant, setup_light) -> None:
|
||||
"""Test the state text of a template."""
|
||||
set_state = STATE_ON
|
||||
set_state = LightState.ON
|
||||
hass.states.async_set("light.test_state", set_state)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.test_template_light")
|
||||
@ -230,7 +229,7 @@ async def test_template_state_text(hass: HomeAssistant, setup_light) -> None:
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
|
||||
set_state = STATE_OFF
|
||||
set_state = LightState.OFF
|
||||
hass.states.async_set("light.test_state", set_state)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.test_template_light")
|
||||
@ -246,12 +245,12 @@ async def test_template_state_text(hass: HomeAssistant, setup_light) -> None:
|
||||
[
|
||||
(
|
||||
"{{ 1 == 1 }}",
|
||||
STATE_ON,
|
||||
LightState.ON,
|
||||
ColorMode.BRIGHTNESS,
|
||||
),
|
||||
(
|
||||
"{{ 1 == 2 }}",
|
||||
STATE_OFF,
|
||||
LightState.OFF,
|
||||
None,
|
||||
),
|
||||
],
|
||||
@ -350,11 +349,11 @@ async def test_on_action(
|
||||
hass: HomeAssistant, setup_light, calls: list[ServiceCall]
|
||||
) -> None:
|
||||
"""Test on action."""
|
||||
hass.states.async_set("light.test_state", STATE_OFF)
|
||||
hass.states.async_set("light.test_state", LightState.OFF)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes["color_mode"] is None
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -370,7 +369,7 @@ async def test_on_action(
|
||||
assert calls[-1].data["action"] == "turn_on"
|
||||
assert calls[-1].data["caller"] == "light.test_template_light"
|
||||
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes["color_mode"] is None
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -410,11 +409,11 @@ async def test_on_action_with_transition(
|
||||
hass: HomeAssistant, setup_light, calls: list[ServiceCall]
|
||||
) -> None:
|
||||
"""Test on action with transition."""
|
||||
hass.states.async_set("light.test_state", STATE_OFF)
|
||||
hass.states.async_set("light.test_state", LightState.OFF)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes["color_mode"] is None
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == LightEntityFeature.TRANSITION
|
||||
@ -429,7 +428,7 @@ async def test_on_action_with_transition(
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["transition"] == 5
|
||||
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes["color_mode"] is None
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == LightEntityFeature.TRANSITION
|
||||
@ -452,11 +451,11 @@ async def test_on_action_optimistic(
|
||||
calls: list[ServiceCall],
|
||||
) -> None:
|
||||
"""Test on action with optimistic state."""
|
||||
hass.states.async_set("light.test_state", STATE_OFF)
|
||||
hass.states.async_set("light.test_state", LightState.OFF)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes["color_mode"] is None
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -472,7 +471,7 @@ async def test_on_action_optimistic(
|
||||
assert len(calls) == 1
|
||||
assert calls[-1].data["action"] == "turn_on"
|
||||
assert calls[-1].data["caller"] == "light.test_template_light"
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -489,7 +488,7 @@ async def test_on_action_optimistic(
|
||||
assert calls[-1].data["action"] == "set_level"
|
||||
assert calls[-1].data["brightness"] == 100
|
||||
assert calls[-1].data["caller"] == "light.test_template_light"
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -511,11 +510,11 @@ async def test_off_action(
|
||||
hass: HomeAssistant, setup_light, calls: list[ServiceCall]
|
||||
) -> None:
|
||||
"""Test off action."""
|
||||
hass.states.async_set("light.test_state", STATE_ON)
|
||||
hass.states.async_set("light.test_state", LightState.ON)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -530,7 +529,7 @@ async def test_off_action(
|
||||
assert len(calls) == 1
|
||||
assert calls[-1].data["action"] == "turn_off"
|
||||
assert calls[-1].data["caller"] == "light.test_template_light"
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -570,11 +569,11 @@ async def test_off_action_with_transition(
|
||||
hass: HomeAssistant, setup_light, calls: list[ServiceCall]
|
||||
) -> None:
|
||||
"""Test off action with transition."""
|
||||
hass.states.async_set("light.test_state", STATE_ON)
|
||||
hass.states.async_set("light.test_state", LightState.ON)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == LightEntityFeature.TRANSITION
|
||||
@ -588,7 +587,7 @@ async def test_off_action_with_transition(
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["transition"] == 2
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == LightEntityFeature.TRANSITION
|
||||
@ -610,7 +609,7 @@ async def test_off_action_optimistic(
|
||||
) -> None:
|
||||
"""Test off action with optimistic state."""
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes["color_mode"] is None
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -624,7 +623,7 @@ async def test_off_action_optimistic(
|
||||
|
||||
assert len(calls) == 1
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes["color_mode"] is None
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -664,7 +663,7 @@ async def test_level_action_no_template(
|
||||
assert calls[-1].data["caller"] == "light.test_template_light"
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["brightness"] == 124
|
||||
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
@ -706,7 +705,7 @@ async def test_level_template(
|
||||
await async_setup_light(hass, count, light_config)
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.attributes.get("brightness") == expected_level
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == expected_color_mode
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -743,7 +742,7 @@ async def test_temperature_template(
|
||||
await async_setup_light(hass, count, light_config)
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.attributes.get("color_temp") == expected_temp
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == expected_color_mode
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.COLOR_TEMP]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -785,7 +784,7 @@ async def test_temperature_action_no_template(
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state is not None
|
||||
assert state.attributes.get("color_temp") == 345
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == ColorMode.COLOR_TEMP
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.COLOR_TEMP]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -834,7 +833,7 @@ async def test_icon_template(hass: HomeAssistant, setup_light) -> None:
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.attributes.get("icon") == ""
|
||||
|
||||
state = hass.states.async_set("light.test_state", STATE_ON)
|
||||
state = hass.states.async_set("light.test_state", LightState.ON)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
@ -863,7 +862,7 @@ async def test_entity_picture_template(hass: HomeAssistant, setup_light) -> None
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.attributes.get("entity_picture") == ""
|
||||
|
||||
state = hass.states.async_set("light.test_state", STATE_ON)
|
||||
state = hass.states.async_set("light.test_state", LightState.ON)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
@ -906,7 +905,7 @@ async def test_legacy_color_action_no_template(
|
||||
assert calls[-1].data["s"] == 50
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == ColorMode.HS
|
||||
assert state.attributes.get("hs_color") == (40, 50)
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.HS]
|
||||
@ -948,7 +947,7 @@ async def test_hs_color_action_no_template(
|
||||
assert calls[-1].data["s"] == 50
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == ColorMode.HS
|
||||
assert state.attributes.get("hs_color") == (40, 50)
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.HS]
|
||||
@ -991,7 +990,7 @@ async def test_rgb_color_action_no_template(
|
||||
assert calls[-1].data["b"] == 192
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == ColorMode.RGB
|
||||
assert state.attributes.get("rgb_color") == (160, 78, 192)
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.RGB]
|
||||
@ -1038,7 +1037,7 @@ async def test_rgbw_color_action_no_template(
|
||||
assert calls[-1].data["w"] == 25
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == ColorMode.RGBW
|
||||
assert state.attributes.get("rgbw_color") == (160, 78, 192, 25)
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.RGBW]
|
||||
@ -1086,7 +1085,7 @@ async def test_rgbww_color_action_no_template(
|
||||
assert calls[-1].data["ww"] == 55
|
||||
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == ColorMode.RGBWW
|
||||
assert state.attributes.get("rgbww_color") == (160, 78, 192, 25, 55)
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.RGBWW]
|
||||
@ -1126,7 +1125,7 @@ async def test_legacy_color_template(
|
||||
await async_setup_light(hass, count, light_config)
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.attributes.get("hs_color") == expected_hs
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == expected_color_mode
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.HS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -1166,7 +1165,7 @@ async def test_hs_template(
|
||||
await async_setup_light(hass, count, light_config)
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.attributes.get("hs_color") == expected_hs
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == expected_color_mode
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.HS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -1207,7 +1206,7 @@ async def test_rgb_template(
|
||||
await async_setup_light(hass, count, light_config)
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.attributes.get("rgb_color") == expected_rgb
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == expected_color_mode
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.RGB]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -1249,7 +1248,7 @@ async def test_rgbw_template(
|
||||
await async_setup_light(hass, count, light_config)
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.attributes.get("rgbw_color") == expected_rgbw
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == expected_color_mode
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.RGBW]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -1296,7 +1295,7 @@ async def test_rgbww_template(
|
||||
await async_setup_light(hass, count, light_config)
|
||||
state = hass.states.get("light.test_template_light")
|
||||
assert state.attributes.get("rgbww_color") == expected_rgbww
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["color_mode"] == expected_color_mode
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.RGBWW]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
@ -1866,14 +1865,14 @@ async def test_available_template_with_entities(
|
||||
) -> None:
|
||||
"""Test availability templates with values from other entities."""
|
||||
# When template returns true..
|
||||
hass.states.async_set(_STATE_AVAILABILITY_BOOLEAN, STATE_ON)
|
||||
hass.states.async_set(_STATE_AVAILABILITY_BOOLEAN, LightState.ON)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Device State should not be unavailable
|
||||
assert hass.states.get("light.test_template_light").state != STATE_UNAVAILABLE
|
||||
|
||||
# When Availability template returns false
|
||||
hass.states.async_set(_STATE_AVAILABILITY_BOOLEAN, STATE_OFF)
|
||||
hass.states.async_set(_STATE_AVAILABILITY_BOOLEAN, LightState.OFF)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# device state should be unavailable
|
||||
|
@ -10,7 +10,7 @@ from kasa import (
|
||||
AuthenticationError,
|
||||
DeviceType,
|
||||
KasaException,
|
||||
LightState,
|
||||
LightState as KasaLightState,
|
||||
Module,
|
||||
TimeoutError,
|
||||
)
|
||||
@ -34,16 +34,11 @@ from homeassistant.components.light import (
|
||||
ATTR_XY_COLOR,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
EFFECT_OFF,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.components.tplink.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_HOST,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@ -163,13 +158,13 @@ async def test_color_light(
|
||||
LIGHT_DOMAIN, "turn_off", BASE_PAYLOAD, blocking=True
|
||||
)
|
||||
light.set_state.assert_called_once_with(
|
||||
LightState(light_on=False, transition=KASA_TRANSITION_VALUE)
|
||||
KasaLightState(light_on=False, transition=KASA_TRANSITION_VALUE)
|
||||
)
|
||||
light.set_state.reset_mock()
|
||||
|
||||
await hass.services.async_call(LIGHT_DOMAIN, "turn_on", BASE_PAYLOAD, blocking=True)
|
||||
light.set_state.assert_called_once_with(
|
||||
LightState(light_on=True, transition=KASA_TRANSITION_VALUE)
|
||||
KasaLightState(light_on=True, transition=KASA_TRANSITION_VALUE)
|
||||
)
|
||||
light.set_state.reset_mock()
|
||||
|
||||
@ -455,7 +450,7 @@ async def test_off_at_start_light(hass: HomeAssistant) -> None:
|
||||
light.is_color = False
|
||||
light.is_variable_color_temp = False
|
||||
light.is_dimmable = False
|
||||
light.state = LightState(light_on=False)
|
||||
light.state = KasaLightState(light_on=False)
|
||||
|
||||
with _patch_discovery(device=device), _patch_connect(device=device):
|
||||
await async_setup_component(hass, tplink.DOMAIN, {tplink.DOMAIN: {}})
|
||||
@ -478,7 +473,7 @@ async def test_dimmer_turn_on_fix(hass: HomeAssistant) -> None:
|
||||
device = _mocked_device(modules=[Module.Light], alias="my_light")
|
||||
light = device.modules[Module.Light]
|
||||
device.device_type = DeviceType.Dimmer
|
||||
light.state = LightState(light_on=False)
|
||||
light.state = KasaLightState(light_on=False)
|
||||
|
||||
with _patch_discovery(device=device), _patch_connect(device=device):
|
||||
await async_setup_component(hass, tplink.DOMAIN, {tplink.DOMAIN: {}})
|
||||
@ -493,7 +488,7 @@ async def test_dimmer_turn_on_fix(hass: HomeAssistant) -> None:
|
||||
LIGHT_DOMAIN, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
|
||||
)
|
||||
light.set_state.assert_called_once_with(
|
||||
LightState(
|
||||
KasaLightState(
|
||||
light_on=True,
|
||||
brightness=None,
|
||||
hue=None,
|
||||
@ -530,7 +525,7 @@ async def test_smart_strip_effects(
|
||||
entity_id = "light.my_light"
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_EFFECT] == "Effect1"
|
||||
assert state.attributes[ATTR_EFFECT_LIST] == ["Off", "Effect1", "Effect2"]
|
||||
|
||||
@ -560,7 +555,7 @@ async def test_smart_strip_effects(
|
||||
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
|
||||
assert state.attributes[ATTR_EFFECT] == "Effect2"
|
||||
|
||||
# Test setting light effect off
|
||||
@ -573,7 +568,7 @@ async def test_smart_strip_effects(
|
||||
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
|
||||
assert state.attributes[ATTR_EFFECT] == "off"
|
||||
light.set_state.assert_not_called()
|
||||
|
||||
@ -588,7 +583,7 @@ async def test_smart_strip_effects(
|
||||
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
|
||||
assert state.attributes[ATTR_EFFECT] == "off"
|
||||
assert "Invalid effect Effect3 for" in caplog.text
|
||||
|
||||
@ -597,15 +592,15 @@ async def test_smart_strip_effects(
|
||||
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_EFFECT] == EFFECT_OFF
|
||||
|
||||
light.state = LightState(light_on=False)
|
||||
light.state = KasaLightState(light_on=False)
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=20))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes[ATTR_EFFECT] is None
|
||||
|
||||
await hass.services.async_call(
|
||||
@ -617,13 +612,13 @@ async def test_smart_strip_effects(
|
||||
light.set_state.assert_called_once()
|
||||
light.set_state.reset_mock()
|
||||
|
||||
light.state = LightState(light_on=True)
|
||||
light.state = KasaLightState(light_on=True)
|
||||
light_effect.effect_list = 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
|
||||
assert state.attributes[ATTR_EFFECT_LIST] is None
|
||||
|
||||
|
||||
@ -646,7 +641,7 @@ async def test_smart_strip_custom_random_effect(hass: HomeAssistant) -> None:
|
||||
entity_id = "light.my_light"
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@ -716,15 +711,15 @@ async def test_smart_strip_custom_random_effect(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
light.state = LightState(light_on=False)
|
||||
light.state = KasaLightState(light_on=False)
|
||||
light_effect.effect = LightEffect.LIGHT_EFFECTS_OFF
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=20))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes[ATTR_EFFECT] is None
|
||||
|
||||
await hass.services.async_call(
|
||||
@ -800,7 +795,7 @@ async def test_smart_strip_custom_random_effect_at_start(hass: HomeAssistant) ->
|
||||
entity_id = "light.my_light"
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
# fallback to set HSV when custom effect is not known so it does turn back on
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
@ -830,7 +825,7 @@ async def test_smart_strip_custom_sequence_effect(hass: HomeAssistant) -> None:
|
||||
entity_id = "light.my_light"
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@ -999,7 +994,7 @@ async def test_scene_effect_light(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state is STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["effect"] is EFFECT_OFF
|
||||
|
||||
await hass.services.async_call(
|
||||
@ -1021,7 +1016,7 @@ async def test_scene_effect_light(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state is STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
await hass.services.async_call(
|
||||
"scene",
|
||||
@ -1040,5 +1035,5 @@ async def test_scene_effect_light(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state is STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes["effect"] is EFFECT_OFF
|
||||
|
@ -16,15 +16,10 @@ from homeassistant.components.light import (
|
||||
ATTR_SUPPORTED_COLOR_MODES,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
ColorMode,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.components.tradfri.const import DOMAIN
|
||||
from homeassistant.const import (
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.const import SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import CommandStore, setup_integration
|
||||
@ -98,7 +93,7 @@ async def test_light_state(
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
for key, value in state_attributes.items():
|
||||
assert state.attributes[key] == value
|
||||
|
||||
@ -115,7 +110,7 @@ async def test_light_available(
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
await command_store.trigger_observe_callback(
|
||||
hass, device, {ATTR_REACHABLE_STATE: 0}
|
||||
@ -263,7 +258,7 @@ async def test_turn_on(
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
for key, value in state_attributes.items():
|
||||
# Allow some rounding error in color conversions.
|
||||
assert state.attributes[key] == pytest.approx(value, abs=0.01)
|
||||
@ -307,4 +302,4 @@ async def test_turn_off(
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
@ -7,15 +7,9 @@ from unittest.mock import AsyncMock, Mock
|
||||
from uiprotect.data import Light
|
||||
from uiprotect.data.types import LEDLevel
|
||||
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS, LightState
|
||||
from homeassistant.components.unifiprotect.const import DEFAULT_ATTRIBUTION
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_ENTITY_ID,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
@ -62,7 +56,7 @@ async def test_light_setup(
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
||||
|
||||
|
||||
@ -88,7 +82,7 @@ async def test_light_update(
|
||||
|
||||
state = hass.states.get("light.test_light")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 128
|
||||
|
||||
|
||||
|
@ -15,8 +15,9 @@ from homeassistant.components.light import (
|
||||
ATTR_SUPPORTED_COLOR_MODES,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
ColorMode,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@ -119,7 +120,7 @@ async def test_light_update_entity(
|
||||
assert state.attributes.get(ATTR_COLOR_TEMP) == 432
|
||||
assert state.attributes.get(ATTR_SUPPORTED_COLOR_MODES) == [ColorMode.COLOR_TEMP]
|
||||
assert state.attributes.get(ATTR_COLOR_MODE) == ColorMode.COLOR_TEMP
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
# Off state.
|
||||
pywemo_bridge_light.state["onoff"] = 0
|
||||
@ -129,4 +130,4 @@ async def test_light_update_entity(
|
||||
{ATTR_ENTITY_ID: [wemo_entity.entity_id]},
|
||||
blocking=True,
|
||||
)
|
||||
assert hass.states.get(wemo_entity.entity_id).state == STATE_OFF
|
||||
assert hass.states.get(wemo_entity.entity_id).state == LightState.OFF
|
||||
|
@ -7,8 +7,12 @@ from homeassistant.components.homeassistant import (
|
||||
DOMAIN as HA_DOMAIN,
|
||||
SERVICE_UPDATE_ENTITY,
|
||||
)
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS, DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, 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_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@ -76,7 +80,7 @@ async def test_turn_on_brightness(
|
||||
|
||||
pywemo_device.set_brightness.assert_called_once_with(80)
|
||||
states = hass.states.get(wemo_entity.entity_id)
|
||||
assert states.state == STATE_ON
|
||||
assert states.state == LightState.ON
|
||||
assert states.attributes[ATTR_BRIGHTNESS] == 204
|
||||
|
||||
|
||||
@ -88,13 +92,13 @@ async def test_light_registry_state_callback(
|
||||
pywemo_device.get_state.return_value = 1
|
||||
pywemo_registry.callbacks[pywemo_device.name](pywemo_device, "", "")
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(wemo_entity.entity_id).state == STATE_ON
|
||||
assert hass.states.get(wemo_entity.entity_id).state == LightState.ON
|
||||
|
||||
# Off state.
|
||||
pywemo_device.get_state.return_value = 0
|
||||
pywemo_registry.callbacks[pywemo_device.name](pywemo_device, "", "")
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(wemo_entity.entity_id).state == STATE_OFF
|
||||
assert hass.states.get(wemo_entity.entity_id).state == LightState.OFF
|
||||
|
||||
|
||||
async def test_light_update_entity(
|
||||
@ -111,7 +115,7 @@ async def test_light_update_entity(
|
||||
{ATTR_ENTITY_ID: [wemo_entity.entity_id]},
|
||||
blocking=True,
|
||||
)
|
||||
assert hass.states.get(wemo_entity.entity_id).state == STATE_ON
|
||||
assert hass.states.get(wemo_entity.entity_id).state == LightState.ON
|
||||
|
||||
# Off state.
|
||||
pywemo_device.get_state.return_value = 0
|
||||
@ -121,4 +125,4 @@ async def test_light_update_entity(
|
||||
{ATTR_ENTITY_ID: [wemo_entity.entity_id]},
|
||||
blocking=True,
|
||||
)
|
||||
assert hass.states.get(wemo_entity.entity_id).state == STATE_OFF
|
||||
assert hass.states.get(wemo_entity.entity_id).state == LightState.OFF
|
||||
|
@ -9,14 +9,9 @@ from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_HS_COLOR,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
@ -146,7 +141,7 @@ async def test_loading_light(
|
||||
# First segment of the strip
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
entry = entity_registry.async_get("light.wl000000000099_1")
|
||||
assert entry
|
||||
@ -170,7 +165,7 @@ async def test_on_off_light_state(
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
# Turn off
|
||||
await hass.services.async_call(
|
||||
@ -183,7 +178,7 @@ async def test_on_off_light_state(
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
|
||||
async def test_dimmer_light_state(
|
||||
@ -202,7 +197,7 @@ async def test_dimmer_light_state(
|
||||
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get(ATTR_BRIGHTNESS) == 42
|
||||
|
||||
await hass.services.async_call(
|
||||
@ -215,7 +210,7 @@ async def test_dimmer_light_state(
|
||||
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
@ -227,7 +222,7 @@ async def test_dimmer_light_state(
|
||||
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get(ATTR_BRIGHTNESS) == 100
|
||||
|
||||
await hass.services.async_call(
|
||||
@ -240,7 +235,7 @@ async def test_dimmer_light_state(
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn on
|
||||
await hass.services.async_call(
|
||||
@ -253,7 +248,7 @@ async def test_dimmer_light_state(
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
|
||||
async def test_color_light_state(
|
||||
@ -276,7 +271,7 @@ async def test_color_light_state(
|
||||
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get(ATTR_BRIGHTNESS) == 42
|
||||
state_color = [
|
||||
round(state.attributes.get(ATTR_HS_COLOR)[0]),
|
||||
@ -294,7 +289,7 @@ async def test_color_light_state(
|
||||
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
@ -310,7 +305,7 @@ async def test_color_light_state(
|
||||
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get(ATTR_BRIGHTNESS) == 100
|
||||
state_color = [
|
||||
round(state.attributes.get(ATTR_HS_COLOR)[0]),
|
||||
@ -328,7 +323,7 @@ async def test_color_light_state(
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn on
|
||||
await hass.services.async_call(
|
||||
@ -341,7 +336,7 @@ async def test_color_light_state(
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
# Hue = 0, Saturation = 100
|
||||
await hass.services.async_call(
|
||||
@ -354,7 +349,7 @@ async def test_color_light_state(
|
||||
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
state_color = [
|
||||
round(state.attributes.get(ATTR_HS_COLOR)[0]),
|
||||
round(state.attributes.get(ATTR_HS_COLOR)[1]),
|
||||
@ -372,5 +367,5 @@ async def test_color_light_state(
|
||||
|
||||
state = hass.states.get("light.wl000000000099_1")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get(ATTR_BRIGHTNESS) == 60
|
||||
|
@ -9,14 +9,9 @@ from homeassistant.components.light import (
|
||||
ATTR_RGBW_COLOR,
|
||||
ATTR_RGBWW_COLOR,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
@ -39,7 +34,7 @@ async def test_light_unique_id(
|
||||
entity_id = "light.mock_title"
|
||||
assert entity_registry.async_get(entity_id).unique_id == FAKE_MAC
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
|
||||
async def test_light_operation(
|
||||
@ -50,7 +45,7 @@ async def test_light_operation(
|
||||
entity_id = "light.mock_title"
|
||||
assert entity_registry.async_get(entity_id).unique_id == FAKE_MAC
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id}, blocking=True
|
||||
@ -58,7 +53,7 @@ async def test_light_operation(
|
||||
bulb.turn_off.assert_called_once()
|
||||
|
||||
await async_push_update(hass, bulb, {"mac": FAKE_MAC, "state": False})
|
||||
assert hass.states.get(entity_id).state == STATE_OFF
|
||||
assert hass.states.get(entity_id).state == LightState.OFF
|
||||
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id}, blocking=True
|
||||
@ -66,7 +61,7 @@ async def test_light_operation(
|
||||
bulb.turn_on.assert_called_once()
|
||||
|
||||
await async_push_update(hass, bulb, {"mac": FAKE_MAC, "state": True})
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
assert hass.states.get(entity_id).state == LightState.ON
|
||||
|
||||
|
||||
async def test_rgbww_light(hass: HomeAssistant) -> None:
|
||||
@ -84,7 +79,7 @@ async def test_rgbww_light(hass: HomeAssistant) -> None:
|
||||
|
||||
await async_push_update(hass, bulb, {"mac": FAKE_MAC, **pilot.pilot_params})
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_RGBWW_COLOR] == (1, 2, 3, 4, 5)
|
||||
|
||||
bulb.turn_on.reset_mock()
|
||||
@ -98,7 +93,7 @@ async def test_rgbww_light(hass: HomeAssistant) -> None:
|
||||
assert pilot.pilot_params == {"dimming": 50, "temp": 6535, "state": True}
|
||||
await async_push_update(hass, bulb, {"mac": FAKE_MAC, **pilot.pilot_params})
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_COLOR_TEMP] == 153
|
||||
|
||||
bulb.turn_on.reset_mock()
|
||||
@ -112,7 +107,7 @@ async def test_rgbww_light(hass: HomeAssistant) -> None:
|
||||
assert pilot.pilot_params == {"sceneId": 1, "state": True}
|
||||
await async_push_update(hass, bulb, {"mac": FAKE_MAC, **pilot.pilot_params})
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_EFFECT] == "Ocean"
|
||||
|
||||
bulb.turn_on.reset_mock()
|
||||
@ -141,7 +136,7 @@ async def test_rgbw_light(hass: HomeAssistant) -> None:
|
||||
|
||||
await async_push_update(hass, bulb, {"mac": FAKE_MAC, **pilot.pilot_params})
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_RGBW_COLOR] == (1, 2, 3, 4)
|
||||
|
||||
bulb.turn_on.reset_mock()
|
||||
@ -170,7 +165,7 @@ async def test_turnable_light(hass: HomeAssistant) -> None:
|
||||
|
||||
await async_push_update(hass, bulb, {"mac": FAKE_MAC, **pilot.pilot_params})
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_COLOR_TEMP] == 153
|
||||
|
||||
|
||||
@ -191,7 +186,7 @@ async def test_old_firmware_dimmable_light(hass: HomeAssistant) -> None:
|
||||
|
||||
await async_push_update(hass, bulb, {"mac": FAKE_MAC, **pilot.pilot_params})
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 128
|
||||
|
||||
bulb.turn_on.reset_mock()
|
||||
|
@ -20,6 +20,7 @@ from homeassistant.components.light import (
|
||||
ATTR_TRANSITION,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
ColorMode,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.components.wled.const import (
|
||||
CONF_KEEP_MAIN_LIGHT,
|
||||
@ -31,8 +32,6 @@ from homeassistant.const import (
|
||||
ATTR_ICON,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -58,7 +57,7 @@ async def test_rgb_light_state(
|
||||
assert state.attributes.get(ATTR_EFFECT) == "Solid"
|
||||
assert state.attributes.get(ATTR_HS_COLOR) == (218.906, 50.196)
|
||||
assert state.attributes.get(ATTR_ICON) is None
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
assert (entry := entity_registry.async_get("light.wled_rgb_light"))
|
||||
assert entry.unique_id == "aabbccddeeff_0"
|
||||
@ -69,7 +68,7 @@ async def test_rgb_light_state(
|
||||
assert state.attributes.get(ATTR_EFFECT) == "Wipe"
|
||||
assert state.attributes.get(ATTR_HS_COLOR) == (40.0, 100.0)
|
||||
assert state.attributes.get(ATTR_ICON) is None
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
assert (entry := entity_registry.async_get("light.wled_rgb_light_segment_1"))
|
||||
assert entry.unique_id == "aabbccddeeff_1"
|
||||
@ -77,7 +76,7 @@ async def test_rgb_light_state(
|
||||
# Test main control of the lightstrip
|
||||
assert (state := hass.states.get("light.wled_rgb_light_main"))
|
||||
assert state.attributes.get(ATTR_BRIGHTNESS) == 128
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
assert (entry := entity_registry.async_get("light.wled_rgb_light_main"))
|
||||
assert entry.unique_id == "aabbccddeeff"
|
||||
@ -196,7 +195,7 @@ async def test_dynamically_handle_segments(
|
||||
) -> None:
|
||||
"""Test if a new/deleted segment is dynamically added/removed."""
|
||||
assert (segment0 := hass.states.get("light.wled_rgb_light"))
|
||||
assert segment0.state == STATE_ON
|
||||
assert segment0.state == LightState.ON
|
||||
assert not hass.states.get("light.wled_rgb_light_main")
|
||||
assert not hass.states.get("light.wled_rgb_light_segment_1")
|
||||
|
||||
@ -210,11 +209,11 @@ async def test_dynamically_handle_segments(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (main := hass.states.get("light.wled_rgb_light_main"))
|
||||
assert main.state == STATE_ON
|
||||
assert main.state == LightState.ON
|
||||
assert (segment0 := hass.states.get("light.wled_rgb_light"))
|
||||
assert segment0.state == STATE_ON
|
||||
assert segment0.state == LightState.ON
|
||||
assert (segment1 := hass.states.get("light.wled_rgb_light_segment_1"))
|
||||
assert segment1.state == STATE_ON
|
||||
assert segment1.state == LightState.ON
|
||||
|
||||
# Test adding if segment shows up again, including the main entity
|
||||
mock_wled.update.return_value = return_value
|
||||
@ -225,7 +224,7 @@ async def test_dynamically_handle_segments(
|
||||
assert (main := hass.states.get("light.wled_rgb_light_main"))
|
||||
assert main.state == STATE_UNAVAILABLE
|
||||
assert (segment0 := hass.states.get("light.wled_rgb_light"))
|
||||
assert segment0.state == STATE_ON
|
||||
assert segment0.state == LightState.ON
|
||||
assert (segment1 := hass.states.get("light.wled_rgb_light_segment_1"))
|
||||
assert segment1.state == STATE_UNAVAILABLE
|
||||
|
||||
@ -241,7 +240,7 @@ async def test_single_segment_behavior(
|
||||
|
||||
assert not hass.states.get("light.wled_rgb_light_main")
|
||||
assert (state := hass.states.get("light.wled_rgb_light"))
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
# Test segment brightness takes main into account
|
||||
device.state.brightness = 100
|
||||
@ -260,7 +259,7 @@ async def test_single_segment_behavior(
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.wled_rgb_light")
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Test main is turned off when turning off a single segment
|
||||
await hass.services.async_call(
|
||||
@ -309,7 +308,7 @@ async def test_light_error(
|
||||
)
|
||||
|
||||
assert (state := hass.states.get("light.wled_rgb_light"))
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert mock_wled.segment.call_count == 1
|
||||
mock_wled.segment.assert_called_with(on=False, segment_id=0, transition=None)
|
||||
|
||||
@ -339,7 +338,7 @@ async def test_light_connection_error(
|
||||
async def test_rgbw_light(hass: HomeAssistant, mock_wled: MagicMock) -> None:
|
||||
"""Test RGBW support for WLED."""
|
||||
assert (state := hass.states.get("light.wled_rgbw_light"))
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get(ATTR_SUPPORTED_COLOR_MODES) == [ColorMode.RGBW]
|
||||
assert state.attributes.get(ATTR_COLOR_MODE) == ColorMode.RGBW
|
||||
assert state.attributes.get(ATTR_RGBW_COLOR) == (255, 0, 0, 139)
|
||||
@ -376,14 +375,14 @@ async def test_single_segment_with_keep_main_light(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (state := hass.states.get("light.wled_rgb_light_main"))
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_fixture", ["cct"])
|
||||
async def test_cct_light(hass: HomeAssistant, mock_wled: MagicMock) -> None:
|
||||
"""Test CCT support for WLED."""
|
||||
assert (state := hass.states.get("light.wled_cct_light"))
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes.get(ATTR_SUPPORTED_COLOR_MODES) == [
|
||||
ColorMode.COLOR_TEMP,
|
||||
ColorMode.RGBW,
|
||||
|
@ -7,6 +7,7 @@ import pytest
|
||||
from yeelight import BulbException, BulbType
|
||||
from yeelight.aio import KEY_CONNECTED
|
||||
|
||||
from homeassistant.components.light import LightState
|
||||
from homeassistant.components.yeelight.const import (
|
||||
CONF_DETECTED_MODEL,
|
||||
CONF_NIGHTLIGHT_SWITCH,
|
||||
@ -21,7 +22,6 @@ from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_ID,
|
||||
CONF_NAME,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -579,7 +579,7 @@ async def test_connection_dropped_resyncs_properties(hass: HomeAssistant) -> Non
|
||||
hass, dt_util.utcnow() + timedelta(seconds=STATE_CHANGE_TIME)
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("light.test_name").state == STATE_ON
|
||||
assert hass.states.get("light.test_name").state == LightState.ON
|
||||
assert len(mocked_bulb.async_get_properties.mock_calls) == 2
|
||||
|
||||
|
||||
@ -659,7 +659,7 @@ async def test_async_setup_with_discovery_not_working(hass: HomeAssistant) -> No
|
||||
await hass.async_block_till_done()
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
assert hass.states.get("light.yeelight_color_0x15243f").state == STATE_ON
|
||||
assert hass.states.get("light.yeelight_color_0x15243f").state == LightState.ON
|
||||
|
||||
|
||||
async def test_async_setup_retries_with_wrong_device(
|
||||
|
@ -36,6 +36,7 @@ from homeassistant.components.light import (
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
LightEntityFeature,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.components.yeelight.const import (
|
||||
ATTR_COUNT,
|
||||
@ -87,14 +88,7 @@ from homeassistant.components.yeelight.light import (
|
||||
YEELIGHT_MONO_EFFECT_LIST,
|
||||
YEELIGHT_TEMP_ONLY_EFFECT_LIST,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, CONF_NAME, STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@ -161,8 +155,8 @@ async def test_services(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(ENTITY_LIGHT).state == STATE_ON
|
||||
assert hass.states.get(ENTITY_NIGHTLIGHT).state == STATE_OFF
|
||||
assert hass.states.get(ENTITY_LIGHT).state == LightState.ON
|
||||
assert hass.states.get(ENTITY_NIGHTLIGHT).state == LightState.OFF
|
||||
|
||||
async def _async_test_service(
|
||||
service,
|
||||
@ -493,7 +487,7 @@ async def test_services(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -
|
||||
{ATTR_ENTITY_ID: ENTITY_LIGHT},
|
||||
blocking=True,
|
||||
)
|
||||
assert hass.states.get(ENTITY_LIGHT).state == STATE_OFF
|
||||
assert hass.states.get(ENTITY_LIGHT).state == LightState.OFF
|
||||
|
||||
mocked_bulb.async_turn_on = AsyncMock()
|
||||
mocked_bulb.async_set_brightness = AsyncMock(side_effect=BulbException)
|
||||
@ -504,7 +498,7 @@ async def test_services(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -
|
||||
{ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_BRIGHTNESS: 50},
|
||||
blocking=True,
|
||||
)
|
||||
assert hass.states.get(ENTITY_LIGHT).state == STATE_OFF
|
||||
assert hass.states.get(ENTITY_LIGHT).state == LightState.OFF
|
||||
|
||||
mocked_bulb.async_set_brightness = AsyncMock(side_effect=TimeoutError)
|
||||
with pytest.raises(HomeAssistantError):
|
||||
@ -514,7 +508,7 @@ async def test_services(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -
|
||||
{ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_BRIGHTNESS: 55},
|
||||
blocking=True,
|
||||
)
|
||||
assert hass.states.get(ENTITY_LIGHT).state == STATE_OFF
|
||||
assert hass.states.get(ENTITY_LIGHT).state == LightState.OFF
|
||||
|
||||
mocked_bulb.async_set_brightness = AsyncMock(side_effect=socket.error)
|
||||
with pytest.raises(HomeAssistantError):
|
||||
@ -552,8 +546,8 @@ async def test_update_errors(
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(ENTITY_LIGHT).state == STATE_ON
|
||||
assert hass.states.get(ENTITY_NIGHTLIGHT).state == STATE_OFF
|
||||
assert hass.states.get(ENTITY_LIGHT).state == LightState.ON
|
||||
assert hass.states.get(ENTITY_NIGHTLIGHT).state == LightState.OFF
|
||||
|
||||
# Timeout usually means the bulb is overloaded with commands
|
||||
# but will still respond eventually.
|
||||
@ -565,7 +559,7 @@ async def test_update_errors(
|
||||
{ATTR_ENTITY_ID: ENTITY_LIGHT},
|
||||
blocking=True,
|
||||
)
|
||||
assert hass.states.get(ENTITY_LIGHT).state == STATE_ON
|
||||
assert hass.states.get(ENTITY_LIGHT).state == LightState.ON
|
||||
|
||||
# socket.error usually means the bulb dropped the connection
|
||||
# or lost wifi, then came back online and forced the existing
|
||||
|
@ -14,6 +14,7 @@ from homeassistant.components.light import (
|
||||
ATTR_XY_COLOR,
|
||||
SCAN_INTERVAL,
|
||||
ColorMode,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.components.zerproc.const import (
|
||||
DATA_ADDRESSES,
|
||||
@ -24,8 +25,6 @@ from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -98,7 +97,7 @@ async def test_init(hass: HomeAssistant, mock_entry) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.ledblue_ccddeeff")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes == {
|
||||
ATTR_FRIENDLY_NAME: "LEDBlue-CCDDEEFF",
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS],
|
||||
@ -111,7 +110,7 @@ async def test_init(hass: HomeAssistant, mock_entry) -> None:
|
||||
}
|
||||
|
||||
state = hass.states.get("light.ledblue_33445566")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes == {
|
||||
ATTR_FRIENDLY_NAME: "LEDBlue-33445566",
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS],
|
||||
@ -282,7 +281,7 @@ async def test_light_update(hass: HomeAssistant, mock_light) -> None:
|
||||
utcnow = dt_util.utcnow()
|
||||
|
||||
state = hass.states.get("light.ledblue_ccddeeff")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes == {
|
||||
ATTR_FRIENDLY_NAME: "LEDBlue-CCDDEEFF",
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS],
|
||||
@ -322,7 +321,7 @@ async def test_light_update(hass: HomeAssistant, mock_light) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.ledblue_ccddeeff")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes == {
|
||||
ATTR_FRIENDLY_NAME: "LEDBlue-CCDDEEFF",
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS],
|
||||
@ -344,7 +343,7 @@ async def test_light_update(hass: HomeAssistant, mock_light) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.ledblue_ccddeeff")
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes == {
|
||||
ATTR_FRIENDLY_NAME: "LEDBlue-CCDDEEFF",
|
||||
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS],
|
||||
|
@ -14,6 +14,7 @@ from homeassistant.components.light import (
|
||||
FLASH_LONG,
|
||||
FLASH_SHORT,
|
||||
ColorMode,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.components.zha.helpers import (
|
||||
ZHADeviceProxy,
|
||||
@ -21,7 +22,7 @@ from homeassistant.components.zha.helpers import (
|
||||
get_zha_gateway,
|
||||
get_zha_gateway_proxy,
|
||||
)
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import (
|
||||
@ -150,7 +151,7 @@ async def test_light(
|
||||
cluster_level = getattr(zigpy_device.endpoints[1], "level", None)
|
||||
cluster_identify = getattr(zigpy_device.endpoints[1], "identify", None)
|
||||
|
||||
assert hass.states.get(entity_id).state == STATE_OFF
|
||||
assert hass.states.get(entity_id).state == LightState.OFF
|
||||
|
||||
# test turning the lights on and off from the light
|
||||
await async_test_on_off_from_light(hass, cluster_on_off, entity_id)
|
||||
@ -176,7 +177,7 @@ async def test_light(
|
||||
# test getting a brightness change from the network
|
||||
await async_test_on_from_light(hass, cluster_on_off, entity_id)
|
||||
await async_test_dimmer_from_light(
|
||||
hass, cluster_level, entity_id, 150, STATE_ON
|
||||
hass, cluster_level, entity_id, 150, LightState.ON
|
||||
)
|
||||
|
||||
|
||||
@ -286,7 +287,7 @@ async def test_on_with_off_color(
|
||||
)
|
||||
|
||||
light1_state = hass.states.get(device_1_entity_id)
|
||||
assert light1_state.state == STATE_ON
|
||||
assert light1_state.state == LightState.ON
|
||||
assert light1_state.attributes["color_temp"] == 235
|
||||
assert light1_state.attributes["color_mode"] == ColorMode.COLOR_TEMP
|
||||
|
||||
@ -352,7 +353,7 @@ async def test_on_with_off_color(
|
||||
)
|
||||
|
||||
light1_state = hass.states.get(device_1_entity_id)
|
||||
assert light1_state.state == STATE_ON
|
||||
assert light1_state.state == LightState.ON
|
||||
assert light1_state.attributes["brightness"] == 254
|
||||
assert light1_state.attributes["color_temp"] == 240
|
||||
assert light1_state.attributes["color_mode"] == ColorMode.COLOR_TEMP
|
||||
@ -365,12 +366,12 @@ async def async_test_on_off_from_light(
|
||||
# turn on at light
|
||||
await send_attributes_report(hass, cluster, {1: 0, 0: 1, 2: 3})
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
assert hass.states.get(entity_id).state == LightState.ON
|
||||
|
||||
# turn off at light
|
||||
await send_attributes_report(hass, cluster, {1: 1, 0: 0, 2: 3})
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
assert hass.states.get(entity_id).state == STATE_OFF
|
||||
assert hass.states.get(entity_id).state == LightState.OFF
|
||||
|
||||
|
||||
async def async_test_on_from_light(
|
||||
@ -380,7 +381,7 @@ async def async_test_on_from_light(
|
||||
# turn on at light
|
||||
await send_attributes_report(hass, cluster, {1: -1, 0: 1, 2: 2})
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
assert hass.states.get(entity_id).state == LightState.ON
|
||||
|
||||
|
||||
async def async_test_on_off_from_hass(
|
||||
|
@ -17,14 +17,13 @@ from homeassistant.components.light import (
|
||||
ATTR_TRANSITION,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
LightEntityFeature,
|
||||
LightState,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -50,7 +49,7 @@ async def test_light(
|
||||
state = hass.states.get(BULB_6_MULTI_COLOR_LIGHT_ENTITY)
|
||||
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
assert state.attributes[ATTR_MIN_MIREDS] == 153
|
||||
assert state.attributes[ATTR_MAX_MIREDS] == 370
|
||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == LightEntityFeature.TRANSITION
|
||||
@ -80,7 +79,7 @@ async def test_light(
|
||||
state = hass.states.get(BULB_6_MULTI_COLOR_LIGHT_ENTITY)
|
||||
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
@ -127,7 +126,7 @@ async def test_light(
|
||||
node.receive_event(event)
|
||||
|
||||
state = hass.states.get(BULB_6_MULTI_COLOR_LIGHT_ENTITY)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_COLOR_MODE] == "color_temp"
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 255
|
||||
assert state.attributes[ATTR_COLOR_TEMP] == 370
|
||||
@ -252,7 +251,7 @@ async def test_light(
|
||||
node.receive_event(blue_event)
|
||||
|
||||
state = hass.states.get(BULB_6_MULTI_COLOR_LIGHT_ENTITY)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_COLOR_MODE] == "hs"
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 255
|
||||
assert state.attributes[ATTR_RGB_COLOR] == (255, 76, 255)
|
||||
@ -355,7 +354,7 @@ async def test_light(
|
||||
node.receive_event(cold_white_event)
|
||||
|
||||
state = hass.states.get(BULB_6_MULTI_COLOR_LIGHT_ENTITY)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_COLOR_MODE] == "color_temp"
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 255
|
||||
assert state.attributes[ATTR_COLOR_TEMP] == 170
|
||||
@ -445,7 +444,7 @@ async def test_v4_dimmer_light(
|
||||
state = hass.states.get(EATON_RF9640_ENTITY)
|
||||
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
# the light should pick currentvalue which has zwave value 22
|
||||
assert state.attributes[ATTR_BRIGHTNESS] == 57
|
||||
|
||||
@ -455,7 +454,7 @@ async def test_optional_light(
|
||||
) -> None:
|
||||
"""Test a device that has an additional light endpoint being identified as light."""
|
||||
state = hass.states.get(AEON_SMART_SWITCH_LIGHT_ENTITY)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
|
||||
async def test_rgbw_light(hass: HomeAssistant, client, zen_31, integration) -> None:
|
||||
@ -463,7 +462,7 @@ async def test_rgbw_light(hass: HomeAssistant, client, zen_31, integration) -> N
|
||||
state = hass.states.get(ZEN_31_ENTITY)
|
||||
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == LightEntityFeature.TRANSITION
|
||||
|
||||
# Test turning on
|
||||
@ -506,7 +505,7 @@ async def test_light_none_color_value(
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == LightEntityFeature.TRANSITION
|
||||
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["hs"]
|
||||
|
||||
@ -517,7 +516,7 @@ async def test_light_on_off_color(
|
||||
"""Test the light entity for RGB lights without dimming support."""
|
||||
node = logic_group_zdb5100
|
||||
state = hass.states.get(ZDB5100_ENTITY)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
async def update_color(red: int, green: int, blue: int) -> None:
|
||||
event = Event(
|
||||
@ -667,14 +666,14 @@ async def test_light_on_off_color(
|
||||
await update_switch_state(False)
|
||||
|
||||
state = hass.states.get(ZDB5100_ENTITY)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Force the light to turn on (green)
|
||||
await update_color(0, 255, 0)
|
||||
await update_switch_state(True)
|
||||
|
||||
state = hass.states.get(ZDB5100_ENTITY)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
@ -800,7 +799,7 @@ async def test_light_color_only(
|
||||
"""Test the light entity for RGB lights with Color Switch CC only."""
|
||||
node = express_controls_ezmultipli
|
||||
state = hass.states.get(HSM200_V1_ENTITY)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
async def update_color(red: int, green: int, blue: int) -> None:
|
||||
event = Event(
|
||||
@ -917,13 +916,13 @@ async def test_light_color_only(
|
||||
await update_color(0, 0, 0)
|
||||
|
||||
state = hass.states.get(HSM200_V1_ENTITY)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Force the light to turn on (50% green)
|
||||
await update_color(0, 128, 0)
|
||||
|
||||
state = hass.states.get(HSM200_V1_ENTITY)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
@ -971,7 +970,7 @@ async def test_light_color_only(
|
||||
await update_color(0, 128, 0)
|
||||
|
||||
state = hass.states.get(HSM200_V1_ENTITY)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
@ -999,7 +998,7 @@ async def test_light_color_only(
|
||||
await update_color(128, 0, 0)
|
||||
|
||||
state = hass.states.get(HSM200_V1_ENTITY)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
# Assert that the color is preserved when changing brightness
|
||||
await hass.services.async_call(
|
||||
@ -1174,7 +1173,7 @@ async def test_basic_cc_light(
|
||||
|
||||
state = hass.states.get(BASIC_LIGHT_ENTITY)
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn on light
|
||||
await hass.services.async_call(
|
||||
@ -1200,7 +1199,7 @@ async def test_basic_cc_light(
|
||||
state = hass.states.get(BASIC_LIGHT_ENTITY)
|
||||
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == LightState.ON
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
@ -1226,7 +1225,7 @@ async def test_basic_cc_light(
|
||||
|
||||
state = hass.states.get(BASIC_LIGHT_ENTITY)
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
# Turn on light with brightness
|
||||
await hass.services.async_call(
|
||||
@ -1252,7 +1251,7 @@ async def test_basic_cc_light(
|
||||
state = hass.states.get(BASIC_LIGHT_ENTITY)
|
||||
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == LightState.OFF
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
|
@ -5,8 +5,7 @@ Call init before using it in your tests to ensure clean test data.
|
||||
|
||||
from typing import Any, Literal
|
||||
|
||||
from homeassistant.components.light import ColorMode, LightEntity
|
||||
from homeassistant.const import STATE_OFF, STATE_ON
|
||||
from homeassistant.components.light import ColorMode, LightEntity, LightState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
@ -25,9 +24,9 @@ def init(empty=False):
|
||||
[]
|
||||
if empty
|
||||
else [
|
||||
MockLight("Ceiling", STATE_ON),
|
||||
MockLight("Ceiling", STATE_OFF),
|
||||
MockLight(None, STATE_OFF),
|
||||
MockLight("Ceiling", LightState.ON),
|
||||
MockLight("Ceiling", LightState.OFF),
|
||||
MockLight(None, LightState.OFF),
|
||||
]
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user