Compare commits

...
Sign in to create a new pull request.

9 commits

Author SHA1 Message Date
G Johansson
be3b18cebf Mod version 2024-09-30 20:28:38 +00:00
G Johansson
1dff94e29c Fix fritzbox tests 2024-09-30 20:28:38 +00:00
G Johansson
5b886d48cf Mod ToggleEntity and implement state in LightEntity 2024-09-30 20:28:38 +00:00
G Johansson
ddf7f08567 light returns enum 2024-09-30 20:28:37 +00:00
G Johansson
d62da432d0 Deprecate STATE_ON in light 2024-09-30 20:28:37 +00:00
G Johansson
0999f61079 Add more 2024-09-30 20:28:37 +00:00
G Johansson
c1c6e6d50e Add more tests 2024-09-30 20:28:37 +00:00
G Johansson
7f88813ba1 Add some tests 2024-09-30 20:28:37 +00:00
G Johansson
3f2292dae4 Change light state calc to use enum 2024-09-30 20:28:36 +00:00
69 changed files with 1229 additions and 1183 deletions

View file

@ -31,6 +31,7 @@ from homeassistant.components.light import (
ColorMode,
LightEntity,
LightEntityFeature,
LightState,
filter_supported_color_modes,
)
from homeassistant.config_entries import ConfigEntry
@ -42,7 +43,6 @@ from homeassistant.const import (
CONF_UNIQUE_ID,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_ON,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)
@ -207,7 +207,7 @@ class LightGroup(GroupEntity, LightEntity):
for entity_id in self._entity_ids
if (state := self.hass.states.get(entity_id)) is not None
]
on_states = [state for state in states if state.state == STATE_ON]
on_states = [state for state in states if state.state == LightState.ON]
valid_state = self.mode(
state.state not in (STATE_UNKNOWN, STATE_UNAVAILABLE) for state in states
@ -218,7 +218,9 @@ class LightGroup(GroupEntity, LightEntity):
self._attr_is_on = None
else:
# Set as ON if any / all member is ON
self._attr_is_on = self.mode(state.state == STATE_ON for state in states)
self._attr_is_on = self.mode(
state.state == LightState.ON for state in states
)
self._attr_available = any(state.state != STATE_UNAVAILABLE for state in states)
self._attr_brightness = reduce_attribute(on_states, ATTR_BRIGHTNESS)

View file

@ -22,16 +22,12 @@ from homeassistant.components.light import (
ATTR_WHITE,
DOMAIN as LIGHT_DOMAIN,
ColorMode,
LightState,
brightness_supported,
color_supported,
color_temp_supported,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_ON,
)
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.core import CALLBACK_TYPE, State, callback
from homeassistant.helpers.event import async_call_later
from homeassistant.util.color import (
@ -244,7 +240,7 @@ class Light(HomeAccessory):
state = new_state.state
attributes = new_state.attributes
color_mode = attributes.get(ATTR_COLOR_MODE)
self.char_on.set_value(int(state == STATE_ON))
self.char_on.set_value(int(state == LightState.ON))
color_mode_changed = self._previous_color_mode != color_mode
self._previous_color_mode = color_mode
@ -265,7 +261,7 @@ class Light(HomeAccessory):
# Therefore, if the brightness is 0 and the device is still on,
# the brightness is mapped to 1 otherwise the update is ignored in
# order to avoid this incorrect behavior.
if brightness == 0 and state == STATE_ON:
if brightness == 0 and state == LightState.ON:
brightness = 1
self.char_brightness.set_value(brightness)
if color_mode_changed:

View file

@ -7,7 +7,7 @@ import csv
import dataclasses
from datetime import timedelta
from enum import IntFlag, StrEnum
from functools import cached_property
from functools import cached_property, partial
import logging
import os
from typing import Any, Self, cast, final
@ -15,15 +15,16 @@ from typing import Any, Self, cast, final
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
SERVICE_TOGGLE,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_ON,
)
from homeassistant.const import SERVICE_TOGGLE, SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, entity_registry as er
from homeassistant.helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.typing import ConfigType, VolDictType
@ -41,6 +42,18 @@ SCAN_INTERVAL = timedelta(seconds=30)
DATA_PROFILES: HassKey[Profiles] = HassKey(f"{DOMAIN}_profiles")
class LightState(StrEnum):
"""Light entity states."""
ON = "on"
OFF = "off"
# The STATE_ON constant is deprecated as of Home Assistant 2024.11
# Please use the LightState enum instead.
_DEPRECATED_STATE_ON = DeprecatedConstantEnum(LightState.ON, "2025.11")
class LightEntityFeature(IntFlag):
"""Supported features of the light entity."""
@ -297,7 +310,7 @@ _LOGGER = logging.getLogger(__name__)
@bind_hass
def is_on(hass: HomeAssistant, entity_id: str) -> bool:
"""Return if the lights are on based on the statemachine."""
return hass.states.is_state(entity_id, STATE_ON)
return hass.states.is_state(entity_id, LightState.ON)
def preprocess_turn_on_alternatives(
@ -900,6 +913,14 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
__color_mode_reported = False
@property
@final
def state(self) -> str | None:
"""Return the light state."""
if (_is_on := self.is_on) is None:
return None
return LightState.ON if _is_on else LightState.OFF
@cached_property
def brightness(self) -> int | None:
"""Return the brightness of this light between 0..255."""
@ -1345,3 +1366,11 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
return True
# philips_js has known issues, we don't need users to open issues
return self.platform.platform_name not in {"philips_js"}
# These can be removed if no deprecated constant are in this module anymore
__getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
__dir__ = partial(
dir_with_deprecated_constants, module_globals_keys=[*globals().keys()]
)
__all__ = all_with_deprecated_constants(globals())

View file

@ -7,13 +7,7 @@ from collections.abc import Iterable, Mapping
import logging
from typing import Any, NamedTuple, cast
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 Context, HomeAssistant, State
from . import (
@ -30,11 +24,12 @@ from . import (
ATTR_XY_COLOR,
DOMAIN,
ColorMode,
LightState,
)
_LOGGER = logging.getLogger(__name__)
VALID_STATES = {STATE_ON, STATE_OFF}
VALID_STATES = {LightState.ON, LightState.OFF}
ATTR_GROUP = [ATTR_BRIGHTNESS, ATTR_EFFECT]
@ -111,7 +106,7 @@ async def _async_reproduce_state(
if reproduce_options is not None and ATTR_TRANSITION in reproduce_options:
service_data[ATTR_TRANSITION] = reproduce_options[ATTR_TRANSITION]
if state.state == STATE_ON:
if state.state == LightState.ON:
service = SERVICE_TURN_ON
for attr in ATTR_GROUP:
# All attributes that are not colors
@ -140,7 +135,7 @@ async def _async_reproduce_state(
service_data[color_attr] = color_attr_state
break
elif state.state == STATE_OFF:
elif state.state == LightState.OFF:
service = SERVICE_TURN_OFF
await hass.services.async_call(

View file

@ -31,8 +31,9 @@ from homeassistant.components.light import (
ColorMode,
LightEntity,
LightEntityFeature,
LightState,
)
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, CONF_TYPE, STATE_ON
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, CONF_TYPE
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -259,7 +260,7 @@ class LimitlessLEDGroup(LightEntity, RestoreEntity):
"""Handle entity about to be added to hass event."""
await super().async_added_to_hass()
if last_state := await self.async_get_last_state():
self._attr_is_on = last_state.state == STATE_ON
self._attr_is_on = last_state.state == LightState.ON
self._attr_brightness = last_state.attributes.get("brightness")
self._attr_color_temp = last_state.attributes.get("color_temp")
self._attr_hs_color = last_state.attributes.get("hs_color")

View file

@ -27,6 +27,7 @@ from homeassistant.components.light import (
ColorMode,
LightEntity,
LightEntityFeature,
LightState,
valid_supported_color_modes,
)
from homeassistant.const import (
@ -34,7 +35,6 @@ from homeassistant.const import (
CONF_OPTIMISTIC,
CONF_PAYLOAD_OFF,
CONF_PAYLOAD_ON,
STATE_ON,
)
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
@ -618,7 +618,7 @@ class MqttLight(MqttEntity, LightEntity, RestoreEntity):
setattr(self, f"_attr_{attribute}", last_state.attributes[attribute])
if self._topic[CONF_STATE_TOPIC] is None and self._optimistic and last_state:
self._attr_is_on = last_state.state == STATE_ON
self._attr_is_on = last_state.state == LightState.ON
restore_state(ATTR_BRIGHTNESS)
restore_state(ATTR_RGB_COLOR)
restore_state(ATTR_HS_COLOR, ATTR_RGB_COLOR)

View file

@ -30,6 +30,7 @@ from homeassistant.components.light import (
ColorMode,
LightEntity,
LightEntityFeature,
LightState,
brightness_supported,
color_supported,
filter_supported_color_modes,
@ -44,7 +45,6 @@ from homeassistant.const import (
CONF_OPTIMISTIC,
CONF_RGB,
CONF_XY,
STATE_ON,
)
from homeassistant.core import async_get_hass, callback
import homeassistant.helpers.config_validation as cv
@ -514,7 +514,7 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
last_state = await self.async_get_last_state()
if self._optimistic and last_state:
self._attr_is_on = last_state.state == STATE_ON
self._attr_is_on = last_state.state == LightState.ON
last_attributes = last_state.attributes
self._attr_brightness = last_attributes.get(
ATTR_BRIGHTNESS, self.brightness

View file

@ -19,15 +19,10 @@ from homeassistant.components.light import (
ColorMode,
LightEntity,
LightEntityFeature,
LightState,
filter_supported_color_modes,
)
from homeassistant.const import (
CONF_NAME,
CONF_OPTIMISTIC,
CONF_STATE_TEMPLATE,
STATE_OFF,
STATE_ON,
)
from homeassistant.const import CONF_NAME, CONF_OPTIMISTIC, CONF_STATE_TEMPLATE
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity
@ -184,9 +179,9 @@ class MqttLightTemplate(MqttEntity, LightEntity, RestoreEntity):
def _state_received(self, msg: ReceiveMessage) -> None:
"""Handle new MQTT messages."""
state = self._value_templates[CONF_STATE_TEMPLATE](msg.payload)
if state == STATE_ON:
if state == LightState.ON:
self._attr_is_on = True
elif state == STATE_OFF:
elif state == LightState.OFF:
self._attr_is_on = False
elif state == PAYLOAD_NONE:
self._attr_is_on = None
@ -269,7 +264,7 @@ class MqttLightTemplate(MqttEntity, LightEntity, RestoreEntity):
last_state = await self.async_get_last_state()
if self._optimistic and last_state:
self._attr_is_on = last_state.state == STATE_ON
self._attr_is_on = last_state.state == LightState.ON
if last_state.attributes.get(ATTR_BRIGHTNESS):
self._attr_brightness = last_state.attributes.get(ATTR_BRIGHTNESS)
if last_state.attributes.get(ATTR_HS_COLOR):

View file

@ -10,9 +10,10 @@ from homeassistant.components.light import (
ATTR_RGBW_COLOR,
ColorMode,
LightEntity,
LightState,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_OFF, STATE_ON, Platform
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -83,7 +84,7 @@ class MySensorsLight(MySensorsChildEntity, LightEntity):
if self.assumed_state:
# optimistically assume that light has changed state
self._state = True
self._values[set_req.V_LIGHT] = STATE_ON
self._values[set_req.V_LIGHT] = LightState.ON
def _turn_on_dimmer(self, **kwargs: Any) -> None:
"""Turn on dimmer child device."""
@ -113,14 +114,14 @@ class MySensorsLight(MySensorsChildEntity, LightEntity):
if self.assumed_state:
# optimistically assume that light has changed state
self._state = False
self._values[value_type] = STATE_OFF
self._values[value_type] = LightState.OFF
self.async_write_ha_state()
@callback
def _async_update_light(self) -> None:
"""Update the controller with values from light child."""
value_type = self.gateway.const.SetReq.V_LIGHT
self._state = self._values[value_type] == STATE_ON
self._state = self._values[value_type] == LightState.ON
@callback
def _async_update_dimmer(self) -> None:

View file

@ -2,14 +2,8 @@
import voluptuous as vol
from homeassistant.const import (
CONF_ID,
CONF_NAME,
CONF_PROTOCOL,
CONF_STATE,
STATE_OFF,
STATE_ON,
)
from homeassistant.components.light import LightState
from homeassistant.const import CONF_ID, CONF_NAME, CONF_PROTOCOL, CONF_STATE
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity
@ -35,7 +29,7 @@ COMMAND_SCHEMA = vol.Schema(
vol.Optional(CONF_UNIT): cv.positive_int,
vol.Optional(CONF_UNITCODE): cv.positive_int,
vol.Optional(CONF_ID): vol.Any(cv.positive_int, cv.string),
vol.Optional(CONF_STATE): vol.Any(STATE_ON, STATE_OFF),
vol.Optional(CONF_STATE): vol.Coerce(LightState),
vol.Optional(CONF_SYSTEMCODE): cv.positive_int,
},
extra=vol.ALLOW_EXTRA,
@ -90,7 +84,7 @@ class PilightBaseDevice(RestoreEntity):
"""Call when entity about to be added to hass."""
await super().async_added_to_hass()
if state := await self.async_get_last_state():
self._is_on = state.state == STATE_ON
self._is_on = state.state == LightState.ON
self._brightness = state.attributes.get("brightness")
@property

View file

@ -7,9 +7,13 @@ from typing import Any
import RFXtrx as rfxtrxmod
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ColorMode,
LightEntity,
LightState,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_ON
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -70,7 +74,7 @@ class RfxtrxLight(RfxtrxCommandEntity, LightEntity):
if self._event is None:
old_state = await self.async_get_last_state()
if old_state is not None:
self._attr_is_on = old_state.state == STATE_ON
self._attr_is_on = old_state.state == LightState.ON
if brightness := old_state.attributes.get(ATTR_BRIGHTNESS):
self._attr_brightness = int(brightness)

View file

@ -10,6 +10,7 @@ from homeassistant.components.light import (
PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA,
ColorMode,
LightEntity,
LightState,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -17,7 +18,6 @@ from homeassistant.const import (
CONF_NAME,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import Event, EventStateChangedData, HomeAssistant, callback
@ -108,7 +108,7 @@ class LightSwitch(LightEntity):
self._attr_available = False
return
self._attr_available = True
self._attr_is_on = state.state == STATE_ON
self._attr_is_on = state.state == LightState.ON
self.async_write_ha_state()
self.async_on_remove(

View file

@ -21,6 +21,7 @@ from homeassistant.components.light import (
ColorMode,
LightEntity,
LightEntityFeature,
LightState,
filter_supported_color_modes,
)
from homeassistant.const import (
@ -29,8 +30,6 @@ from homeassistant.const import (
CONF_LIGHTS,
CONF_UNIQUE_ID,
CONF_VALUE_TEMPLATE,
STATE_OFF,
STATE_ON,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import TemplateError
@ -48,7 +47,7 @@ from .template_entity import (
)
_LOGGER = logging.getLogger(__name__)
_VALID_STATES = [STATE_ON, STATE_OFF, "true", "false"]
_VALID_STATES = [LightState.ON, LightState.OFF, "true", "false"]
# Legacy
CONF_COLOR_ACTION = "set_color"
@ -737,7 +736,7 @@ class LightTemplate(TemplateEntity, LightEntity):
state = str(result).lower()
if state in _VALID_STATES:
self._state = state in ("true", STATE_ON)
self._state = state in ("true", LightState.ON)
return
_LOGGER.error(

View file

@ -23,9 +23,10 @@ from homeassistant.components.light import (
ColorMode,
LightEntity,
LightEntityFeature,
LightState,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_ON, Platform
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, State, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -194,7 +195,7 @@ class Light(LightEntity, ZHAEntity):
def restore_external_state_attributes(self, state: State) -> None:
"""Restore entity state."""
self.entity_data.entity.restore_external_state_attributes(
state=(state.state == STATE_ON),
state=(state.state == LightState.ON),
off_with_transition=state.attributes.get(OFF_WITH_TRANSITION),
off_brightness=state.attributes.get(OFF_BRIGHTNESS),
brightness=state.attributes.get(ATTR_BRIGHTNESS),

View file

@ -17,7 +17,7 @@ import sys
import threading
import time
from types import FunctionType
from typing import TYPE_CHECKING, Any, Final, Literal, NotRequired, TypedDict, final
from typing import TYPE_CHECKING, Any, Final, NotRequired, TypedDict, final
import voluptuous as vol
@ -1664,8 +1664,7 @@ class ToggleEntity(
_attr_state: None = None
@property
@final
def state(self) -> Literal["on", "off"] | None:
def state(self) -> str | None:
"""Return the state."""
if (is_on := self.is_on) is None:
return None

View file

@ -11,6 +11,7 @@ from homeassistant.components.light import (
ATTR_SUPPORTED_COLOR_MODES,
DOMAIN as LIGHT_DOMAIN,
ColorMode,
LightState,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -18,7 +19,6 @@ from homeassistant.const import (
ATTR_SUPPORTED_FEATURES,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_ON,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
@ -43,7 +43,7 @@ async def test_attributes(hass: HomeAssistant) -> None:
await setup_platform(hass, LIGHT_DOMAIN)
state = hass.states.get(DEVICE_ID)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes.get(ATTR_BRIGHTNESS) == 204
assert state.attributes.get(ATTR_RGB_COLOR) == (0, 63, 255)
assert state.attributes.get(ATTR_COLOR_TEMP) is None

View file

@ -7,8 +7,9 @@ from homeassistant.components.light import (
DOMAIN as LIGHT_DOMAIN,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
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.helpers import entity_registry as er
@ -30,7 +31,7 @@ async def test_light(
light_id = "100"
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_OFF
assert state.state == LightState.OFF
entry = entity_registry.async_get(entity_id)
assert entry
@ -96,7 +97,7 @@ async def test_things_light(
light_id = "204"
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_ON
assert state.state == LightState.ON
entry = entity_registry.async_get(entity_id)
assert entry

View file

@ -9,7 +9,8 @@ from pybalboa.enums import OffOnState, UnknownState
import pytest
from syrupy import SnapshotAssertion
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNKNOWN, Platform
from homeassistant.components.light import LightState
from homeassistant.const import STATE_UNKNOWN, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
@ -59,17 +60,17 @@ async def test_light(hass: HomeAssistant, client: MagicMock, mock_light) -> None
# check if the initial state is off
state = hass.states.get(ENTITY_LIGHT)
assert state.state == STATE_OFF
assert state.state == LightState.OFF
# test calling turn on
await common.async_turn_on(hass, ENTITY_LIGHT)
state = await client_update(hass, client, ENTITY_LIGHT)
assert state.state == STATE_ON
assert state.state == LightState.ON
# test calling turn off
await common.async_turn_off(hass, ENTITY_LIGHT)
state = await client_update(hass, client, ENTITY_LIGHT)
assert state.state == STATE_OFF
assert state.state == LightState.OFF
async def test_light_unknown_state(

View file

@ -12,14 +12,9 @@ from homeassistant.components.light import (
ATTR_RGBW_COLOR,
ATTR_SUPPORTED_COLOR_MODES,
ColorMode,
LightState,
)
from homeassistant.const import (
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
)
from homeassistant.const import SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
@ -67,7 +62,7 @@ async def test_dimmer_init(
assert color_modes == [ColorMode.BRIGHTNESS]
assert state.attributes[ATTR_BRIGHTNESS] == 65
assert state.state == STATE_ON
assert state.state == LightState.ON
device = device_registry.async_get(entry.device_id)
@ -91,7 +86,7 @@ async def test_dimmer_update(dimmer, hass: HomeAssistant) -> None:
state = hass.states.get(entity_id)
assert state.attributes[ATTR_BRIGHTNESS] == 53
assert state.state == STATE_ON
assert state.state == LightState.ON
async def test_dimmer_on(dimmer, hass: HomeAssistant) -> None:
@ -109,7 +104,7 @@ async def test_dimmer_on(dimmer, hass: HomeAssistant) -> None:
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
assert state.state == LightState.OFF
def turn_on(brightness):
assert brightness == 254
@ -125,7 +120,7 @@ async def test_dimmer_on(dimmer, hass: HomeAssistant) -> None:
)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 254
@ -144,7 +139,7 @@ async def test_dimmer_on_with_brightness(dimmer, hass: HomeAssistant) -> None:
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
assert state.state == LightState.OFF
def turn_on(brightness):
assert brightness == 202
@ -167,7 +162,7 @@ async def test_dimmer_on_with_brightness(dimmer, hass: HomeAssistant) -> None:
state = hass.states.get(entity_id)
assert state.attributes[ATTR_BRIGHTNESS] == 202
assert state.state == STATE_ON
assert state.state == LightState.ON
async def test_dimmer_off(dimmer, hass: HomeAssistant) -> None:
@ -183,7 +178,7 @@ async def test_dimmer_off(dimmer, hass: HomeAssistant) -> None:
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
def turn_off():
feature_mock.is_on = False
@ -198,7 +193,7 @@ async def test_dimmer_off(dimmer, hass: HomeAssistant) -> None:
)
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
assert state.state == LightState.OFF
assert state.attributes[ATTR_BRIGHTNESS] is None
@ -266,7 +261,7 @@ async def test_wlightbox_s_update(wlightbox_s, hass: HomeAssistant) -> None:
await async_setup_entity(hass, entity_id)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 0xAB
@ -284,7 +279,7 @@ async def test_wlightbox_s_on(wlightbox_s, hass: HomeAssistant) -> None:
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
assert state.state == LightState.OFF
def turn_on(brightness):
assert brightness == 254
@ -301,7 +296,7 @@ async def test_wlightbox_s_on(wlightbox_s, hass: HomeAssistant) -> None:
state = hass.states.get(entity_id)
assert state.attributes[ATTR_BRIGHTNESS] == 254
assert state.state == STATE_ON
assert state.state == LightState.ON
@pytest.fixture(name="wlightbox")
@ -372,7 +367,7 @@ async def test_wlightbox_update(wlightbox, hass: HomeAssistant) -> None:
state = hass.states.get(entity_id)
assert state.attributes[ATTR_RGBW_COLOR] == (0xFA, 0x00, 0x20, 0x3A)
assert state.state == STATE_ON
assert state.state == LightState.ON
async def test_wlightbox_on_rgbw(wlightbox, hass: HomeAssistant) -> None:
@ -388,7 +383,7 @@ async def test_wlightbox_on_rgbw(wlightbox, hass: HomeAssistant) -> None:
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
assert state.state == LightState.OFF
def turn_on(value):
feature_mock.is_on = True
@ -421,7 +416,7 @@ async def test_wlightbox_on_rgbw(wlightbox, hass: HomeAssistant) -> None:
)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_RGBW_COLOR] == (0xC1, 0xD2, 0xF3, 0xC7)
@ -438,7 +433,7 @@ async def test_wlightbox_on_to_last_color(wlightbox, hass: HomeAssistant) -> Non
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
assert state.state == LightState.OFF
def turn_on(value):
feature_mock.is_on = True
@ -458,7 +453,7 @@ async def test_wlightbox_on_to_last_color(wlightbox, hass: HomeAssistant) -> Non
state = hass.states.get(entity_id)
assert state.attributes[ATTR_RGBW_COLOR] == (0xF1, 0xE2, 0xD3, 0xE4)
assert state.state == STATE_ON
assert state.state == LightState.ON
async def test_wlightbox_off(wlightbox, hass: HomeAssistant) -> None:
@ -474,7 +469,7 @@ async def test_wlightbox_off(wlightbox, hass: HomeAssistant) -> None:
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
def turn_off():
feature_mock.is_on = False
@ -492,7 +487,7 @@ async def test_wlightbox_off(wlightbox, hass: HomeAssistant) -> None:
state = hass.states.get(entity_id)
assert state.attributes[ATTR_RGBW_COLOR] is None
assert state.state == STATE_OFF
assert state.state == LightState.OFF
@pytest.mark.parametrize("feature", ALL_LIGHT_FIXTURES, indirect=["feature"])
@ -549,7 +544,7 @@ async def test_wlightbox_on_effect(wlightbox, hass: HomeAssistant) -> None:
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
assert state.state == LightState.OFF
def turn_on(value):
feature_mock.is_on = True

View file

@ -26,14 +26,9 @@ from homeassistant.components.light import (
SERVICE_TURN_ON,
ColorMode,
LightEntityFeature,
LightState,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_SUPPORTED_FEATURES,
STATE_OFF,
STATE_ON,
Platform,
)
from homeassistant.const import ATTR_ENTITY_ID, ATTR_SUPPORTED_FEATURES, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
@ -333,10 +328,10 @@ async def test_light_state_change(
light_ws_data: WebsocketDataType,
) -> None:
"""Verify light can change state on websocket event."""
assert hass.states.get("light.hue_go").state == STATE_ON
assert hass.states.get("light.hue_go").state == LightState.ON
await light_ws_data({"state": {"on": False}})
assert hass.states.get("light.hue_go").state == STATE_OFF
assert hass.states.get("light.hue_go").state == LightState.OFF
@pytest.mark.parametrize(
@ -1158,7 +1153,7 @@ async def test_verify_group_supported_features(hass: HomeAssistant) -> None:
assert len(hass.states.async_all()) == 4
group_state = hass.states.get("light.group")
assert group_state.state == STATE_ON
assert group_state.state == LightState.ON
assert group_state.attributes[ATTR_COLOR_MODE] == ColorMode.COLOR_TEMP
assert (
group_state.attributes[ATTR_SUPPORTED_FEATURES]
@ -1275,7 +1270,7 @@ async def test_verify_group_color_mode_fallback(
) -> None:
"""Test that group supported features reflect what included lights support."""
group_state = hass.states.get("light.opbergruimte")
assert group_state.state == STATE_OFF
assert group_state.state == LightState.OFF
assert group_state.attributes[ATTR_COLOR_MODE] is None
await mock_websocket_data(
@ -1300,5 +1295,5 @@ async def test_verify_group_color_mode_fallback(
}
)
group_state = hass.states.get("light.opbergruimte")
assert group_state.state == STATE_ON
assert group_state.state == LightState.ON
assert group_state.attributes[ATTR_COLOR_MODE] is ColorMode.BRIGHTNESS

View file

@ -19,8 +19,9 @@ from homeassistant.components.light import (
DOMAIN as LIGHT_DOMAIN,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
LightState,
)
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.setup import async_setup_component
@ -56,7 +57,7 @@ async def test_state_attributes(hass: HomeAssistant) -> None:
)
state = hass.states.get(ENTITY_LIGHT)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes.get(ATTR_XY_COLOR) == (0.4, 0.4)
assert state.attributes.get(ATTR_BRIGHTNESS) == 25
assert state.attributes.get(ATTR_RGB_COLOR) == (255, 234, 164)
@ -108,14 +109,14 @@ async def test_turn_off(hass: HomeAssistant) -> None:
)
state = hass.states.get(ENTITY_LIGHT)
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: ENTITY_LIGHT}, blocking=True
)
state = hass.states.get(ENTITY_LIGHT)
assert state.state == STATE_OFF
assert state.state == LightState.OFF
async def test_turn_off_without_entity_id(hass: HomeAssistant) -> None:
@ -125,11 +126,11 @@ async def test_turn_off_without_entity_id(hass: HomeAssistant) -> None:
)
state = hass.states.get(ENTITY_LIGHT)
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "all"}, blocking=True
)
state = hass.states.get(ENTITY_LIGHT)
assert state.state == STATE_OFF
assert state.state == LightState.OFF

View file

@ -4,13 +4,15 @@ from unittest.mock import patch
from syrupy.assertion import SnapshotAssertion
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.const import (
ATTR_ENTITY_ID,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant
@ -41,11 +43,11 @@ async def test_light_without_binary_sensor(
test_gateway.publisher.dispatch("Test", ("devolo.Dimmer:Test", 0.0))
await hass.async_block_till_done()
state = hass.states.get(f"{LIGHT_DOMAIN}.test")
assert state.state == STATE_OFF
assert state.state == LightState.OFF
test_gateway.publisher.dispatch("Test", ("devolo.Dimmer:Test", 100.0))
await hass.async_block_till_done()
state = hass.states.get(f"{LIGHT_DOMAIN}.test")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 255
# Test setting brightness
@ -109,11 +111,11 @@ async def test_light_with_binary_sensor(
test_gateway.publisher.dispatch("Test", ("devolo.Dimmer:Test", 0.0))
await hass.async_block_till_done()
state = hass.states.get(f"{LIGHT_DOMAIN}.test")
assert state.state == STATE_OFF
assert state.state == LightState.OFF
test_gateway.publisher.dispatch("Test", ("devolo.Dimmer:Test", 100.0))
await hass.async_block_till_done()
state = hass.states.get(f"{LIGHT_DOMAIN}.test")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 255
# Test setting brightness

View file

@ -10,12 +10,11 @@ from homeassistant.components.light import (
ATTR_COLOR_MODE,
ATTR_SUPPORTED_COLOR_MODES,
ColorMode,
LightState,
)
from homeassistant.const import (
ATTR_FRIENDLY_NAME,
ATTR_SUPPORTED_FEATURES,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant, State
@ -57,7 +56,7 @@ async def test_light_setup(hass: HomeAssistant, mock_device) -> None:
assert entity_state.attributes[ATTR_FRIENDLY_NAME] == mock_device.name
assert entity_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
assert entity_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
assert entity_state.state == STATE_OFF
assert entity_state.state == LightState.OFF
await run_service_tests(
hass,
mock_device,
@ -93,12 +92,12 @@ async def test_light_restore_state(hass: HomeAssistant, mock_device) -> None:
"""Test restore from cache."""
mock_restore_cache(
hass,
[State("light.name", STATE_ON, attributes={ATTR_BRIGHTNESS: 77})],
[State("light.name", LightState.ON, attributes={ATTR_BRIGHTNESS: 77})],
)
await create_entity_from_device(hass, mock_device)
mock_device.init_level.assert_called_once_with(77)
entity_state = hass.states.get("light.name")
assert entity_state.state == STATE_ON
assert entity_state.state == LightState.ON
assert entity_state.attributes[ATTR_BRIGHTNESS] == 77
assert entity_state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS
@ -112,4 +111,4 @@ async def test_light_restore_state_bad_cache(hass: HomeAssistant, mock_device) -
await create_entity_from_device(hass, mock_device)
mock_device.init_level.assert_not_called()
entity_state = hass.states.get("light.name")
assert entity_state.state == STATE_OFF
assert entity_state.state == LightState.OFF

View file

@ -12,12 +12,12 @@ from homeassistant.components.light import (
ATTR_COLOR_TEMP,
ATTR_HS_COLOR,
DOMAIN as LIGHT_DOMAIN,
LightState,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant
@ -66,7 +66,7 @@ async def test_light_change_state_temperature(
) -> None:
"""Test the change of state of a Elgato Key Light device."""
assert (state := hass.states.get("light.frenck"))
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,

View file

@ -7,7 +7,7 @@ from aioesphomeapi import (
APIVersion,
LightColorCapability,
LightInfo,
LightState,
LightState as ESPHomeLightState,
)
import pytest
@ -34,8 +34,8 @@ from homeassistant.components.light import (
FLASH_SHORT,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_ON,
ColorMode,
LightState,
)
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant
@ -57,7 +57,7 @@ async def test_light_on_off(
supported_color_modes=[LightColorCapability.ON_OFF],
)
]
states = [LightState(key=1, state=True)]
states = [ESPHomeLightState(key=1, state=True)]
user_service = []
await mock_generic_device_entry(
mock_client=mock_client,
@ -67,7 +67,7 @@ async def test_light_on_off(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -97,7 +97,7 @@ async def test_light_brightness(
supported_color_modes=[LightColorCapability.BRIGHTNESS],
)
]
states = [LightState(key=1, state=True, brightness=100)]
states = [ESPHomeLightState(key=1, state=True, brightness=100)]
user_service = []
await mock_generic_device_entry(
mock_client=mock_client,
@ -107,7 +107,7 @@ async def test_light_brightness(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -215,7 +215,7 @@ async def test_light_brightness_on_off(
],
)
]
states = [LightState(key=1, state=True, brightness=100)]
states = [ESPHomeLightState(key=1, state=True, brightness=100)]
user_service = []
await mock_generic_device_entry(
mock_client=mock_client,
@ -225,7 +225,7 @@ async def test_light_brightness_on_off(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -285,7 +285,7 @@ async def test_light_legacy_white_converted_to_brightness(
],
)
]
states = [LightState(key=1, state=True, brightness=100)]
states = [ESPHomeLightState(key=1, state=True, brightness=100)]
user_service = []
await mock_generic_device_entry(
mock_client=mock_client,
@ -295,7 +295,7 @@ async def test_light_legacy_white_converted_to_brightness(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -343,7 +343,7 @@ async def test_light_legacy_white_with_rgb(
supported_color_modes=[color_mode, color_mode_2],
)
]
states = [LightState(key=1, state=True, brightness=100)]
states = [ESPHomeLightState(key=1, state=True, brightness=100)]
user_service = []
await mock_generic_device_entry(
mock_client=mock_client,
@ -353,7 +353,7 @@ async def test_light_legacy_white_with_rgb(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [
ColorMode.RGB,
ColorMode.WHITE,
@ -397,7 +397,7 @@ async def test_light_brightness_on_off_with_unknown_color_mode(
],
)
]
states = [LightState(key=1, state=True, brightness=100)]
states = [ESPHomeLightState(key=1, state=True, brightness=100)]
user_service = []
await mock_generic_device_entry(
mock_client=mock_client,
@ -407,7 +407,7 @@ async def test_light_brightness_on_off_with_unknown_color_mode(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -468,7 +468,7 @@ async def test_light_on_and_brightness(
],
)
]
states = [LightState(key=1, state=True, brightness=100)]
states = [ESPHomeLightState(key=1, state=True, brightness=100)]
user_service = []
await mock_generic_device_entry(
mock_client=mock_client,
@ -478,7 +478,7 @@ async def test_light_on_and_brightness(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -518,7 +518,7 @@ async def test_rgb_color_temp_light(
supported_color_modes=color_modes,
)
]
states = [LightState(key=1, state=True, brightness=100)]
states = [ESPHomeLightState(key=1, state=True, brightness=100)]
user_service = []
await mock_generic_device_entry(
mock_client=mock_client,
@ -528,7 +528,7 @@ async def test_rgb_color_temp_light(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -606,7 +606,9 @@ async def test_light_rgb(
],
)
]
states = [LightState(key=1, state=True, brightness=100, red=1, green=1, blue=1)]
states = [
ESPHomeLightState(key=1, state=True, brightness=100, red=1, green=1, blue=1)
]
user_service = []
await mock_generic_device_entry(
mock_client=mock_client,
@ -616,7 +618,7 @@ async def test_light_rgb(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -725,7 +727,7 @@ async def test_light_rgbw(
)
]
states = [
LightState(
ESPHomeLightState(
key=1,
state=True,
brightness=100,
@ -748,7 +750,7 @@ async def test_light_rgbw(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.RGBW]
assert state.attributes[ATTR_COLOR_MODE] == ColorMode.RGBW
@ -892,7 +894,7 @@ async def test_light_rgbww_with_cold_warm_white_support(
)
]
states = [
LightState(
ESPHomeLightState(
key=1,
state=True,
color_brightness=1,
@ -919,7 +921,7 @@ async def test_light_rgbww_with_cold_warm_white_support(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.RGBWW]
assert state.attributes[ATTR_COLOR_MODE] == ColorMode.RGBWW
assert state.attributes[ATTR_RGBWW_COLOR] == (255, 255, 255, 255, 255)
@ -1131,7 +1133,7 @@ async def test_light_rgbww_without_cold_warm_white_support(
)
]
states = [
LightState(
ESPHomeLightState(
key=1,
state=True,
color_brightness=1,
@ -1156,7 +1158,7 @@ async def test_light_rgbww_without_cold_warm_white_support(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.RGBWW]
assert state.attributes[ATTR_COLOR_MODE] == ColorMode.RGBWW
assert state.attributes[ATTR_RGBWW_COLOR] == (255, 255, 255, 255, 0)
@ -1359,7 +1361,7 @@ async def test_light_color_temp(
)
]
states = [
LightState(
ESPHomeLightState(
key=1,
state=True,
brightness=100,
@ -1376,7 +1378,7 @@ async def test_light_color_temp(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_MIN_MIREDS] == 153
@ -1434,7 +1436,7 @@ async def test_light_color_temp_no_mireds_set(
)
]
states = [
LightState(
ESPHomeLightState(
key=1,
state=True,
brightness=100,
@ -1451,7 +1453,7 @@ async def test_light_color_temp_no_mireds_set(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_MIN_MIREDS] is None
@ -1531,7 +1533,7 @@ async def test_light_color_temp_legacy(
)
]
states = [
LightState(
ESPHomeLightState(
key=1,
state=True,
brightness=100,
@ -1553,7 +1555,7 @@ async def test_light_color_temp_legacy(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_COLOR_MODE] == ColorMode.COLOR_TEMP
@ -1617,7 +1619,7 @@ async def test_light_rgb_legacy(
)
]
states = [
LightState(
ESPHomeLightState(
key=1,
state=True,
brightness=100,
@ -1639,7 +1641,7 @@ async def test_light_rgb_legacy(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.RGB]
assert attributes[ATTR_COLOR_MODE] == ColorMode.RGB
@ -1707,7 +1709,7 @@ async def test_light_effects(
],
)
]
states = [LightState(key=1, state=True, brightness=100)]
states = [ESPHomeLightState(key=1, state=True, brightness=100)]
user_service = []
await mock_generic_device_entry(
mock_client=mock_client,
@ -1717,7 +1719,7 @@ async def test_light_effects(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_EFFECT_LIST] == ["effect1", "effect2"]
await hass.services.async_call(
@ -1762,7 +1764,7 @@ async def test_only_cold_warm_white_support(
)
]
states = [
LightState(
ESPHomeLightState(
key=1,
state=True,
color_brightness=1,
@ -1784,7 +1786,7 @@ async def test_only_cold_warm_white_support(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.COLOR_TEMP]
assert state.attributes[ATTR_COLOR_MODE] == ColorMode.COLOR_TEMP
assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == 0
@ -1853,7 +1855,7 @@ async def test_light_no_color_modes(
supported_color_modes=[color_mode],
)
]
states = [LightState(key=1, state=True, brightness=100)]
states = [ESPHomeLightState(key=1, state=True, brightness=100)]
user_service = []
await mock_generic_device_entry(
mock_client=mock_client,
@ -1863,7 +1865,7 @@ async def test_light_no_color_modes(
)
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.ONOFF]
await hass.services.async_call(

View file

@ -52,6 +52,7 @@ from homeassistant.components.light import (
ATTR_WHITE,
DOMAIN as LIGHT_DOMAIN,
ColorMode,
LightState,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -59,8 +60,6 @@ from homeassistant.const import (
CONF_HOST,
CONF_MODE,
CONF_NAME,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant
@ -100,7 +99,7 @@ async def test_light_unique_id(
entity_id = "light.bulb_rgbcw_ddeeff"
assert entity_registry.async_get(entity_id).unique_id == MAC_ADDRESS
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
async def test_light_goes_unavailable_and_recovers(
@ -121,7 +120,7 @@ async def test_light_goes_unavailable_and_recovers(
entity_id = "light.bulb_rgbcw_ddeeff"
assert entity_registry.async_get(entity_id).unique_id == MAC_ADDRESS
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
now = utcnow()
bulb.async_update = AsyncMock(side_effect=RuntimeError)
@ -135,7 +134,7 @@ async def test_light_goes_unavailable_and_recovers(
async_fire_time_changed(hass, now + timedelta(seconds=i))
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
async def test_light_mac_address_not_found(
@ -154,7 +153,7 @@ async def test_light_mac_address_not_found(
entity_id = "light.bulb_rgbcw_ddeeff"
assert entity_registry.async_get(entity_id).unique_id == config_entry.entry_id
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
@pytest.mark.parametrize(
@ -215,7 +214,7 @@ async def test_rgb_light(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "rgb"
@ -229,7 +228,7 @@ async def test_rgb_light(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
assert hass.states.get(entity_id).state == STATE_OFF
assert hass.states.get(entity_id).state == LightState.OFF
bulb.brightness = 0
await hass.services.async_call(
@ -256,7 +255,7 @@ async def test_rgb_light(hass: HomeAssistant) -> None:
bulb.async_set_brightness.assert_called_with(100)
bulb.async_set_brightness.reset_mock()
await async_mock_device_turn_on(hass, bulb)
assert hass.states.get(entity_id).state == STATE_ON
assert hass.states.get(entity_id).state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -321,7 +320,7 @@ async def test_rgb_light_auto_on(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == ColorMode.RGB
@ -335,7 +334,7 @@ async def test_rgb_light_auto_on(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
assert hass.states.get(entity_id).state == STATE_OFF
assert hass.states.get(entity_id).state == LightState.OFF
bulb.brightness = 0
await hass.services.async_call(
@ -375,7 +374,7 @@ async def test_rgb_light_auto_on(hass: HomeAssistant) -> None:
)
bulb.async_turn_on.assert_called_once()
await async_mock_device_turn_on(hass, bulb)
assert hass.states.get(entity_id).state == STATE_ON
assert hass.states.get(entity_id).state == LightState.ON
bulb.async_turn_on.reset_mock()
await hass.services.async_call(
@ -454,7 +453,7 @@ async def test_rgbw_light_auto_on(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == ColorMode.RGBW
@ -468,7 +467,7 @@ async def test_rgbw_light_auto_on(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
assert hass.states.get(entity_id).state == STATE_OFF
assert hass.states.get(entity_id).state == LightState.OFF
bulb.brightness = 0
await hass.services.async_call(
@ -490,7 +489,7 @@ async def test_rgbw_light_auto_on(hass: HomeAssistant) -> None:
)
bulb.async_turn_on.assert_called_once()
await async_mock_device_turn_on(hass, bulb)
assert hass.states.get(entity_id).state == STATE_ON
assert hass.states.get(entity_id).state == LightState.ON
bulb.async_turn_on.reset_mock()
await hass.services.async_call(
@ -589,7 +588,7 @@ async def test_rgbww_light_auto_on(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == ColorMode.RGBWW
@ -603,7 +602,7 @@ async def test_rgbww_light_auto_on(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
assert hass.states.get(entity_id).state == STATE_OFF
assert hass.states.get(entity_id).state == LightState.OFF
bulb.brightness = 0
await hass.services.async_call(
@ -625,7 +624,7 @@ async def test_rgbww_light_auto_on(hass: HomeAssistant) -> None:
)
bulb.async_turn_on.assert_called_once()
await async_mock_device_turn_on(hass, bulb)
assert hass.states.get(entity_id).state == STATE_ON
assert hass.states.get(entity_id).state == LightState.ON
bulb.async_turn_on.reset_mock()
await hass.services.async_call(
@ -706,7 +705,7 @@ async def test_rgb_cct_light(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "rgb"
@ -720,7 +719,7 @@ async def test_rgb_cct_light(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
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, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
@ -772,7 +771,7 @@ async def test_rgb_cct_light(hass: HomeAssistant) -> None:
)
await async_mock_device_turn_on(hass, bulb)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "color_temp"
@ -829,7 +828,7 @@ async def test_rgbw_light_cold_white(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "rgbw"
@ -843,7 +842,7 @@ async def test_rgbw_light_cold_white(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
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, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
@ -861,7 +860,7 @@ async def test_rgbw_light_cold_white(hass: HomeAssistant) -> None:
bulb.async_set_brightness.assert_called_with(100)
bulb.async_set_brightness.reset_mock()
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -935,7 +934,7 @@ async def test_rgbw_light_warm_white(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "rgbw"
@ -949,7 +948,7 @@ async def test_rgbw_light_warm_white(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
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, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
@ -967,7 +966,7 @@ async def test_rgbw_light_warm_white(hass: HomeAssistant) -> None:
bulb.async_set_brightness.assert_called_with(100)
bulb.async_set_brightness.reset_mock()
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -1073,7 +1072,7 @@ async def test_rgb_or_w_light(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "rgb"
@ -1087,7 +1086,7 @@ async def test_rgb_or_w_light(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
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, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
@ -1105,7 +1104,7 @@ async def test_rgb_or_w_light(hass: HomeAssistant) -> None:
bulb.async_set_brightness.assert_called_with(100)
bulb.async_set_brightness.reset_mock()
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -1184,7 +1183,7 @@ async def test_rgbcw_light(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "rgbww"
@ -1198,7 +1197,7 @@ async def test_rgbcw_light(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
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, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
@ -1309,7 +1308,7 @@ async def test_rgbcw_light(hass: HomeAssistant) -> None:
bulb.rgb = (MIN_RGB_BRIGHTNESS, MIN_RGB_BRIGHTNESS, MIN_RGB_BRIGHTNESS)
await async_mock_device_turn_on(hass, bulb)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_COLOR_MODE] == ColorMode.RGBWW
assert state.attributes[ATTR_BRIGHTNESS] == 1
@ -1343,7 +1342,7 @@ async def test_white_light(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "brightness"
@ -1356,7 +1355,7 @@ async def test_white_light(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
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, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
@ -1394,7 +1393,7 @@ async def test_no_color_modes(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_COLOR_MODE] == "onoff"
assert ATTR_EFFECT_LIST in attributes # single channel now supports effects
@ -1405,7 +1404,7 @@ async def test_no_color_modes(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
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, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
@ -1438,7 +1437,7 @@ async def test_rgb_light_custom_effects(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "rgb"
@ -1452,7 +1451,7 @@ async def test_rgb_light_custom_effects(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
await hass.async_block_till_done()
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,
@ -1468,7 +1467,7 @@ async def test_rgb_light_custom_effects(hass: HomeAssistant) -> None:
await async_mock_device_turn_on(hass, bulb)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_EFFECT] == "custom"
@ -1486,7 +1485,7 @@ async def test_rgb_light_custom_effects(hass: HomeAssistant) -> None:
await async_mock_device_turn_on(hass, bulb)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_EFFECT] == "custom"
@ -1520,7 +1519,7 @@ async def test_rgb_light_custom_effects_invalid_colors(
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "rgb"
@ -1549,7 +1548,7 @@ async def test_rgb_light_custom_effect_via_service(
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "rgb"
@ -1563,7 +1562,7 @@ async def test_rgb_light_custom_effect_via_service(
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
assert hass.states.get(entity_id).state == STATE_OFF
assert hass.states.get(entity_id).state == LightState.OFF
await hass.services.async_call(
DOMAIN,
@ -1631,7 +1630,7 @@ async def test_addressable_light(hass: HomeAssistant) -> None:
entity_id = "light.bulb_rgbcw_ddeeff"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
attributes = state.attributes
assert attributes[ATTR_COLOR_MODE] == "onoff"
assert ATTR_EFFECT_LIST in attributes
@ -1643,7 +1642,7 @@ async def test_addressable_light(hass: HomeAssistant) -> None:
bulb.async_turn_off.assert_called_once()
await async_mock_device_turn_off(hass, bulb)
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, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True

View file

@ -9,8 +9,9 @@ from homeassistant.components.light import (
ATTR_HS_COLOR,
DOMAIN as LIGHT_DOMAIN,
SERVICE_TURN_ON,
LightState,
)
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, STATE_OFF, STATE_ON
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
@ -34,7 +35,7 @@ async def test_light_get_state(
entity_id = "light.lightbulb"
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes.get("friendly_name") == "lightbulb"
entry = entity_registry.async_get(entity_id)
@ -55,7 +56,7 @@ async def test_light_set_on(
entity_id = "light.lightbulb"
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes.get("friendly_name") == "lightbulb"
entry = entity_registry.async_get(entity_id)
@ -74,7 +75,7 @@ async def test_light_set_on(
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_ON
assert state.state == LightState.ON
async def test_light_set_off(
@ -87,7 +88,7 @@ async def test_light_set_off(
entity_id = "light.bedroomlight"
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_OFF
assert state.state == LightState.OFF
assert state.attributes.get("friendly_name") == "bedroomlight"
entry = entity_registry.async_get(entity_id)
@ -106,7 +107,7 @@ async def test_light_set_off(
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_OFF
assert state.state == LightState.OFF
async def test_light_set_brightness(
@ -119,7 +120,7 @@ async def test_light_set_brightness(
entity_id = "light.lightbulb"
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes.get("friendly_name") == "lightbulb"
entry = entity_registry.async_get(entity_id)
@ -138,7 +139,7 @@ async def test_light_set_brightness(
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_ON
assert state.state == LightState.ON
assert int(state.attributes[ATTR_BRIGHTNESS]) == 0
@ -152,7 +153,7 @@ async def test_light_set_hue(
entity_id = "light.lightbulb"
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes.get("friendly_name") == "lightbulb"
entry = entity_registry.async_get(entity_id)
@ -175,6 +176,6 @@ async def test_light_set_hue(
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_ON
assert state.state == LightState.ON
assert int(state.attributes[ATTR_BRIGHTNESS]) == 0
assert state.attributes[ATTR_HS_COLOR] == (0, 0)

View file

@ -21,6 +21,7 @@ from homeassistant.components.light import (
ATTR_SUPPORTED_COLOR_MODES,
DOMAIN as LIGHT_DOMAIN,
ColorMode,
LightState,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -28,7 +29,6 @@ from homeassistant.const import (
CONF_DEVICES,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_ON,
)
from homeassistant.core import HomeAssistant
import homeassistant.util.dt as dt_util
@ -57,7 +57,7 @@ async def test_setup(hass: HomeAssistant, fritz: Mock) -> None:
state = hass.states.get(ENTITY_ID)
assert state
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_FRIENDLY_NAME] == "fake_name"
assert state.attributes[ATTR_COLOR_MODE] == ColorMode.COLOR_TEMP
assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == 2700
@ -80,7 +80,7 @@ async def test_setup_non_color(hass: HomeAssistant, fritz: Mock) -> None:
state = hass.states.get(ENTITY_ID)
assert state
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_FRIENDLY_NAME] == "fake_name"
assert state.attributes[ATTR_BRIGHTNESS] == 100
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["brightness"]
@ -100,7 +100,7 @@ async def test_setup_non_color_non_level(hass: HomeAssistant, fritz: Mock) -> No
state = hass.states.get(ENTITY_ID)
assert state
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_FRIENDLY_NAME] == "fake_name"
assert ATTR_BRIGHTNESS not in state.attributes
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["onoff"]
@ -126,7 +126,7 @@ async def test_setup_color(hass: HomeAssistant, fritz: Mock) -> None:
state = hass.states.get(ENTITY_ID)
assert state
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_FRIENDLY_NAME] == "fake_name"
assert state.attributes[ATTR_COLOR_MODE] == ColorMode.HS
assert state.attributes[ATTR_COLOR_TEMP_KELVIN] is None

View file

@ -30,13 +30,12 @@ from homeassistant.components.light import (
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
ColorMode,
LightState,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_SUPPORTED_FEATURES,
EVENT_CALL_SERVICE,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)
@ -76,7 +75,7 @@ async def test_default_state(
state = hass.states.get("light.bedroom_group")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
assert state.attributes.get(ATTR_ENTITY_ID) == ["light.kitchen", "light.bedroom"]
assert state.attributes.get(ATTR_BRIGHTNESS) is None
@ -135,41 +134,41 @@ async def test_state_reporting_any(hass: HomeAssistant) -> None:
assert hass.states.get("light.light_group").state == STATE_UNKNOWN
# At least one member on -> group on
hass.states.async_set("light.test1", STATE_ON)
hass.states.async_set("light.test1", LightState.ON)
hass.states.async_set("light.test2", STATE_UNAVAILABLE)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_ON
assert hass.states.get("light.light_group").state == LightState.ON
hass.states.async_set("light.test1", STATE_ON)
hass.states.async_set("light.test2", STATE_OFF)
hass.states.async_set("light.test1", LightState.ON)
hass.states.async_set("light.test2", LightState.OFF)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_ON
assert hass.states.get("light.light_group").state == LightState.ON
hass.states.async_set("light.test1", STATE_ON)
hass.states.async_set("light.test2", STATE_ON)
hass.states.async_set("light.test1", LightState.ON)
hass.states.async_set("light.test2", LightState.ON)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_ON
assert hass.states.get("light.light_group").state == LightState.ON
hass.states.async_set("light.test1", STATE_ON)
hass.states.async_set("light.test1", LightState.ON)
hass.states.async_set("light.test2", STATE_UNKNOWN)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_ON
assert hass.states.get("light.light_group").state == LightState.ON
# Otherwise -> off
hass.states.async_set("light.test1", STATE_OFF)
hass.states.async_set("light.test2", STATE_OFF)
hass.states.async_set("light.test1", LightState.OFF)
hass.states.async_set("light.test2", LightState.OFF)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_OFF
assert hass.states.get("light.light_group").state == LightState.OFF
hass.states.async_set("light.test1", STATE_UNKNOWN)
hass.states.async_set("light.test2", STATE_OFF)
hass.states.async_set("light.test2", LightState.OFF)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_OFF
assert hass.states.get("light.light_group").state == LightState.OFF
hass.states.async_set("light.test1", STATE_UNAVAILABLE)
hass.states.async_set("light.test2", STATE_OFF)
hass.states.async_set("light.test2", LightState.OFF)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_OFF
assert hass.states.get("light.light_group").state == LightState.OFF
# All group members removed from the state machine -> unavailable
hass.states.async_remove("light.test1")
@ -211,12 +210,12 @@ async def test_state_reporting_all(hass: HomeAssistant) -> None:
assert hass.states.get("light.light_group").state == STATE_UNAVAILABLE
# At least one member unknown or unavailable -> group unknown
hass.states.async_set("light.test1", STATE_ON)
hass.states.async_set("light.test1", LightState.ON)
hass.states.async_set("light.test2", STATE_UNAVAILABLE)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_UNKNOWN
hass.states.async_set("light.test1", STATE_ON)
hass.states.async_set("light.test1", LightState.ON)
hass.states.async_set("light.test2", STATE_UNKNOWN)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_UNKNOWN
@ -226,12 +225,12 @@ async def test_state_reporting_all(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_UNKNOWN
hass.states.async_set("light.test1", STATE_OFF)
hass.states.async_set("light.test1", LightState.OFF)
hass.states.async_set("light.test2", STATE_UNAVAILABLE)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_UNKNOWN
hass.states.async_set("light.test1", STATE_OFF)
hass.states.async_set("light.test1", LightState.OFF)
hass.states.async_set("light.test2", STATE_UNKNOWN)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_UNKNOWN
@ -242,21 +241,21 @@ async def test_state_reporting_all(hass: HomeAssistant) -> None:
assert hass.states.get("light.light_group").state == STATE_UNKNOWN
# At least one member off -> group off
hass.states.async_set("light.test1", STATE_ON)
hass.states.async_set("light.test2", STATE_OFF)
hass.states.async_set("light.test1", LightState.ON)
hass.states.async_set("light.test2", LightState.OFF)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_OFF
assert hass.states.get("light.light_group").state == LightState.OFF
hass.states.async_set("light.test1", STATE_OFF)
hass.states.async_set("light.test2", STATE_OFF)
hass.states.async_set("light.test1", LightState.OFF)
hass.states.async_set("light.test2", LightState.OFF)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_OFF
assert hass.states.get("light.light_group").state == LightState.OFF
# Otherwise -> on
hass.states.async_set("light.test1", STATE_ON)
hass.states.async_set("light.test2", STATE_ON)
hass.states.async_set("light.test1", LightState.ON)
hass.states.async_set("light.test2", LightState.ON)
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_ON
assert hass.states.get("light.light_group").state == LightState.ON
# All group members removed from the state machine -> unavailable
hass.states.async_remove("light.test1")
@ -268,8 +267,8 @@ async def test_state_reporting_all(hass: HomeAssistant) -> None:
async def test_brightness(hass: HomeAssistant) -> None:
"""Test brightness reporting."""
entities = [
MockLight("test1", STATE_ON),
MockLight("test2", STATE_OFF),
MockLight("test1", LightState.ON),
MockLight("test2", LightState.OFF),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -301,7 +300,7 @@ async def test_brightness(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 255
assert state.attributes[ATTR_COLOR_MODE] == "brightness"
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
@ -315,7 +314,7 @@ async def test_brightness(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 177
assert state.attributes[ATTR_COLOR_MODE] == "brightness"
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
@ -329,7 +328,7 @@ async def test_brightness(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 100
assert state.attributes[ATTR_COLOR_MODE] == "brightness"
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
@ -339,8 +338,8 @@ async def test_brightness(hass: HomeAssistant) -> None:
async def test_color_hs(hass: HomeAssistant) -> None:
"""Test hs color reporting."""
entities = [
MockLight("test1", STATE_ON),
MockLight("test2", STATE_OFF),
MockLight("test1", LightState.ON),
MockLight("test2", LightState.OFF),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -373,7 +372,7 @@ async def test_color_hs(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_COLOR_MODE] == "hs"
assert state.attributes[ATTR_HS_COLOR] == (0, 100)
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["hs"]
@ -409,8 +408,8 @@ async def test_color_hs(hass: HomeAssistant) -> None:
async def test_color_rgb(hass: HomeAssistant) -> None:
"""Test rgbw color reporting."""
entities = [
MockLight("test1", STATE_ON),
MockLight("test2", STATE_OFF),
MockLight("test1", LightState.ON),
MockLight("test2", LightState.OFF),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -445,7 +444,7 @@ async def test_color_rgb(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_COLOR_MODE] == "rgb"
assert state.attributes[ATTR_RGB_COLOR] == (0, 64, 128)
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["rgb"]
@ -481,8 +480,8 @@ async def test_color_rgb(hass: HomeAssistant) -> None:
async def test_color_rgbw(hass: HomeAssistant) -> None:
"""Test rgbw color reporting."""
entities = [
MockLight("test1", STATE_ON),
MockLight("test2", STATE_OFF),
MockLight("test1", LightState.ON),
MockLight("test2", LightState.OFF),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -517,7 +516,7 @@ async def test_color_rgbw(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_COLOR_MODE] == "rgbw"
assert state.attributes[ATTR_RGBW_COLOR] == (0, 64, 128, 255)
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["rgbw"]
@ -553,8 +552,8 @@ async def test_color_rgbw(hass: HomeAssistant) -> None:
async def test_color_rgbww(hass: HomeAssistant) -> None:
"""Test rgbww color reporting."""
entities = [
MockLight("test1", STATE_ON),
MockLight("test2", STATE_OFF),
MockLight("test1", LightState.ON),
MockLight("test2", LightState.OFF),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -589,7 +588,7 @@ async def test_color_rgbww(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_COLOR_MODE] == "rgbww"
assert state.attributes[ATTR_RGBWW_COLOR] == (0, 32, 64, 128, 255)
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["rgbww"]
@ -625,8 +624,8 @@ async def test_color_rgbww(hass: HomeAssistant) -> None:
async def test_white(hass: HomeAssistant) -> None:
"""Test white reporting."""
entities = [
MockLight("test1", STATE_ON),
MockLight("test2", STATE_ON),
MockLight("test1", LightState.ON),
MockLight("test2", LightState.ON),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -682,8 +681,8 @@ async def test_white(hass: HomeAssistant) -> None:
async def test_color_temp(hass: HomeAssistant) -> None:
"""Test color temp reporting."""
entities = [
MockLight("test1", STATE_ON),
MockLight("test2", STATE_OFF),
MockLight("test1", LightState.ON),
MockLight("test2", LightState.OFF),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -751,9 +750,9 @@ async def test_color_temp(hass: HomeAssistant) -> None:
async def test_emulated_color_temp_group(hass: HomeAssistant) -> None:
"""Test emulated color temperature in a group."""
entities = [
MockLight("test1", STATE_ON),
MockLight("test2", STATE_OFF),
MockLight("test3", STATE_OFF),
MockLight("test1", LightState.ON),
MockLight("test2", LightState.OFF),
MockLight("test3", LightState.OFF),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -798,17 +797,17 @@ async def test_emulated_color_temp_group(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
state = hass.states.get("light.test1")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_COLOR_TEMP] == 200
assert ATTR_HS_COLOR in state.attributes
state = hass.states.get("light.test2")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_COLOR_TEMP] == 200
assert ATTR_HS_COLOR in state.attributes
state = hass.states.get("light.test3")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_HS_COLOR] == (27.001, 19.243)
@ -818,8 +817,8 @@ async def test_min_max_mireds(hass: HomeAssistant) -> None:
min/max mireds is reported both when light is on and off
"""
entities = [
MockLight("test1", STATE_ON),
MockLight("test2", STATE_OFF),
MockLight("test1", LightState.ON),
MockLight("test2", LightState.OFF),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -901,7 +900,7 @@ async def test_effect_list(hass: HomeAssistant) -> None:
hass.states.async_set(
"light.test1",
STATE_ON,
LightState.ON,
{ATTR_EFFECT_LIST: ["None", "Random", "Colorloop"], ATTR_SUPPORTED_FEATURES: 4},
)
await hass.async_block_till_done()
@ -914,7 +913,7 @@ async def test_effect_list(hass: HomeAssistant) -> None:
hass.states.async_set(
"light.test2",
STATE_ON,
LightState.ON,
{ATTR_EFFECT_LIST: ["None", "Random", "Rainbow"], ATTR_SUPPORTED_FEATURES: 4},
)
await hass.async_block_till_done()
@ -928,7 +927,7 @@ async def test_effect_list(hass: HomeAssistant) -> None:
hass.states.async_set(
"light.test1",
STATE_OFF,
LightState.OFF,
{ATTR_EFFECT_LIST: ["None", "Colorloop", "Seven"], ATTR_SUPPORTED_FEATURES: 4},
)
await hass.async_block_till_done()
@ -960,31 +959,33 @@ async def test_effect(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
hass.states.async_set(
"light.test1", STATE_ON, {ATTR_EFFECT: "None", ATTR_SUPPORTED_FEATURES: 6}
"light.test1", LightState.ON, {ATTR_EFFECT: "None", ATTR_SUPPORTED_FEATURES: 6}
)
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.attributes[ATTR_EFFECT] == "None"
hass.states.async_set(
"light.test2", STATE_ON, {ATTR_EFFECT: "None", ATTR_SUPPORTED_FEATURES: 6}
"light.test2", LightState.ON, {ATTR_EFFECT: "None", ATTR_SUPPORTED_FEATURES: 6}
)
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.attributes[ATTR_EFFECT] == "None"
hass.states.async_set(
"light.test3", STATE_ON, {ATTR_EFFECT: "Random", ATTR_SUPPORTED_FEATURES: 6}
"light.test3",
LightState.ON,
{ATTR_EFFECT: "Random", ATTR_SUPPORTED_FEATURES: 6},
)
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.attributes[ATTR_EFFECT] == "None"
hass.states.async_set(
"light.test1", STATE_OFF, {ATTR_EFFECT: "None", ATTR_SUPPORTED_FEATURES: 6}
"light.test1", LightState.OFF, {ATTR_EFFECT: "None", ATTR_SUPPORTED_FEATURES: 6}
)
hass.states.async_set(
"light.test2", STATE_OFF, {ATTR_EFFECT: "None", ATTR_SUPPORTED_FEATURES: 6}
"light.test2", LightState.OFF, {ATTR_EFFECT: "None", ATTR_SUPPORTED_FEATURES: 6}
)
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
@ -994,9 +995,9 @@ async def test_effect(hass: HomeAssistant) -> None:
async def test_supported_color_modes(hass: HomeAssistant) -> None:
"""Test supported_color_modes reporting."""
entities = [
MockLight("test1", STATE_ON),
MockLight("test2", STATE_OFF),
MockLight("test3", STATE_OFF),
MockLight("test1", LightState.ON),
MockLight("test2", LightState.OFF),
MockLight("test3", LightState.OFF),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -1042,9 +1043,9 @@ async def test_supported_color_modes(hass: HomeAssistant) -> None:
async def test_color_mode(hass: HomeAssistant) -> None:
"""Test color_mode reporting."""
entities = [
MockLight("test1", STATE_ON),
MockLight("test2", STATE_OFF),
MockLight("test3", STATE_OFF),
MockLight("test1", LightState.ON),
MockLight("test2", LightState.OFF),
MockLight("test3", LightState.OFF),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -1115,12 +1116,12 @@ async def test_color_mode(hass: HomeAssistant) -> None:
async def test_color_mode2(hass: HomeAssistant) -> None:
"""Test onoff color_mode and brightness are given lowest priority."""
entities = [
MockLight("test1", STATE_ON),
MockLight("test2", STATE_ON),
MockLight("test3", STATE_ON),
MockLight("test4", STATE_ON),
MockLight("test5", STATE_ON),
MockLight("test6", STATE_ON),
MockLight("test1", LightState.ON),
MockLight("test2", LightState.ON),
MockLight("test3", LightState.ON),
MockLight("test4", LightState.ON),
MockLight("test5", LightState.ON),
MockLight("test6", LightState.ON),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -1206,28 +1207,28 @@ async def test_supported_features(hass: HomeAssistant) -> None:
await hass.async_start()
await hass.async_block_till_done()
hass.states.async_set("light.test1", STATE_ON, {ATTR_SUPPORTED_FEATURES: 0})
hass.states.async_set("light.test1", LightState.ON, {ATTR_SUPPORTED_FEATURES: 0})
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
# SUPPORT_COLOR_TEMP = 2
# SUPPORT_COLOR_TEMP = 2 will be blocked in favour of ColorMode.COLOR_TEMP
hass.states.async_set("light.test2", STATE_ON, {ATTR_SUPPORTED_FEATURES: 2})
hass.states.async_set("light.test2", LightState.ON, {ATTR_SUPPORTED_FEATURES: 2})
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
# LightEntityFeature.TRANSITION | LightEntityFeature.FLASH | SUPPORT_BRIGHTNESS = 41
# SUPPORT_BRIGHTNESS = 1 will be translated to ColorMode.BRIGHTNESS
hass.states.async_set("light.test1", STATE_OFF, {ATTR_SUPPORTED_FEATURES: 41})
hass.states.async_set("light.test1", LightState.OFF, {ATTR_SUPPORTED_FEATURES: 41})
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
# LightEntityFeature.TRANSITION | LightEntityFeature.FLASH = 40
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 40
# Test that unknown feature 256 is blocked
hass.states.async_set("light.test2", STATE_OFF, {ATTR_SUPPORTED_FEATURES: 256})
hass.states.async_set("light.test2", LightState.OFF, {ATTR_SUPPORTED_FEATURES: 256})
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 40
@ -1240,9 +1241,9 @@ async def test_service_calls(
) -> None:
"""Test service calls."""
entities = [
MockLight("bed_light", STATE_ON),
MockLight("ceiling_lights", STATE_OFF),
MockLight("kitchen_lights", STATE_OFF),
MockLight("bed_light", LightState.ON),
MockLight("ceiling_lights", LightState.OFF),
MockLight("kitchen_lights", LightState.OFF),
]
setup_test_component_platform(hass, LIGHT_DOMAIN, entities)
@ -1287,7 +1288,7 @@ async def test_service_calls(
await hass.async_block_till_done()
group_state = hass.states.get("light.light_group")
assert group_state.state == STATE_ON
assert group_state.state == LightState.ON
assert group_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [supported_color_modes]
await hass.services.async_call(
@ -1296,9 +1297,9 @@ async def test_service_calls(
{ATTR_ENTITY_ID: "light.light_group"},
blocking=True,
)
assert hass.states.get("light.bed_light").state == STATE_OFF
assert hass.states.get("light.ceiling_lights").state == STATE_OFF
assert hass.states.get("light.kitchen_lights").state == STATE_OFF
assert hass.states.get("light.bed_light").state == LightState.OFF
assert hass.states.get("light.ceiling_lights").state == LightState.OFF
assert hass.states.get("light.kitchen_lights").state == LightState.OFF
await hass.services.async_call(
LIGHT_DOMAIN,
@ -1307,9 +1308,9 @@ async def test_service_calls(
blocking=True,
)
assert hass.states.get("light.bed_light").state == STATE_ON
assert hass.states.get("light.ceiling_lights").state == STATE_ON
assert hass.states.get("light.kitchen_lights").state == STATE_ON
assert hass.states.get("light.bed_light").state == LightState.ON
assert hass.states.get("light.ceiling_lights").state == LightState.ON
assert hass.states.get("light.kitchen_lights").state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -1318,9 +1319,9 @@ async def test_service_calls(
blocking=True,
)
assert hass.states.get("light.bed_light").state == STATE_OFF
assert hass.states.get("light.ceiling_lights").state == STATE_OFF
assert hass.states.get("light.kitchen_lights").state == STATE_OFF
assert hass.states.get("light.bed_light").state == LightState.OFF
assert hass.states.get("light.ceiling_lights").state == LightState.OFF
assert hass.states.get("light.kitchen_lights").state == LightState.OFF
await hass.services.async_call(
LIGHT_DOMAIN,
@ -1334,17 +1335,17 @@ async def test_service_calls(
)
state = hass.states.get("light.bed_light")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 128
assert state.attributes[ATTR_RGB_COLOR] == (42, 255, 255)
state = hass.states.get("light.ceiling_lights")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 128
assert state.attributes[ATTR_RGB_COLOR] == (42, 255, 255)
state = hass.states.get("light.kitchen_lights")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 128
assert state.attributes[ATTR_RGB_COLOR] == (42, 255, 255)
@ -1360,17 +1361,17 @@ async def test_service_calls(
)
state = hass.states.get("light.bed_light")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 128
assert state.attributes[ATTR_RGB_COLOR] == (255, 0, 0)
state = hass.states.get("light.ceiling_lights")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 128
assert state.attributes[ATTR_RGB_COLOR] == (255, 0, 0)
state = hass.states.get("light.kitchen_lights")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 128
assert state.attributes[ATTR_RGB_COLOR] == (255, 0, 0)
@ -1399,7 +1400,7 @@ async def test_service_call_effect(hass: HomeAssistant) -> None:
await hass.async_start()
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_ON
assert hass.states.get("light.light_group").state == LightState.ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -1414,18 +1415,18 @@ async def test_service_call_effect(hass: HomeAssistant) -> None:
)
state = hass.states.get("light.bed_light")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 128
assert state.attributes[ATTR_EFFECT] == "Random"
assert state.attributes[ATTR_RGB_COLOR] == (42, 255, 255)
state = hass.states.get("light.ceiling_lights")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 128
assert state.attributes[ATTR_RGB_COLOR] == (42, 255, 255)
state = hass.states.get("light.kitchen_lights")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 128
assert state.attributes[ATTR_RGB_COLOR] == (42, 255, 255)
@ -1505,7 +1506,7 @@ async def test_reload(hass: HomeAssistant) -> None:
await hass.async_start()
await hass.async_block_till_done()
assert hass.states.get("light.light_group").state == STATE_ON
assert hass.states.get("light.light_group").state == LightState.ON
yaml_path = get_fixture_path("configuration.yaml", "group")
with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
@ -1524,7 +1525,7 @@ async def test_reload(hass: HomeAssistant) -> None:
async def test_reload_with_platform_not_setup(hass: HomeAssistant) -> None:
"""Test the ability to reload lights."""
hass.states.async_set("light.bowl", STATE_ON)
hass.states.async_set("light.bowl", LightState.ON)
await async_setup_component(
hass,
LIGHT_DOMAIN,
@ -1574,11 +1575,11 @@ async def test_reload_with_base_integration_platform_not_setup(
},
)
await hass.async_block_till_done()
hass.states.async_set("light.master_hall_lights", STATE_ON)
hass.states.async_set("light.master_hall_lights_2", STATE_OFF)
hass.states.async_set("light.master_hall_lights", LightState.ON)
hass.states.async_set("light.master_hall_lights_2", LightState.OFF)
hass.states.async_set("light.outside_patio_lights", STATE_OFF)
hass.states.async_set("light.outside_patio_lights_2", STATE_OFF)
hass.states.async_set("light.outside_patio_lights", LightState.OFF)
hass.states.async_set("light.outside_patio_lights_2", LightState.OFF)
yaml_path = get_fixture_path("configuration.yaml", "group")
with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
@ -1593,8 +1594,8 @@ async def test_reload_with_base_integration_platform_not_setup(
assert hass.states.get("light.light_group") is None
assert hass.states.get("light.master_hall_lights_g") is not None
assert hass.states.get("light.outside_patio_lights_g") is not None
assert hass.states.get("light.master_hall_lights_g").state == STATE_ON
assert hass.states.get("light.outside_patio_lights_g").state == STATE_OFF
assert hass.states.get("light.master_hall_lights_g").state == LightState.ON
assert hass.states.get("light.outside_patio_lights_g").state == LightState.OFF
async def test_nested_group(hass: HomeAssistant) -> None:
@ -1626,7 +1627,7 @@ async def test_nested_group(hass: HomeAssistant) -> None:
state = hass.states.get("light.bedroom_group")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes.get(ATTR_ENTITY_ID) == [
"light.bed_light",
"light.kitchen_lights",
@ -1634,7 +1635,7 @@ async def test_nested_group(hass: HomeAssistant) -> None:
state = hass.states.get("light.nested_group")
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes.get(ATTR_ENTITY_ID) == ["light.bedroom_group"]
# Test controlling the nested group
@ -1645,7 +1646,7 @@ async def test_nested_group(hass: HomeAssistant) -> None:
{ATTR_ENTITY_ID: "light.nested_group"},
blocking=True,
)
assert hass.states.get("light.bed_light").state == STATE_OFF
assert hass.states.get("light.kitchen_lights").state == STATE_OFF
assert hass.states.get("light.bedroom_group").state == STATE_OFF
assert hass.states.get("light.nested_group").state == STATE_OFF
assert hass.states.get("light.bed_light").state == LightState.OFF
assert hass.states.get("light.kitchen_lights").state == LightState.OFF
assert hass.states.get("light.bedroom_group").state == LightState.OFF
assert hass.states.get("light.nested_group").state == LightState.OFF

View file

@ -15,13 +15,11 @@ from homeassistant.components.home_connect.const import (
REFRIGERATION_EXTERNAL_LIGHT_BRIGHTNESS,
REFRIGERATION_EXTERNAL_LIGHT_POWER,
)
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN, LightState
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import (
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
Platform,
)
@ -75,7 +73,7 @@ async def test_light(
},
SERVICE_TURN_ON,
{},
STATE_ON,
LightState.ON,
"Hood",
),
(
@ -88,7 +86,7 @@ async def test_light(
},
SERVICE_TURN_ON,
{"brightness": 200},
STATE_ON,
LightState.ON,
"Hood",
),
(
@ -99,7 +97,7 @@ async def test_light(
},
SERVICE_TURN_OFF,
{},
STATE_OFF,
LightState.OFF,
"Hood",
),
(
@ -125,7 +123,7 @@ async def test_light(
},
SERVICE_TURN_ON,
{"brightness": 200},
STATE_ON,
LightState.ON,
"Hood",
),
(
@ -136,7 +134,7 @@ async def test_light(
},
SERVICE_TURN_OFF,
{},
STATE_OFF,
LightState.OFF,
"Hood",
),
(
@ -147,7 +145,7 @@ async def test_light(
},
SERVICE_TURN_ON,
{},
STATE_ON,
LightState.ON,
"Hood",
),
(
@ -160,7 +158,7 @@ async def test_light(
},
SERVICE_TURN_ON,
{},
STATE_ON,
LightState.ON,
"FridgeFreezer",
),
],

View file

@ -29,14 +29,13 @@ from homeassistant.components.light import (
ATTR_WHITE,
DOMAIN as LIGHT_DOMAIN,
ColorMode,
LightState,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_SUPPORTED_FEATURES,
EVENT_HOMEASSISTANT_START,
PERCENTAGE,
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
)
from homeassistant.core import CoreState, Event, HomeAssistant
@ -57,7 +56,7 @@ async def test_light_basic(hass: HomeAssistant, hk_driver, events: list[Event])
"""Test light with char state."""
entity_id = "light.demo"
hass.states.async_set(entity_id, STATE_ON, {ATTR_SUPPORTED_FEATURES: 0})
hass.states.async_set(entity_id, LightState.ON, {ATTR_SUPPORTED_FEATURES: 0})
await hass.async_block_till_done()
acc = Light(hass, hk_driver, "Light", entity_id, 1, None)
hk_driver.add_accessory(acc)
@ -70,7 +69,7 @@ async def test_light_basic(hass: HomeAssistant, hk_driver, events: list[Event])
await hass.async_block_till_done()
assert acc.char_on.value == 1
hass.states.async_set(entity_id, STATE_OFF, {ATTR_SUPPORTED_FEATURES: 0})
hass.states.async_set(entity_id, LightState.OFF, {ATTR_SUPPORTED_FEATURES: 0})
await hass.async_block_till_done()
assert acc.char_on.value == 0
@ -104,7 +103,7 @@ async def test_light_basic(hass: HomeAssistant, hk_driver, events: list[Event])
assert len(events) == 1
assert events[-1].data[ATTR_VALUE] == "Set state to 1"
hass.states.async_set(entity_id, STATE_ON)
hass.states.async_set(entity_id, LightState.ON)
await hass.async_block_till_done()
hk_driver.set_characteristics(
@ -134,7 +133,7 @@ async def test_light_brightness(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 255},
)
await hass.async_block_till_done()
@ -153,7 +152,7 @@ async def test_light_brightness(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 102},
)
await hass.async_block_till_done()
@ -230,21 +229,21 @@ async def test_light_brightness(
# in update_state
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 0},
)
await hass.async_block_till_done()
assert acc.char_brightness.value == 1
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 255},
)
await hass.async_block_till_done()
assert acc.char_brightness.value == 100
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 0},
)
await hass.async_block_till_done()
@ -253,21 +252,21 @@ async def test_light_brightness(
# Ensure floats are handled
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 55.66},
)
await hass.async_block_till_done()
assert acc.char_brightness.value == 22
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 108.4},
)
await hass.async_block_till_done()
assert acc.char_brightness.value == 43
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_BRIGHTNESS: 0.0},
)
await hass.async_block_till_done()
@ -282,7 +281,7 @@ async def test_light_color_temperature(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: ["color_temp"], ATTR_COLOR_TEMP_KELVIN: 5263},
)
await hass.async_block_till_done()
@ -332,7 +331,7 @@ async def test_light_color_temperature_and_rgb_color(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{
ATTR_SUPPORTED_COLOR_MODES: supported_color_modes,
ATTR_COLOR_TEMP_KELVIN: 5263,
@ -349,7 +348,7 @@ async def test_light_color_temperature_and_rgb_color(
assert hasattr(acc, "char_color_temp")
hass.states.async_set(entity_id, STATE_ON, {ATTR_COLOR_TEMP_KELVIN: 4464})
hass.states.async_set(entity_id, LightState.ON, {ATTR_COLOR_TEMP_KELVIN: 4464})
await hass.async_block_till_done()
acc.run()
await hass.async_block_till_done()
@ -357,7 +356,7 @@ async def test_light_color_temperature_and_rgb_color(
assert acc.char_hue.value == 27
assert acc.char_saturation.value == 27
hass.states.async_set(entity_id, STATE_ON, {ATTR_COLOR_TEMP_KELVIN: 2840})
hass.states.async_set(entity_id, LightState.ON, {ATTR_COLOR_TEMP_KELVIN: 2840})
await hass.async_block_till_done()
acc.run()
await hass.async_block_till_done()
@ -513,7 +512,7 @@ async def test_light_color_temperature_and_rgb_color(
assert events[-1].data[ATTR_VALUE] == "set color at (80, 35)"
# Set from HASS
hass.states.async_set(entity_id, STATE_ON, {ATTR_HS_COLOR: (100, 100)})
hass.states.async_set(entity_id, LightState.ON, {ATTR_HS_COLOR: (100, 100)})
await hass.async_block_till_done()
acc.run()
await hass.async_block_till_done()
@ -533,7 +532,7 @@ async def test_light_rgb_color(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, ATTR_HS_COLOR: (260, 90)},
)
await hass.async_block_till_done()
@ -654,7 +653,7 @@ async def test_light_rgb_with_color_temp(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, **state_props},
)
await hass.async_block_till_done()
@ -774,7 +773,7 @@ async def test_light_rgbwx_with_color_temp_and_brightness(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, **state_props},
)
await hass.async_block_till_done()
@ -833,7 +832,7 @@ async def test_light_rgb_or_w_lights(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGB, ColorMode.WHITE],
ATTR_RGBW_COLOR: (128, 50, 0, 255),
@ -917,7 +916,7 @@ async def test_light_rgb_or_w_lights(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGB, ColorMode.WHITE],
ATTR_BRIGHTNESS: 255,
@ -968,7 +967,7 @@ async def test_light_rgb_with_white_switch_to_temp(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: supported_color_modes, **state_props},
)
await hass.async_block_till_done()
@ -1042,7 +1041,7 @@ async def test_light_rgb_with_hs_color_none(hass: HomeAssistant, hk_driver) -> N
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGB],
ATTR_RGBWW_COLOR: (128, 50, 0, 255, 255),
@ -1076,7 +1075,7 @@ async def test_light_rgbww_with_color_temp_conversion(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBWW],
ATTR_RGBWW_COLOR: (128, 50, 0, 255, 255),
@ -1154,7 +1153,7 @@ async def test_light_rgbww_with_color_temp_conversion(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBWW],
ATTR_RGBWW_COLOR: (0, 0, 0, 128, 255),
@ -1197,7 +1196,7 @@ async def test_light_rgbw_with_color_temp_conversion(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBW],
ATTR_RGBWW_COLOR: (128, 50, 0, 255, 255),
@ -1285,7 +1284,7 @@ async def test_light_set_brightness_and_color(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS],
ATTR_BRIGHTNESS: 255,
@ -1309,7 +1308,7 @@ async def test_light_set_brightness_and_color(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS], ATTR_BRIGHTNESS: 102},
)
await hass.async_block_till_done()
@ -1317,7 +1316,7 @@ async def test_light_set_brightness_and_color(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS], ATTR_HS_COLOR: (4.5, 9.2)},
)
await hass.async_block_till_done()
@ -1369,7 +1368,7 @@ async def test_light_min_max_mireds(hass: HomeAssistant, hk_driver) -> None:
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.COLOR_TEMP],
ATTR_BRIGHTNESS: 255,
@ -1391,7 +1390,7 @@ async def test_light_set_brightness_and_color_temp(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.COLOR_TEMP],
ATTR_BRIGHTNESS: 255,
@ -1414,7 +1413,7 @@ async def test_light_set_brightness_and_color_temp(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{ATTR_SUPPORTED_COLOR_MODES: [ColorMode.COLOR_TEMP], ATTR_BRIGHTNESS: 102},
)
await hass.async_block_till_done()
@ -1422,7 +1421,7 @@ async def test_light_set_brightness_and_color_temp(
hass.states.async_set(
entity_id,
STATE_ON,
LightState.ON,
{
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.COLOR_TEMP],
ATTR_COLOR_TEMP_KELVIN: (4461),

View file

@ -11,8 +11,9 @@ from homeassistant.components.light import (
DOMAIN as LIGHT_DOMAIN,
ColorMode,
LightEntityFeature,
LightState,
)
from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
from homeassistant.const import ATTR_SUPPORTED_FEATURES
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
@ -42,7 +43,7 @@ async def test_hmip_light(
hass, mock_hap, entity_id, entity_name, device_model
)
assert ha_state.state == STATE_ON
assert ha_state.state == LightState.ON
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.ONOFF
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.ONOFF]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
@ -57,7 +58,7 @@ async def test_hmip_light(
await async_manipulate_test_data(hass, hmip_device, "on", False)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
assert ha_state.attributes[ATTR_COLOR_MODE] is None
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.ONOFF]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
@ -71,7 +72,7 @@ async def test_hmip_light(
await async_manipulate_test_data(hass, hmip_device, "on", True)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_ON
assert ha_state.state == LightState.ON
async def test_hmip_notification_light(
@ -89,7 +90,7 @@ async def test_hmip_notification_light(
hass, mock_hap, entity_id, entity_name, device_model
)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
assert ha_state.attributes[ATTR_COLOR_MODE] is None
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.HS]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == LightEntityFeature.TRANSITION
@ -144,7 +145,7 @@ async def test_hmip_notification_light(
hass, hmip_device, "simpleRGBColorState", RGBColorState.PURPLE, 2
)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_ON
assert ha_state.state == LightState.ON
assert ha_state.attributes[ATTR_COLOR_NAME] == RGBColorState.PURPLE
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.HS
@ -165,11 +166,11 @@ async def test_hmip_notification_light(
}
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, 2)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
await async_manipulate_test_data(hass, hmip_device, "dimLevel", None, 2)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
assert not ha_state.attributes.get(ATTR_BRIGHTNESS)
@ -188,7 +189,7 @@ async def test_hmip_dimmer(
hass, mock_hap, entity_id, entity_name, device_model
)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
assert ha_state.attributes[ATTR_COLOR_MODE] is None
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
@ -211,7 +212,7 @@ async def test_hmip_dimmer(
assert hmip_device.mock_calls[-1][1] == (1.0, 1)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_ON
assert ha_state.state == LightState.ON
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
@ -225,11 +226,11 @@ async def test_hmip_dimmer(
assert hmip_device.mock_calls[-1][1] == (0, 1)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
await async_manipulate_test_data(hass, hmip_device, "dimLevel", None)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
assert not ha_state.attributes.get(ATTR_BRIGHTNESS)
@ -248,7 +249,7 @@ async def test_hmip_light_measuring(
hass, mock_hap, entity_id, entity_name, device_model
)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
assert ha_state.attributes[ATTR_COLOR_MODE] is None
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.ONOFF]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
@ -263,7 +264,7 @@ async def test_hmip_light_measuring(
await async_manipulate_test_data(hass, hmip_device, "on", True)
await async_manipulate_test_data(hass, hmip_device, "currentPowerConsumption", 50)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_ON
assert ha_state.state == LightState.ON
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.ONOFF
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.ONOFF]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
@ -276,7 +277,7 @@ async def test_hmip_light_measuring(
assert hmip_device.mock_calls[-1][1] == ()
await async_manipulate_test_data(hass, hmip_device, "on", False)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
async def test_hmip_wired_multi_dimmer(
@ -294,7 +295,7 @@ async def test_hmip_wired_multi_dimmer(
hass, mock_hap, entity_id, entity_name, device_model
)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
assert ha_state.attributes[ATTR_COLOR_MODE] is None
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
@ -317,7 +318,7 @@ async def test_hmip_wired_multi_dimmer(
assert hmip_device.mock_calls[-1][1] == (0.39215686274509803, 1)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, channel=1)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_ON
assert ha_state.state == LightState.ON
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
@ -331,11 +332,11 @@ async def test_hmip_wired_multi_dimmer(
assert hmip_device.mock_calls[-1][1] == (0, 1)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, channel=1)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
await async_manipulate_test_data(hass, hmip_device, "dimLevel", None, channel=1)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
assert not ha_state.attributes.get(ATTR_BRIGHTNESS)
@ -354,7 +355,7 @@ async def test_hmip_din_rail_dimmer_3_channel1(
hass, mock_hap, entity_id, entity_name, device_model
)
assert ha_state.state == STATE_ON
assert ha_state.state == LightState.ON
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
service_call_counter = len(hmip_device.mock_calls)
@ -376,7 +377,7 @@ async def test_hmip_din_rail_dimmer_3_channel1(
assert hmip_device.mock_calls[-1][1] == (0.39215686274509803, 1)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, channel=1)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_ON
assert ha_state.state == LightState.ON
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
@ -390,11 +391,11 @@ async def test_hmip_din_rail_dimmer_3_channel1(
assert hmip_device.mock_calls[-1][1] == (0, 1)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, channel=1)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
await async_manipulate_test_data(hass, hmip_device, "dimLevel", None, channel=1)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
assert not ha_state.attributes.get(ATTR_BRIGHTNESS)
@ -413,7 +414,7 @@ async def test_hmip_din_rail_dimmer_3_channel2(
hass, mock_hap, entity_id, entity_name, device_model
)
assert ha_state.state == STATE_ON
assert ha_state.state == LightState.ON
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
service_call_counter = len(hmip_device.mock_calls)
@ -435,7 +436,7 @@ async def test_hmip_din_rail_dimmer_3_channel2(
assert hmip_device.mock_calls[-1][1] == (0.39215686274509803, 2)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, channel=2)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_ON
assert ha_state.state == LightState.ON
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
@ -449,11 +450,11 @@ async def test_hmip_din_rail_dimmer_3_channel2(
assert hmip_device.mock_calls[-1][1] == (0, 2)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, channel=2)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
await async_manipulate_test_data(hass, hmip_device, "dimLevel", None, channel=2)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
assert not ha_state.attributes.get(ATTR_BRIGHTNESS)
@ -472,7 +473,7 @@ async def test_hmip_din_rail_dimmer_3_channel3(
hass, mock_hap, entity_id, entity_name, device_model
)
assert ha_state.state == STATE_ON
assert ha_state.state == LightState.ON
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
service_call_counter = len(hmip_device.mock_calls)
@ -494,7 +495,7 @@ async def test_hmip_din_rail_dimmer_3_channel3(
assert hmip_device.mock_calls[-1][1] == (0.39215686274509803, 3)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, channel=3)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_ON
assert ha_state.state == LightState.ON
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
assert ha_state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS]
@ -508,9 +509,9 @@ async def test_hmip_din_rail_dimmer_3_channel3(
assert hmip_device.mock_calls[-1][1] == (0, 3)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, channel=3)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
await async_manipulate_test_data(hass, hmip_device, "dimLevel", None, channel=3)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ha_state.state == LightState.OFF
assert not ha_state.attributes.get(ATTR_BRIGHTNESS)

View file

@ -7,14 +7,12 @@ import pytest
from pytest_unordered import unordered
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.light import ATTR_BRIGHTNESS, DOMAIN as LIGHT_DOMAIN
from homeassistant.const import (
ATTR_ENTITY_ID,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
DOMAIN as LIGHT_DOMAIN,
LightState,
)
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
@ -44,13 +42,13 @@ async def test_light_attributes_state_update(
assert hass.states.async_entity_ids("light") == unordered([entity_id])
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
assert state.state == LightState.OFF
assert state == snapshot
hw_callback(HW_LIGHT_CHANGED, ["[02:08:01:01]", 50])
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state == snapshot
@ -114,7 +112,7 @@ async def test_light_restore_brightness(
hw_callback(HW_LIGHT_CHANGED, ["[02:08:01:01]", 50])
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 127
await hass.services.async_call(

View file

@ -18,8 +18,9 @@ from homeassistant.components.light import (
ATTR_HS_COLOR,
ATTR_RGBW_COLOR,
ColorMode,
LightState,
)
from homeassistant.const import CONF_NAME, STATE_OFF, STATE_ON, EntityCategory
from homeassistant.const import CONF_NAME, EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
@ -41,7 +42,7 @@ async def test_light_simple(hass: HomeAssistant, knx: KNXTestKit) -> None:
}
)
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# turn on light
await hass.services.async_call(
"light",
@ -52,7 +53,7 @@ async def test_light_simple(hass: HomeAssistant, knx: KNXTestKit) -> None:
await knx.assert_write(test_address, True)
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
color_mode=ColorMode.ONOFF,
)
# turn off light
@ -63,14 +64,14 @@ async def test_light_simple(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_address, False)
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# receive ON telegram
await knx.receive_write(test_address, True)
knx.assert_state("light.test", STATE_ON)
knx.assert_state("light.test", LightState.ON)
# receive OFF telegram
await knx.receive_write(test_address, False)
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# switch does not respond to read by default
await knx.receive_read(test_address)
@ -104,19 +105,19 @@ async def test_light_brightness(hass: HomeAssistant, knx: KNXTestKit) -> None:
)
await knx.assert_write(test_brightness, (80,))
# state is still OFF until controller reports otherwise
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
await knx.receive_write(test_address, True)
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=80,
color_mode=ColorMode.BRIGHTNESS,
)
# receive brightness changes from KNX
await knx.receive_write(test_brightness_state, (255,))
knx.assert_state("light.test", STATE_ON, brightness=255)
knx.assert_state("light.test", LightState.ON, brightness=255)
await knx.receive_write(test_brightness, (128,))
knx.assert_state("light.test", STATE_ON, brightness=128)
knx.assert_state("light.test", LightState.ON, brightness=128)
# turn off light via brightness
await hass.services.async_call(
"light",
@ -125,7 +126,7 @@ async def test_light_brightness(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_address, False)
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
async def test_light_color_temp_absolute(hass: HomeAssistant, knx: KNXTestKit) -> None:
@ -163,7 +164,7 @@ async def test_light_color_temp_absolute(hass: HomeAssistant, knx: KNXTestKit) -
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=255,
color_mode=ColorMode.COLOR_TEMP,
color_temp=370,
@ -177,12 +178,12 @@ async def test_light_color_temp_absolute(hass: HomeAssistant, knx: KNXTestKit) -
blocking=True,
)
await knx.assert_write(test_ct, (0x0F, 0xA0))
knx.assert_state("light.test", STATE_ON, color_temp=250)
knx.assert_state("light.test", LightState.ON, color_temp=250)
# change color temperature from KNX
await knx.receive_write(test_ct_state, (0x17, 0x70)) # 6000 Kelvin - 166 Mired
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
color_temp=166,
color_temp_kelvin=6000,
)
@ -225,7 +226,7 @@ async def test_light_color_temp_relative(hass: HomeAssistant, knx: KNXTestKit) -
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=255,
color_mode=ColorMode.COLOR_TEMP,
color_temp=250,
@ -244,7 +245,7 @@ async def test_light_color_temp_relative(hass: HomeAssistant, knx: KNXTestKit) -
await knx.assert_write(test_ct, (0x55,))
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
color_temp=300,
color_temp_kelvin=3333,
)
@ -252,7 +253,7 @@ async def test_light_color_temp_relative(hass: HomeAssistant, knx: KNXTestKit) -
await knx.receive_write(test_ct_state, (0xE6,)) # 3901 Kelvin - 90.1 % - 256 Mired
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
color_temp=256,
color_temp_kelvin=3901,
)
@ -298,7 +299,7 @@ async def test_light_hs_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=255,
color_mode=ColorMode.HS,
hs_color=(360, 100),
@ -311,7 +312,7 @@ async def test_light_hs_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_hue, (0xAA,))
knx.assert_state("light.test", STATE_ON, brightness=255, hs_color=(240, 100))
knx.assert_state("light.test", LightState.ON, brightness=255, hs_color=(240, 100))
# change color from HA - only saturation
await hass.services.async_call(
@ -324,7 +325,7 @@ async def test_light_hs_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_sat, (0x80,))
knx.assert_state("light.test", STATE_ON, brightness=255, hs_color=(240, 50))
knx.assert_state("light.test", LightState.ON, brightness=255, hs_color=(240, 50))
# change color from HA - hue and sat
await hass.services.async_call(
@ -335,15 +336,15 @@ async def test_light_hs_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
)
await knx.assert_write(test_hue, (0xEA,))
await knx.assert_write(test_sat, (0x96,))
knx.assert_state("light.test", STATE_ON, brightness=255, hs_color=(330, 59))
knx.assert_state("light.test", LightState.ON, brightness=255, hs_color=(330, 59))
# change color and brightness from KNX
await knx.receive_write(test_brightness, (0xB2,))
knx.assert_state("light.test", STATE_ON, brightness=178, hs_color=(330, 59))
knx.assert_state("light.test", LightState.ON, brightness=178, hs_color=(330, 59))
await knx.receive_write(test_hue, (0x7D,))
knx.assert_state("light.test", STATE_ON, brightness=178, hs_color=(176, 59))
knx.assert_state("light.test", LightState.ON, brightness=178, hs_color=(176, 59))
await knx.receive_write(test_sat, (0xD1,))
knx.assert_state("light.test", STATE_ON, brightness=178, hs_color=(176, 82))
knx.assert_state("light.test", LightState.ON, brightness=178, hs_color=(176, 82))
async def test_light_xyy_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
@ -373,7 +374,7 @@ async def test_light_xyy_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=204,
color_mode=ColorMode.XY,
xy_color=(0.8, 0.8),
@ -386,7 +387,9 @@ async def test_light_xyy_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_xyy, (179, 116, 76, 139, 139, 3))
knx.assert_state("light.test", STATE_ON, brightness=139, xy_color=(0.701, 0.299))
knx.assert_state(
"light.test", LightState.ON, brightness=139, xy_color=(0.701, 0.299)
)
# change brightness from HA
await hass.services.async_call(
@ -396,7 +399,9 @@ async def test_light_xyy_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_xyy, (0, 0, 0, 0, 255, 1))
knx.assert_state("light.test", STATE_ON, brightness=255, xy_color=(0.701, 0.299))
knx.assert_state(
"light.test", LightState.ON, brightness=255, xy_color=(0.701, 0.299)
)
# change color from HA
await hass.services.async_call(
@ -406,17 +411,19 @@ async def test_light_xyy_color(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_xyy, (120, 16, 63, 59, 0, 2))
knx.assert_state("light.test", STATE_ON, brightness=255, xy_color=(0.469, 0.247))
knx.assert_state(
"light.test", LightState.ON, brightness=255, xy_color=(0.469, 0.247)
)
# change color and brightness from KNX
await knx.receive_write(test_xyy, (0x85, 0x1E, 0x4F, 0x5C, 0x19, 0x03))
knx.assert_state("light.test", STATE_ON, brightness=25, xy_color=(0.52, 0.31))
knx.assert_state("light.test", LightState.ON, brightness=25, xy_color=(0.52, 0.31))
# change brightness from KNX
await knx.receive_write(test_xyy, (0x00, 0x00, 0x00, 0x00, 0x80, 0x01))
knx.assert_state("light.test", STATE_ON, brightness=128, xy_color=(0.52, 0.31))
knx.assert_state("light.test", LightState.ON, brightness=128, xy_color=(0.52, 0.31))
# change color from KNX
await knx.receive_write(test_xyy, (0x2E, 0x14, 0x40, 0x00, 0x00, 0x02))
knx.assert_state("light.test", STATE_ON, brightness=128, xy_color=(0.18, 0.25))
knx.assert_state("light.test", LightState.ON, brightness=128, xy_color=(0.18, 0.25))
async def test_light_xyy_color_with_brightness(
@ -455,7 +462,7 @@ async def test_light_xyy_color_with_brightness(
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=255, # brightness form xyy_color ignored when extra brightness GA is used
color_mode=ColorMode.XY,
xy_color=(0.8, 0.8),
@ -468,7 +475,9 @@ async def test_light_xyy_color_with_brightness(
blocking=True,
)
await knx.assert_write(test_xyy, (179, 116, 76, 139, 0, 2))
knx.assert_state("light.test", STATE_ON, brightness=255, xy_color=(0.701, 0.299))
knx.assert_state(
"light.test", LightState.ON, brightness=255, xy_color=(0.701, 0.299)
)
# change brightness from HA
await hass.services.async_call(
@ -478,7 +487,9 @@ async def test_light_xyy_color_with_brightness(
blocking=True,
)
await knx.assert_write(test_brightness, (0x8B,))
knx.assert_state("light.test", STATE_ON, brightness=139, xy_color=(0.701, 0.299))
knx.assert_state(
"light.test", LightState.ON, brightness=139, xy_color=(0.701, 0.299)
)
# change color and brightness from HA
await hass.services.async_call(
@ -490,13 +501,15 @@ async def test_light_xyy_color_with_brightness(
await knx.assert_write(test_xyy, (120, 16, 63, 59, 255, 3))
# brightness relies on brightness_state GA
await knx.receive_write(test_brightness_state, (255,))
knx.assert_state("light.test", STATE_ON, brightness=255, xy_color=(0.469, 0.247))
knx.assert_state(
"light.test", LightState.ON, brightness=255, xy_color=(0.469, 0.247)
)
# change color and brightness from KNX
await knx.receive_write(test_xyy, (0x85, 0x1E, 0x4F, 0x5C, 0x00, 0x02))
knx.assert_state("light.test", STATE_ON, brightness=255, xy_color=(0.52, 0.31))
knx.assert_state("light.test", LightState.ON, brightness=255, xy_color=(0.52, 0.31))
await knx.receive_write(test_brightness, (21,))
knx.assert_state("light.test", STATE_ON, brightness=21, xy_color=(0.52, 0.31))
knx.assert_state("light.test", LightState.ON, brightness=21, xy_color=(0.52, 0.31))
async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> None:
@ -541,7 +554,7 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=255,
color_mode=ColorMode.RGB,
rgb_color=(255, 255, 255),
@ -556,7 +569,7 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
await knx.assert_write(test_red, (255,))
await knx.assert_write(test_green, (0,))
await knx.assert_write(test_blue, (0,))
knx.assert_state("light.test", STATE_ON, brightness=255, rgb_color=(255, 0, 0))
knx.assert_state("light.test", LightState.ON, brightness=255, rgb_color=(255, 0, 0))
# change brightness from HA
await hass.services.async_call(
@ -568,7 +581,7 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
await knx.assert_write(test_red, (200,))
await knx.assert_write(test_green, (0,))
await knx.assert_write(test_blue, (0,))
knx.assert_state("light.test", STATE_ON, brightness=200, rgb_color=(255, 0, 0))
knx.assert_state("light.test", LightState.ON, brightness=200, rgb_color=(255, 0, 0))
# change only color, keep brightness from HA
await hass.services.async_call(
@ -580,7 +593,9 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
await knx.assert_write(test_red, (200,))
await knx.assert_write(test_green, (82,))
await knx.assert_write(test_blue, (141,))
knx.assert_state("light.test", STATE_ON, brightness=200, rgb_color=(255, 105, 180))
knx.assert_state(
"light.test", LightState.ON, brightness=200, rgb_color=(255, 105, 180)
)
# change color and brightness from HA
await hass.services.async_call(
@ -592,18 +607,20 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
await knx.assert_write(test_red, (100,))
await knx.assert_write(test_green, (100,))
await knx.assert_write(test_blue, (0,))
knx.assert_state("light.test", STATE_ON, brightness=100, rgb_color=(255, 255, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=100, rgb_color=(255, 255, 0)
)
# turn OFF from KNX
await knx.receive_write(test_red, (0,))
await knx.receive_write(test_green, (0,))
await knx.receive_write(test_blue, (0,))
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# turn ON from KNX
await knx.receive_write(test_red, (0,))
await knx.receive_write(test_green, (180,))
await knx.receive_write(test_blue, (0,))
knx.assert_state("light.test", STATE_ON, brightness=180, rgb_color=(0, 255, 0))
knx.assert_state("light.test", LightState.ON, brightness=180, rgb_color=(0, 255, 0))
# turn OFF from HA
await hass.services.async_call(
@ -615,7 +632,7 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
await knx.assert_write(test_red, (0,))
await knx.assert_write(test_green, (0,))
await knx.assert_write(test_blue, (0,))
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# turn ON from HA
await hass.services.async_call(
@ -628,7 +645,9 @@ async def test_light_rgb_individual(hass: HomeAssistant, knx: KNXTestKit) -> Non
await knx.assert_write(test_red, (255,))
await knx.assert_write(test_green, (255,))
await knx.assert_write(test_blue, (255,))
knx.assert_state("light.test", STATE_ON, brightness=255, rgb_color=(255, 255, 255))
knx.assert_state(
"light.test", LightState.ON, brightness=255, rgb_color=(255, 255, 255)
)
# turn ON with brightness only from HA - defaults to white
await knx.receive_write(test_red, (0,))
@ -697,7 +716,7 @@ async def test_light_rgbw_individual(
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=255,
color_mode=ColorMode.RGBW,
rgbw_color=(0, 0, 0, 255),
@ -713,7 +732,9 @@ async def test_light_rgbw_individual(
await knx.assert_write(test_green, (0,))
await knx.assert_write(test_blue, (0,))
await knx.assert_write(test_white, (0,))
knx.assert_state("light.test", STATE_ON, brightness=255, rgbw_color=(255, 0, 0, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=255, rgbw_color=(255, 0, 0, 0)
)
# change brightness from HA
await hass.services.async_call(
@ -726,7 +747,9 @@ async def test_light_rgbw_individual(
await knx.assert_write(test_green, (0,))
await knx.assert_write(test_blue, (0,))
await knx.assert_write(test_white, (0,))
knx.assert_state("light.test", STATE_ON, brightness=200, rgbw_color=(255, 0, 0, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=200, rgbw_color=(255, 0, 0, 0)
)
# change only color, keep brightness from HA
await hass.services.async_call(
@ -741,7 +764,7 @@ async def test_light_rgbw_individual(
await knx.assert_write(test_white, (139,))
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=200,
rgb_color=(255, 104, 179), # minor rounding error - expected (255, 105, 180)
rgbw_color=(255, 0, 127, 177), # expected (255, 0, 128, 178)
@ -759,24 +782,26 @@ async def test_light_rgbw_individual(
await knx.assert_write(test_blue, (0,))
await knx.assert_write(test_white, (0,))
knx.assert_state(
"light.test", STATE_ON, brightness=100, rgbw_color=(255, 255, 0, 0)
"light.test", LightState.ON, brightness=100, rgbw_color=(255, 255, 0, 0)
)
# turn OFF from KNX
await knx.receive_write(test_red, (0,))
await knx.receive_write(test_green, (0,))
# # individual color debounce takes 0.2 seconds if not all 4 addresses received
knx.assert_state("light.test", STATE_ON)
knx.assert_state("light.test", LightState.ON)
freezer.tick(timedelta(seconds=XknxLight.DEBOUNCE_TIMEOUT))
async_fire_time_changed(hass)
await knx.xknx.task_registry.block_till_done()
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# turn ON from KNX
await knx.receive_write(test_red, (0,))
await knx.receive_write(test_green, (180,))
await knx.receive_write(test_blue, (0,))
await knx.receive_write(test_white, (0,))
knx.assert_state("light.test", STATE_ON, brightness=180, rgbw_color=(0, 255, 0, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=180, rgbw_color=(0, 255, 0, 0)
)
# turn OFF from HA
await hass.services.async_call(
@ -789,7 +814,7 @@ async def test_light_rgbw_individual(
await knx.assert_write(test_green, (0,))
await knx.assert_write(test_blue, (0,))
await knx.assert_write(test_white, (0,))
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# turn ON from HA
await hass.services.async_call(
@ -804,7 +829,7 @@ async def test_light_rgbw_individual(
await knx.assert_write(test_blue, (255,))
await knx.assert_write(test_white, (255,))
knx.assert_state(
"light.test", STATE_ON, brightness=255, rgbw_color=(255, 255, 255, 255)
"light.test", LightState.ON, brightness=255, rgbw_color=(255, 255, 255, 255)
)
# turn ON with brightness only from HA - defaults to white
@ -851,7 +876,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=255,
color_mode=ColorMode.RGB,
rgb_color=(255, 255, 255),
@ -864,7 +889,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_rgb, (255, 0, 0))
knx.assert_state("light.test", STATE_ON, brightness=255, rgb_color=(255, 0, 0))
knx.assert_state("light.test", LightState.ON, brightness=255, rgb_color=(255, 0, 0))
# change brightness from HA
await hass.services.async_call(
@ -874,7 +899,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_rgb, (200, 0, 0))
knx.assert_state("light.test", STATE_ON, brightness=200, rgb_color=(255, 0, 0))
knx.assert_state("light.test", LightState.ON, brightness=200, rgb_color=(255, 0, 0))
# change color, keep brightness from HA
await hass.services.async_call(
@ -886,7 +911,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
await knx.assert_write(test_rgb, (200, 82, 141))
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=200,
rgb_color=(255, 105, 180),
)
@ -898,17 +923,19 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_rgb, (100, 100, 0))
knx.assert_state("light.test", STATE_ON, brightness=100, rgb_color=(255, 255, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=100, rgb_color=(255, 255, 0)
)
# turn OFF from KNX
await knx.receive_write(test_address_state, False)
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# receive color update from KNX - still OFF
await knx.receive_write(test_rgb, (0, 180, 0))
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# turn ON from KNX - include color update
await knx.receive_write(test_address_state, True)
knx.assert_state("light.test", STATE_ON, brightness=180, rgb_color=(0, 255, 0))
knx.assert_state("light.test", LightState.ON, brightness=180, rgb_color=(0, 255, 0))
# turn OFF from HA
await hass.services.async_call(
@ -918,7 +945,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_address, False)
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# turn ON from HA
await hass.services.async_call(
@ -929,7 +956,7 @@ async def test_light_rgb(hass: HomeAssistant, knx: KNXTestKit) -> None:
)
# color will be restored in no other state was received
await knx.assert_write(test_address, True)
knx.assert_state("light.test", STATE_ON, brightness=180, rgb_color=(0, 255, 0))
knx.assert_state("light.test", LightState.ON, brightness=180, rgb_color=(0, 255, 0))
async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
@ -959,7 +986,7 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=255,
color_mode=ColorMode.RGBW,
rgbw_color=(255, 101, 102, 103),
@ -972,7 +999,9 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_rgbw, (0xFF, 0x00, 0x00, 0x00, 0x00, 0x0F))
knx.assert_state("light.test", STATE_ON, brightness=255, rgbw_color=(255, 0, 0, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=255, rgbw_color=(255, 0, 0, 0)
)
# change brightness from HA
await hass.services.async_call(
@ -982,7 +1011,9 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_rgbw, (0xC8, 0x00, 0x00, 0x00, 0x00, 0x0F))
knx.assert_state("light.test", STATE_ON, brightness=200, rgbw_color=(255, 0, 0, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=200, rgbw_color=(255, 0, 0, 0)
)
# change color, keep brightness from HA
await hass.services.async_call(
@ -994,7 +1025,7 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
await knx.assert_write(test_rgbw, (200, 0, 100, 139, 0x00, 0x0F))
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=200,
rgb_color=(255, 104, 179), # minor rounding error - expected (255, 105, 180)
rgbw_color=(255, 0, 127, 177), # expected (255, 0, 128, 178)
@ -1008,18 +1039,20 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
)
await knx.assert_write(test_rgbw, (100, 100, 0, 0, 0x00, 0x0F))
knx.assert_state(
"light.test", STATE_ON, brightness=100, rgbw_color=(255, 255, 0, 0)
"light.test", LightState.ON, brightness=100, rgbw_color=(255, 255, 0, 0)
)
# turn OFF from KNX
await knx.receive_write(test_address_state, False)
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# receive color update from KNX - still OFF
await knx.receive_write(test_rgbw, (0, 180, 0, 0, 0x00, 0x0F))
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# turn ON from KNX - include color update
await knx.receive_write(test_address_state, True)
knx.assert_state("light.test", STATE_ON, brightness=180, rgbw_color=(0, 255, 0, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=180, rgbw_color=(0, 255, 0, 0)
)
# turn OFF from HA
await hass.services.async_call(
@ -1029,7 +1062,7 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
blocking=True,
)
await knx.assert_write(test_address, False)
knx.assert_state("light.test", STATE_OFF)
knx.assert_state("light.test", LightState.OFF)
# turn ON from HA
await hass.services.async_call(
@ -1040,7 +1073,9 @@ async def test_light_rgbw(hass: HomeAssistant, knx: KNXTestKit) -> None:
)
# color will be restored if no other state was received
await knx.assert_write(test_address, True)
knx.assert_state("light.test", STATE_ON, brightness=180, rgbw_color=(0, 255, 0, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=180, rgbw_color=(0, 255, 0, 0)
)
async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> None:
@ -1076,7 +1111,7 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=255,
color_mode=ColorMode.RGBW,
rgbw_color=(255, 101, 102, 103),
@ -1089,10 +1124,14 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
blocking=True,
)
await knx.assert_write(test_rgbw, (0xFF, 0x00, 0x00, 0x00, 0x00, 0x0F))
knx.assert_state("light.test", STATE_ON, brightness=255, rgbw_color=(255, 0, 0, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=255, rgbw_color=(255, 0, 0, 0)
)
# # update from dedicated brightness state
await knx.receive_write(test_brightness_state, (0xF0,))
knx.assert_state("light.test", STATE_ON, brightness=240, rgbw_color=(255, 0, 0, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=240, rgbw_color=(255, 0, 0, 0)
)
# single encoded brightness - at least one primary color = 255
# # change brightness from HA
@ -1103,7 +1142,9 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
blocking=True,
)
await knx.assert_write(test_brightness, (128,))
knx.assert_state("light.test", STATE_ON, brightness=128, rgbw_color=(255, 0, 0, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=128, rgbw_color=(255, 0, 0, 0)
)
# # change color and brightness from HA
await hass.services.async_call(
"light",
@ -1115,7 +1156,7 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
await knx.assert_write(test_brightness, (128,))
knx.assert_state(
"light.test",
STATE_ON,
LightState.ON,
brightness=128,
rgb_color=(255, 105, 180),
rgbw_color=(255, 0, 128, 178),
@ -1125,7 +1166,9 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
# brightness is handled by dedicated brightness address only
# # from dedicated rgbw state
await knx.receive_write(test_rgbw_state, (0xC8, 0x00, 0x00, 0x00, 0x00, 0x0F))
knx.assert_state("light.test", STATE_ON, brightness=128, rgbw_color=(200, 0, 0, 0))
knx.assert_state(
"light.test", LightState.ON, brightness=128, rgbw_color=(200, 0, 0, 0)
)
# # from HA - only color
await hass.services.async_call(
"light",
@ -1135,7 +1178,7 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
)
await knx.assert_write(test_rgbw, (20, 30, 40, 50, 0x00, 0x0F))
knx.assert_state(
"light.test", STATE_ON, brightness=128, rgbw_color=(20, 30, 40, 50)
"light.test", LightState.ON, brightness=128, rgbw_color=(20, 30, 40, 50)
)
# # from HA - brightness and color
await hass.services.async_call(
@ -1151,7 +1194,7 @@ async def test_light_rgbw_brightness(hass: HomeAssistant, knx: KNXTestKit) -> No
await knx.assert_write(test_rgbw, (100, 200, 55, 12, 0x00, 0x0F))
await knx.assert_write(test_brightness, (50,))
knx.assert_state(
"light.test", STATE_ON, brightness=50, rgbw_color=(100, 200, 55, 12)
"light.test", LightState.ON, brightness=50, rgbw_color=(100, 200, 55, 12)
)
@ -1175,7 +1218,7 @@ async def test_light_ui_create(
await knx.assert_read("2/2/2")
await knx.receive_response("2/2/2", True)
state = hass.states.get("light.test")
assert state.state is STATE_ON
assert state.state == LightState.ON
@pytest.mark.parametrize(
@ -1217,7 +1260,7 @@ async def test_light_ui_color_temp(
)
await knx.assert_write("3/3/3", raw_ct)
state = hass.states.get("light.test")
assert state.state is STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == pytest.approx(4200, abs=1)
@ -1235,7 +1278,7 @@ async def test_light_ui_load(
await knx.assert_read("1/0/45", response=True, ignore_order=True)
state = hass.states.get("light.test")
assert state.state is STATE_ON
assert state.state == LightState.ON
entity = entity_registry.async_get("light.test")
assert entity.entity_category is EntityCategory.CONFIG

View file

@ -21,13 +21,12 @@ from homeassistant.components.light import (
ATTR_XY_COLOR,
SCAN_INTERVAL,
ColorMode,
LightState,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_FRIENDLY_NAME,
ATTR_SUPPORTED_FEATURES,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant
@ -70,7 +69,7 @@ async def mock_light(
async def test_init(hass: HomeAssistant, mock_light: MagicMock) -> None:
"""Test platform setup."""
state = hass.states.get("light.bedroom")
assert state.state == STATE_OFF
assert state.state == LightState.OFF
assert dict(state.attributes) == {
ATTR_FRIENDLY_NAME: "Bedroom",
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBW],
@ -198,7 +197,7 @@ async def test_light_update(hass: HomeAssistant, mock_light: MagicMock) -> None:
utcnow = dt_util.utcnow()
state = hass.states.get("light.bedroom")
assert state.state == STATE_OFF
assert state.state == LightState.OFF
assert dict(state.attributes) == {
ATTR_FRIENDLY_NAME: "Bedroom",
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBW],
@ -232,7 +231,7 @@ async def test_light_update(hass: HomeAssistant, mock_light: MagicMock) -> None:
await hass.async_block_till_done()
state = hass.states.get("light.bedroom")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert dict(state.attributes) == {
ATTR_FRIENDLY_NAME: "Bedroom",
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBW],
@ -252,7 +251,7 @@ async def test_light_update(hass: HomeAssistant, mock_light: MagicMock) -> None:
await hass.async_block_till_done()
state = hass.states.get("light.bedroom")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert dict(state.attributes) == {
ATTR_FRIENDLY_NAME: "Bedroom",
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBW],
@ -272,7 +271,7 @@ async def test_light_update(hass: HomeAssistant, mock_light: MagicMock) -> None:
await hass.async_block_till_done()
state = hass.states.get("light.bedroom")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert dict(state.attributes) == {
ATTR_FRIENDLY_NAME: "Bedroom",
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.RGBW],

View file

@ -12,13 +12,12 @@ from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_TRANSITION,
DOMAIN as DOMAIN_LIGHT,
LightState,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
Platform,
)
@ -66,7 +65,7 @@ async def test_output_turn_on(hass: HomeAssistant, entry: MockConfigEntry) -> No
state = hass.states.get(LIGHT_OUTPUT1)
assert state is not None
assert state.state != STATE_ON
assert state.state != LightState.ON
# command success
dim_output.reset_mock(return_value=True)
@ -83,7 +82,7 @@ async def test_output_turn_on(hass: HomeAssistant, entry: MockConfigEntry) -> No
state = hass.states.get(LIGHT_OUTPUT1)
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
async def test_output_turn_on_with_attributes(
@ -110,7 +109,7 @@ async def test_output_turn_on_with_attributes(
state = hass.states.get(LIGHT_OUTPUT1)
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
async def test_output_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> None:
@ -119,7 +118,7 @@ async def test_output_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> N
with patch.object(MockModuleConnection, "dim_output") as dim_output:
state = hass.states.get(LIGHT_OUTPUT1)
state.state = STATE_ON
state.state = LightState.ON
# command failed
dim_output.return_value = False
@ -135,7 +134,7 @@ async def test_output_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> N
state = hass.states.get(LIGHT_OUTPUT1)
assert state is not None
assert state.state != STATE_OFF
assert state.state != LightState.OFF
# command success
dim_output.reset_mock(return_value=True)
@ -152,7 +151,7 @@ async def test_output_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> N
state = hass.states.get(LIGHT_OUTPUT1)
assert state is not None
assert state.state == STATE_OFF
assert state.state == LightState.OFF
async def test_output_turn_off_with_attributes(
@ -165,7 +164,7 @@ async def test_output_turn_off_with_attributes(
dim_output.return_value = True
state = hass.states.get(LIGHT_OUTPUT1)
state.state = STATE_ON
state.state = LightState.ON
await hass.services.async_call(
DOMAIN_LIGHT,
@ -181,7 +180,7 @@ async def test_output_turn_off_with_attributes(
state = hass.states.get(LIGHT_OUTPUT1)
assert state is not None
assert state.state == STATE_OFF
assert state.state == LightState.OFF
async def test_relay_turn_on(hass: HomeAssistant, entry: MockConfigEntry) -> None:
@ -206,7 +205,7 @@ async def test_relay_turn_on(hass: HomeAssistant, entry: MockConfigEntry) -> Non
state = hass.states.get(LIGHT_RELAY1)
assert state is not None
assert state.state != STATE_ON
assert state.state != LightState.ON
# command success
control_relays.reset_mock(return_value=True)
@ -223,7 +222,7 @@ async def test_relay_turn_on(hass: HomeAssistant, entry: MockConfigEntry) -> Non
state = hass.states.get(LIGHT_RELAY1)
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
async def test_relay_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> None:
@ -235,7 +234,7 @@ async def test_relay_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> No
states[0] = RelayStateModifier.OFF
state = hass.states.get(LIGHT_RELAY1)
state.state = STATE_ON
state.state = LightState.ON
# command failed
control_relays.return_value = False
@ -251,7 +250,7 @@ async def test_relay_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> No
state = hass.states.get(LIGHT_RELAY1)
assert state is not None
assert state.state != STATE_OFF
assert state.state != LightState.OFF
# command success
control_relays.reset_mock(return_value=True)
@ -268,7 +267,7 @@ async def test_relay_turn_off(hass: HomeAssistant, entry: MockConfigEntry) -> No
state = hass.states.get(LIGHT_RELAY1)
assert state is not None
assert state.state == STATE_OFF
assert state.state == LightState.OFF
async def test_pushed_output_status_change(
@ -287,7 +286,7 @@ async def test_pushed_output_status_change(
state = hass.states.get(LIGHT_OUTPUT1)
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
assert state.attributes[ATTR_BRIGHTNESS] == 127
# push status "off"
@ -297,7 +296,7 @@ async def test_pushed_output_status_change(
state = hass.states.get(LIGHT_OUTPUT1)
assert state is not None
assert state.state == STATE_OFF
assert state.state == LightState.OFF
async def test_pushed_relay_status_change(
@ -318,7 +317,7 @@ async def test_pushed_relay_status_change(
state = hass.states.get(LIGHT_RELAY1)
assert state is not None
assert state.state == STATE_ON
assert state.state == LightState.ON
# push status "off"
states[0] = False
@ -328,7 +327,7 @@ async def test_pushed_relay_status_change(
state = hass.states.get(LIGHT_RELAY1)
assert state is not None
assert state.state == STATE_OFF
assert state.state == LightState.OFF
async def test_unload_config_entry(hass: HomeAssistant, entry: MockConfigEntry) -> None:

View file

@ -43,14 +43,9 @@ from homeassistant.components.light import (
DOMAIN as LIGHT_DOMAIN,
SERVICE_TURN_ON,
ColorMode,
LightState,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
CONF_HOST,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import device_registry as dr, entity_registry as er
@ -732,7 +727,7 @@ async def test_matrix_flame_morph_effects(hass: HomeAssistant) -> None:
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert len(bulb.set_power.calls) == 1
assert len(bulb.set_tile_effect.calls) == 1
@ -791,7 +786,7 @@ async def test_matrix_flame_morph_effects(hass: HomeAssistant) -> None:
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert len(bulb.set_power.calls) == 1
assert len(bulb.set_tile_effect.calls) == 1
@ -864,7 +859,7 @@ async def test_sky_effect(hass: HomeAssistant) -> None:
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert len(bulb.set_power.calls) == 1
assert len(bulb.set_tile_effect.calls) == 1
@ -922,7 +917,7 @@ async def test_sky_effect(hass: HomeAssistant) -> None:
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert len(bulb.set_power.calls) == 1
assert len(bulb.set_tile_effect.calls) == 1
@ -1010,7 +1005,7 @@ async def test_lightstrip_move_effect(hass: HomeAssistant) -> None:
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON
assert len(bulb.set_power.calls) == 1
assert len(bulb.set_extended_color_zones.calls) == 1
@ -1308,7 +1303,7 @@ async def test_config_zoned_light_strip_fails(
await async_setup_component(hass, lifx.DOMAIN, {lifx.DOMAIN: {}})
await hass.async_block_till_done()
assert entity_registry.async_get(entity_id).unique_id == SERIAL
assert hass.states.get(entity_id).state == STATE_OFF
assert hass.states.get(entity_id).state == LightState.OFF
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=30))
await hass.async_block_till_done(wait_background_tasks=True)
@ -1356,14 +1351,14 @@ async def test_legacy_zoned_light_strip(
await async_setup_component(hass, lifx.DOMAIN, {lifx.DOMAIN: {}})
await hass.async_block_till_done()
assert entity_registry.async_get(entity_id).unique_id == SERIAL
assert hass.states.get(entity_id).state == STATE_OFF
assert hass.states.get(entity_id).state == LightState.OFF
# 1 to get the number of zones
# 2 get populate the zones
assert get_color_zones_mock.call_count == 3
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=30))
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == STATE_OFF
assert hass.states.get(entity_id).state == LightState.OFF
# 2 get populate the zones
assert get_color_zones_mock.call_count == 5
@ -1385,7 +1380,7 @@ async def test_white_light_fails(
await async_setup_component(hass, lifx.DOMAIN, {lifx.DOMAIN: {}})
await hass.async_block_till_done()
assert entity_registry.async_get(entity_id).unique_id == SERIAL
assert hass.states.get(entity_id).state == STATE_OFF
assert hass.states.get(entity_id).state == LightState.OFF
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
LIGHT_DOMAIN, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
@ -2013,4 +2008,4 @@ async def test_light_strip_zones_not_populated_yet(hass: HomeAssistant) -> None:
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=30))
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON

View file

@ -8,8 +8,8 @@ from pytest_unordered import unordered
from homeassistant.components import automation
from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.light import DOMAIN
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON, EntityCategory
from homeassistant.components.light import DOMAIN, LightState
from homeassistant.const import CONF_PLATFORM, EntityCategory
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.entity_registry import RegistryEntryHider
@ -192,7 +192,7 @@ async def test_if_state(
DOMAIN, "test", "5678", device_id=device_entry.id
)
hass.states.async_set(entry.entity_id, STATE_ON)
hass.states.async_set(entry.entity_id, LightState.ON)
assert await async_setup_component(
hass,
@ -253,7 +253,7 @@ async def test_if_state(
assert len(service_calls) == 1
assert service_calls[0].data["some"] == "is_on event - test_event1"
hass.states.async_set(entry.entity_id, STATE_OFF)
hass.states.async_set(entry.entity_id, LightState.OFF)
hass.bus.async_fire("test_event1")
hass.bus.async_fire("test_event2")
await hass.async_block_till_done()
@ -279,7 +279,7 @@ async def test_if_state_legacy(
DOMAIN, "test", "5678", device_id=device_entry.id
)
hass.states.async_set(entry.entity_id, STATE_ON)
hass.states.async_set(entry.entity_id, LightState.ON)
assert await async_setup_component(
hass,
@ -338,7 +338,7 @@ async def test_if_fires_on_for_condition(
DOMAIN, "test", "5678", device_id=device_entry.id
)
hass.states.async_set(entry.entity_id, STATE_ON)
hass.states.async_set(entry.entity_id, LightState.ON)
point1 = dt_util.utcnow()
point2 = point1 + timedelta(seconds=10)
@ -390,7 +390,7 @@ async def test_if_fires_on_for_condition(
await hass.async_block_till_done()
assert len(service_calls) == 0
hass.states.async_set(entry.entity_id, STATE_OFF)
hass.states.async_set(entry.entity_id, LightState.OFF)
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(service_calls) == 0

View file

@ -7,8 +7,8 @@ from pytest_unordered import unordered
from homeassistant.components import automation
from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.light import DOMAIN
from homeassistant.const import STATE_OFF, STATE_ON, EntityCategory
from homeassistant.components.light import DOMAIN, LightState
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.entity_registry import RegistryEntryHider
@ -195,7 +195,7 @@ async def test_if_fires_on_state_change(
DOMAIN, "test", "5678", device_id=device_entry.id
)
hass.states.async_set(entry.entity_id, STATE_ON)
hass.states.async_set(entry.entity_id, LightState.ON)
assert await async_setup_component(
hass,
@ -253,7 +253,7 @@ async def test_if_fires_on_state_change(
await hass.async_block_till_done()
assert len(service_calls) == 0
hass.states.async_set(entry.entity_id, STATE_OFF)
hass.states.async_set(entry.entity_id, LightState.OFF)
await hass.async_block_till_done()
assert len(service_calls) == 2
assert {service_calls[0].data["some"], service_calls[1].data["some"]} == {
@ -261,7 +261,7 @@ async def test_if_fires_on_state_change(
f"turn_on_or_off device - {entry.entity_id} - on - off - None",
}
hass.states.async_set(entry.entity_id, STATE_ON)
hass.states.async_set(entry.entity_id, LightState.ON)
await hass.async_block_till_done()
assert len(service_calls) == 4
assert {service_calls[2].data["some"], service_calls[3].data["some"]} == {
@ -288,7 +288,7 @@ async def test_if_fires_on_state_change_legacy(
DOMAIN, "test", "5678", device_id=device_entry.id
)
hass.states.async_set(entry.entity_id, STATE_ON)
hass.states.async_set(entry.entity_id, LightState.ON)
assert await async_setup_component(
hass,
@ -316,7 +316,7 @@ async def test_if_fires_on_state_change_legacy(
await hass.async_block_till_done()
assert len(service_calls) == 0
hass.states.async_set(entry.entity_id, STATE_OFF)
hass.states.async_set(entry.entity_id, LightState.OFF)
await hass.async_block_till_done()
assert len(service_calls) == 1
assert (
@ -343,7 +343,7 @@ async def test_if_fires_on_state_change_with_for(
DOMAIN, "test", "5678", device_id=device_entry.id
)
hass.states.async_set(entry.entity_id, STATE_ON)
hass.states.async_set(entry.entity_id, LightState.ON)
assert await async_setup_component(
hass,
@ -372,7 +372,7 @@ async def test_if_fires_on_state_change_with_for(
await hass.async_block_till_done()
assert len(service_calls) == 0
hass.states.async_set(entry.entity_id, STATE_OFF)
hass.states.async_set(entry.entity_id, LightState.OFF)
await hass.async_block_till_done()
assert len(service_calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))

View file

@ -1,5 +1,6 @@
"""The tests for the Light component."""
from types import ModuleType
from typing import Literal
from unittest.mock import MagicMock, mock_open, patch
@ -15,8 +16,6 @@ from homeassistant.const import (
SERVICE_TOGGLE,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError, Unauthorized
@ -29,6 +28,8 @@ from tests.common import (
MockEntityPlatform,
MockUser,
async_mock_service,
help_test_all,
import_and_test_deprecated_constant_enum,
setup_test_component_platform,
)
@ -38,10 +39,10 @@ orig_Profiles = light.Profiles
async def test_methods(hass: HomeAssistant) -> None:
"""Test if methods call the services as expected."""
# Test is_on
hass.states.async_set("light.test", STATE_ON)
hass.states.async_set("light.test", light.LightState.ON)
assert light.is_on(hass, "light.test")
hass.states.async_set("light.test", STATE_OFF)
hass.states.async_set("light.test", light.LightState.OFF)
assert not light.is_on(hass, "light.test")
# Test turn_on
@ -914,8 +915,8 @@ async def test_light_turn_on_auth(
async def test_light_brightness_step(hass: HomeAssistant) -> None:
"""Test that light context works."""
entities = [
MockLight("Test_0", STATE_ON),
MockLight("Test_1", STATE_ON),
MockLight("Test_0", light.LightState.ON),
MockLight("Test_1", light.LightState.ON),
]
setup_test_component_platform(hass, light.DOMAIN, entities)
@ -1143,7 +1144,7 @@ invalid_no_brightness_no_color_no_transition,,,
assert invalid_profile_name not in profiles.data
@pytest.mark.parametrize("light_state", [STATE_ON, STATE_OFF])
@pytest.mark.parametrize("light_state", [light.LightState.ON, light.LightState.OFF])
async def test_light_backwards_compatibility_supported_color_modes(
hass: HomeAssistant, light_state: Literal["on", "off"]
) -> None:
@ -1191,28 +1192,28 @@ async def test_light_backwards_compatibility_supported_color_modes(
state = hass.states.get(entity0.entity_id)
assert state.attributes["supported_color_modes"] == [light.ColorMode.ONOFF]
if light_state == STATE_OFF:
if light_state == light.LightState.OFF:
assert state.attributes["color_mode"] is None
else:
assert state.attributes["color_mode"] == light.ColorMode.ONOFF
state = hass.states.get(entity1.entity_id)
assert state.attributes["supported_color_modes"] == [light.ColorMode.BRIGHTNESS]
if light_state == STATE_OFF:
if light_state == light.LightState.OFF:
assert state.attributes["color_mode"] is None
else:
assert state.attributes["color_mode"] == light.ColorMode.UNKNOWN
state = hass.states.get(entity2.entity_id)
assert state.attributes["supported_color_modes"] == [light.ColorMode.COLOR_TEMP]
if light_state == STATE_OFF:
if light_state == light.LightState.OFF:
assert state.attributes["color_mode"] is None
else:
assert state.attributes["color_mode"] == light.ColorMode.UNKNOWN
state = hass.states.get(entity3.entity_id)
assert state.attributes["supported_color_modes"] == [light.ColorMode.HS]
if light_state == STATE_OFF:
if light_state == light.LightState.OFF:
assert state.attributes["color_mode"] is None
else:
assert state.attributes["color_mode"] == light.ColorMode.UNKNOWN
@ -1222,7 +1223,7 @@ async def test_light_backwards_compatibility_supported_color_modes(
light.ColorMode.COLOR_TEMP,
light.ColorMode.HS,
]
if light_state == STATE_OFF:
if light_state == light.LightState.OFF:
assert state.attributes["color_mode"] is None
else:
assert state.attributes["color_mode"] == light.ColorMode.UNKNOWN
@ -1231,11 +1232,11 @@ async def test_light_backwards_compatibility_supported_color_modes(
async def test_light_backwards_compatibility_color_mode(hass: HomeAssistant) -> None:
"""Test color_mode if not implemented by the entity."""
entities = [
MockLight("Test_0", STATE_ON),
MockLight("Test_1", STATE_ON),
MockLight("Test_2", STATE_ON),
MockLight("Test_3", STATE_ON),
MockLight("Test_4", STATE_ON),
MockLight("Test_0", light.LightState.ON),
MockLight("Test_1", light.LightState.ON),
MockLight("Test_2", light.LightState.ON),
MockLight("Test_3", light.LightState.ON),
MockLight("Test_4", light.LightState.ON),
]
entity0 = entities[0]
@ -1306,7 +1307,7 @@ async def test_light_backwards_compatibility_color_mode(hass: HomeAssistant) ->
async def test_light_service_call_rgbw(hass: HomeAssistant) -> None:
"""Test rgbw functionality in service calls."""
entity0 = MockLight("Test_rgbw", STATE_ON)
entity0 = MockLight("Test_rgbw", light.LightState.ON)
entity0.supported_color_modes = {light.ColorMode.RGBW}
setup_test_component_platform(hass, light.DOMAIN, [entity0])
@ -1335,10 +1336,10 @@ async def test_light_service_call_rgbw(hass: HomeAssistant) -> None:
async def test_light_state_off(hass: HomeAssistant) -> None:
"""Test rgbw color conversion in state updates."""
entities = [
MockLight("Test_onoff", STATE_OFF),
MockLight("Test_brightness", STATE_OFF),
MockLight("Test_ct", STATE_OFF),
MockLight("Test_rgbw", STATE_OFF),
MockLight("Test_onoff", light.LightState.OFF),
MockLight("Test_brightness", light.LightState.OFF),
MockLight("Test_ct", light.LightState.OFF),
MockLight("Test_rgbw", light.LightState.OFF),
]
setup_test_component_platform(hass, light.DOMAIN, entities)
@ -1405,7 +1406,7 @@ async def test_light_state_off(hass: HomeAssistant) -> None:
async def test_light_state_rgbw(hass: HomeAssistant) -> None:
"""Test rgbw color conversion in state updates."""
entity0 = MockLight("Test_rgbw", STATE_ON)
entity0 = MockLight("Test_rgbw", light.LightState.ON)
setup_test_component_platform(hass, light.DOMAIN, [entity0])
entity0.brightness = 255
@ -1436,7 +1437,7 @@ async def test_light_state_rgbw(hass: HomeAssistant) -> None:
async def test_light_state_rgbww(hass: HomeAssistant) -> None:
"""Test rgbww color conversion in state updates."""
entity0 = MockLight("Test_rgbww", STATE_ON)
entity0 = MockLight("Test_rgbww", light.LightState.ON)
setup_test_component_platform(hass, light.DOMAIN, [entity0])
entity0.supported_color_modes = {light.ColorMode.RGBWW}
@ -1468,14 +1469,14 @@ async def test_light_state_rgbww(hass: HomeAssistant) -> None:
async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None:
"""Test color conversion in service calls."""
entities = [
MockLight("Test_hs", STATE_ON),
MockLight("Test_rgb", STATE_ON),
MockLight("Test_xy", STATE_ON),
MockLight("Test_all", STATE_ON),
MockLight("Test_legacy", STATE_ON),
MockLight("Test_rgbw", STATE_ON),
MockLight("Test_rgbww", STATE_ON),
MockLight("Test_temperature", STATE_ON),
MockLight("Test_hs", light.LightState.ON),
MockLight("Test_rgb", light.LightState.ON),
MockLight("Test_xy", light.LightState.ON),
MockLight("Test_all", light.LightState.ON),
MockLight("Test_legacy", light.LightState.ON),
MockLight("Test_rgbw", light.LightState.ON),
MockLight("Test_rgbww", light.LightState.ON),
MockLight("Test_temperature", light.LightState.ON),
]
setup_test_component_platform(hass, light.DOMAIN, entities)
@ -1913,13 +1914,13 @@ async def test_light_service_call_color_conversion_named_tuple(
) -> None:
"""Test a named tuple (RGBColor) is handled correctly."""
entities = [
MockLight("Test_hs", STATE_ON),
MockLight("Test_rgb", STATE_ON),
MockLight("Test_xy", STATE_ON),
MockLight("Test_all", STATE_ON),
MockLight("Test_legacy", STATE_ON),
MockLight("Test_rgbw", STATE_ON),
MockLight("Test_rgbww", STATE_ON),
MockLight("Test_hs", light.LightState.ON),
MockLight("Test_rgb", light.LightState.ON),
MockLight("Test_xy", light.LightState.ON),
MockLight("Test_all", light.LightState.ON),
MockLight("Test_legacy", light.LightState.ON),
MockLight("Test_rgbw", light.LightState.ON),
MockLight("Test_rgbww", light.LightState.ON),
]
setup_test_component_platform(hass, light.DOMAIN, entities)
@ -1991,9 +1992,9 @@ async def test_light_service_call_color_conversion_named_tuple(
async def test_light_service_call_color_temp_emulation(hass: HomeAssistant) -> None:
"""Test color conversion in service calls."""
entities = [
MockLight("Test_hs_ct", STATE_ON),
MockLight("Test_hs", STATE_ON),
MockLight("Test_hs_white", STATE_ON),
MockLight("Test_hs_ct", light.LightState.ON),
MockLight("Test_hs", light.LightState.ON),
MockLight("Test_hs_white", light.LightState.ON),
]
setup_test_component_platform(hass, light.DOMAIN, entities)
@ -2049,8 +2050,8 @@ async def test_light_service_call_color_temp_emulation(hass: HomeAssistant) -> N
async def test_light_service_call_color_temp_conversion(hass: HomeAssistant) -> None:
"""Test color temp conversion in service calls."""
entities = [
MockLight("Test_rgbww_ct", STATE_ON),
MockLight("Test_rgbww", STATE_ON),
MockLight("Test_rgbww_ct", light.LightState.ON),
MockLight("Test_rgbww", light.LightState.ON),
]
setup_test_component_platform(hass, light.DOMAIN, entities)
@ -2180,8 +2181,8 @@ async def test_light_service_call_color_temp_conversion(hass: HomeAssistant) ->
async def test_light_mired_color_temp_conversion(hass: HomeAssistant) -> None:
"""Test color temp conversion from K to legacy mired."""
entities = [
MockLight("Test_rgbww_ct", STATE_ON),
MockLight("Test_rgbww", STATE_ON),
MockLight("Test_rgbww_ct", light.LightState.ON),
MockLight("Test_rgbww", light.LightState.ON),
]
setup_test_component_platform(hass, light.DOMAIN, entities)
@ -2225,7 +2226,7 @@ async def test_light_mired_color_temp_conversion(hass: HomeAssistant) -> None:
async def test_light_service_call_white_mode(hass: HomeAssistant) -> None:
"""Test color_mode white in service calls."""
entity0 = MockLight("Test_white", STATE_ON)
entity0 = MockLight("Test_white", light.LightState.ON)
entity0.supported_color_modes = {light.ColorMode.HS, light.ColorMode.WHITE}
setup_test_component_platform(hass, light.DOMAIN, [entity0])
@ -2325,10 +2326,10 @@ async def test_light_service_call_white_mode(hass: HomeAssistant) -> None:
async def test_light_state_color_conversion(hass: HomeAssistant) -> None:
"""Test color conversion in state updates."""
entities = [
MockLight("Test_hs", STATE_ON),
MockLight("Test_rgb", STATE_ON),
MockLight("Test_xy", STATE_ON),
MockLight("Test_legacy", STATE_ON),
MockLight("Test_hs", light.LightState.ON),
MockLight("Test_rgb", light.LightState.ON),
MockLight("Test_xy", light.LightState.ON),
MockLight("Test_legacy", light.LightState.ON),
]
setup_test_component_platform(hass, light.DOMAIN, entities)
@ -2802,3 +2803,46 @@ def test_report_invalid_color_modes(
entity._async_calculate_state()
expected_warning = "sets invalid supported color modes"
assert (expected_warning in caplog.text) is warning_expected
@pytest.mark.parametrize(
"module",
[light],
)
def test_all(module: ModuleType) -> None:
"""Test module.__all__ is correctly set."""
help_test_all(module)
@pytest.mark.parametrize(
"enum",
[light.LightState.ON],
)
@pytest.mark.parametrize(
"module",
[light],
)
def test_deprecated_stream_type_constants(
caplog: pytest.LogCaptureFixture,
enum: light.LightState,
module: ModuleType,
) -> None:
"""Test deprecated stream type constants."""
import_and_test_deprecated_constant_enum(caplog, module, enum, "STATE_", "2025.11")
@pytest.mark.parametrize(
"enum",
[light.LightState.ON],
)
@pytest.mark.parametrize(
"module",
[light],
)
def test_deprecated_state_constants(
caplog: pytest.LogCaptureFixture,
enum: light.LightState,
module: ModuleType,
) -> None:
"""Test deprecated stream type constants."""
import_and_test_deprecated_constant_enum(caplog, module, enum, "STATE_", "2025.11")

View file

@ -10,15 +10,10 @@ from homeassistant.components.light import (
DOMAIN as LIGHT_DOMAIN,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
LightState,
)
from homeassistant.components.linear_garage_door import DOMAIN
from homeassistant.const import (
ATTR_ENTITY_ID,
CONF_BRIGHTNESS,
STATE_OFF,
STATE_ON,
Platform,
)
from homeassistant.const import ATTR_ENTITY_ID, CONF_BRIGHTNESS, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
@ -109,8 +104,8 @@ async def test_update_light_state(
await setup_integration(hass, mock_config_entry, [Platform.LIGHT])
assert hass.states.get("light.test_garage_1_light").state == STATE_ON
assert hass.states.get("light.test_garage_2_light").state == STATE_OFF
assert hass.states.get("light.test_garage_1_light").state == LightState.ON
assert hass.states.get("light.test_garage_2_light").state == LightState.OFF
device_states = load_json_object_fixture("get_device_state_1.json", DOMAIN)
mock_linear.get_device_state.side_effect = lambda device_id: device_states[
@ -120,5 +115,5 @@ async def test_update_light_state(
freezer.tick(timedelta(seconds=60))
async_fire_time_changed(hass)
assert hass.states.get("light.test_garage_1_light").state == STATE_OFF
assert hass.states.get("light.test_garage_2_light").state == STATE_ON
assert hass.states.get("light.test_garage_1_light").state == LightState.OFF
assert hass.states.get("light.test_garage_2_light").state == LightState.ON

View file

@ -1,6 +1,6 @@
"""Tests for the Lutron Caseta integration."""
from homeassistant.const import STATE_ON
from homeassistant.components.light import LightState
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
@ -23,4 +23,4 @@ async def test_light_unique_id(
assert entity_registry.async_get(caseta_entity_id).unique_id == "5442321"
state = hass.states.get(ra3_entity_id)
assert state.state == STATE_ON
assert state.state == LightState.ON

View file

@ -3,7 +3,7 @@
from pymodbus.exceptions import ModbusException
import pytest
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN, LightState
from homeassistant.components.modbus.const import (
CALL_TYPE_COIL,
CALL_TYPE_DISCRETE,
@ -25,8 +25,6 @@ from homeassistant.const import (
CONF_NAME,
CONF_SCAN_INTERVAL,
CONF_SLAVE,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant, State
@ -177,19 +175,19 @@ async def test_config_light(hass: HomeAssistant, mock_modbus) -> None:
[0x00],
False,
{CONF_VERIFY: {}},
STATE_OFF,
LightState.OFF,
),
(
[0x01],
False,
{CONF_VERIFY: {}},
STATE_ON,
LightState.ON,
),
(
[0xFE],
False,
{CONF_VERIFY: {}},
STATE_OFF,
LightState.OFF,
),
(
[0x00],
@ -201,7 +199,7 @@ async def test_config_light(hass: HomeAssistant, mock_modbus) -> None:
[0x00],
True,
None,
STATE_OFF,
LightState.OFF,
),
],
)
@ -212,7 +210,7 @@ async def test_all_light(hass: HomeAssistant, mock_do_cycle, expected) -> None:
@pytest.mark.parametrize(
"mock_test_state",
[(State(ENTITY_ID, STATE_ON),)],
[(State(ENTITY_ID, LightState.ON),)],
indirect=True,
)
@pytest.mark.parametrize(
@ -267,31 +265,31 @@ async def test_light_service_turn(
assert MODBUS_DOMAIN in hass.config.components
assert hass.states.get(ENTITY_ID).state == STATE_OFF
assert hass.states.get(ENTITY_ID).state == LightState.OFF
await hass.services.async_call(
"light", "turn_on", service_data={"entity_id": ENTITY_ID}
)
await hass.async_block_till_done()
assert hass.states.get(ENTITY_ID).state == STATE_ON
assert hass.states.get(ENTITY_ID).state == LightState.ON
await hass.services.async_call(
"light", "turn_off", service_data={"entity_id": ENTITY_ID}
)
await hass.async_block_till_done()
assert hass.states.get(ENTITY_ID).state == STATE_OFF
assert hass.states.get(ENTITY_ID).state == LightState.OFF
mock_modbus.read_holding_registers.return_value = ReadResult([0x01])
assert hass.states.get(ENTITY_ID2).state == STATE_OFF
assert hass.states.get(ENTITY_ID2).state == LightState.OFF
await hass.services.async_call(
"light", "turn_on", service_data={"entity_id": ENTITY_ID2}
)
await hass.async_block_till_done()
assert hass.states.get(ENTITY_ID2).state == STATE_ON
assert hass.states.get(ENTITY_ID2).state == LightState.ON
mock_modbus.read_holding_registers.return_value = ReadResult([0x00])
await hass.services.async_call(
"light", "turn_off", service_data={"entity_id": ENTITY_ID2}
)
await hass.async_block_till_done()
assert hass.states.get(ENTITY_ID2).state == STATE_OFF
assert hass.states.get(ENTITY_ID2).state == LightState.OFF
mock_modbus.write_register.side_effect = ModbusException("fail write_")
await hass.services.async_call(
@ -321,12 +319,12 @@ async def test_service_light_update(hass: HomeAssistant, mock_modbus_ha) -> None
await hass.services.async_call(
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
)
assert hass.states.get(ENTITY_ID).state == STATE_OFF
assert hass.states.get(ENTITY_ID).state == LightState.OFF
mock_modbus_ha.read_coils.return_value = ReadResult([0x01])
await hass.services.async_call(
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
)
assert hass.states.get(ENTITY_ID).state == STATE_ON
assert hass.states.get(ENTITY_ID).state == LightState.ON
async def test_no_discovery_info_light(

View file

@ -5,7 +5,11 @@ from unittest.mock import patch
from aiomodernforms import ModernFormsConnectionError
import pytest
from homeassistant.components.light import ATTR_BRIGHTNESS, DOMAIN as LIGHT_DOMAIN
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
DOMAIN as LIGHT_DOMAIN,
LightState,
)
from homeassistant.components.modern_forms.const import (
ATTR_SLEEP_TIME,
DOMAIN,
@ -17,7 +21,6 @@ from homeassistant.const import (
ATTR_FRIENDLY_NAME,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant
@ -40,7 +43,7 @@ async def test_light_state(
assert state
assert state.attributes.get(ATTR_BRIGHTNESS) == 128
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "ModernFormsFan Light"
assert state.state == STATE_ON
assert state.state == LightState.ON
entry = entity_registry.async_get("light.modernformsfan_light")
assert entry
@ -130,7 +133,7 @@ async def test_light_error(
)
await hass.async_block_till_done()
state = hass.states.get("light.modernformsfan_light")
assert state.state == STATE_ON
assert state.state == LightState.ON
assert "Invalid response from API" in caplog.text

View file

@ -190,7 +190,7 @@ from homeassistant.components.mqtt.light.schema_basic import (
VALUE_TEMPLATE_KEYS,
)
from homeassistant.components.mqtt.models import PublishPayloadType
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON, STATE_UNKNOWN
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_UNKNOWN
from homeassistant.core import HomeAssistant, State
from .test_common import (
@ -282,7 +282,7 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
async_fire_mqtt_message(hass, "test_light_rgb/status", "ON")
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") is None
assert state.attributes.get("brightness") is None
assert state.attributes.get("color_temp") is None
@ -297,7 +297,7 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
async_fire_mqtt_message(hass, "test_light_rgb/status", "OFF")
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
async_fire_mqtt_message(hass, "test_light_rgb/status", "None")
@ -363,7 +363,7 @@ async def test_controlling_state_via_topic(
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") is None
assert state.attributes.get("brightness") is None
assert state.attributes.get("color_temp") is None
@ -378,7 +378,7 @@ async def test_controlling_state_via_topic(
async_fire_mqtt_message(hass, "test_light_rgb/status", "0")
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
async_fire_mqtt_message(hass, "test_light_rgb/brightness/status", "100")
@ -662,7 +662,7 @@ async def test_invalid_state_via_topic(
async_fire_mqtt_message(hass, "test_light_rgb/effect/status", "none")
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (255, 255, 255)
assert state.attributes.get("brightness") == 255
assert state.attributes.get("color_temp") is None
@ -673,7 +673,7 @@ async def test_invalid_state_via_topic(
async_fire_mqtt_message(hass, "test_light_rgb/status", "")
light_state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
async_fire_mqtt_message(hass, "test_light_rgb/brightness/status", "")
light_state = hass.states.get("light.test")
@ -720,7 +720,7 @@ async def test_invalid_state_via_topic(
async_fire_mqtt_message(hass, "test_light_rgb/color_mode/status", "color_temp")
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (255, 254, 250)
assert state.attributes.get("brightness") == 255
assert state.attributes.get("color_temp") == 153
@ -767,13 +767,13 @@ async def test_brightness_controlling_scale(
async_fire_mqtt_message(hass, "test_scale/status", "on")
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") is None
async_fire_mqtt_message(hass, "test_scale/status", "off")
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
async_fire_mqtt_message(hass, "test_scale/status", "on")
@ -910,7 +910,7 @@ async def test_controlling_state_via_topic_with_templates(
hass, "test_light_rgb/effect/status", '{"hello": "rainbow"}'
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 50
assert state.attributes.get("rgb_color") == (1, 2, 3)
assert state.attributes.get("effect") == "rainbow"
@ -921,7 +921,7 @@ async def test_controlling_state_via_topic_with_templates(
hass, "test_light_rgb/rgbw/status", '{"hello": [1, 2, 3, 4]}'
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgbw_color") == (1, 2, 3, 4)
assert state.attributes.get(light.ATTR_COLOR_MODE) == "rgbw"
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
@ -930,7 +930,7 @@ async def test_controlling_state_via_topic_with_templates(
hass, "test_light_rgb/rgbww/status", '{"hello": [1, 2, 3, 4, 5]}'
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgbww_color") == (1, 2, 3, 4, 5)
assert state.attributes.get(light.ATTR_COLOR_MODE) == "rgbww"
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
@ -1017,7 +1017,7 @@ async def test_sending_mqtt_commands_and_optimistic(
mqtt_mock = await mqtt_mock_entry()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 95
assert state.attributes.get("hs_color") == (100, 100)
assert state.attributes.get("effect") == "random"
@ -1037,7 +1037,7 @@ async def test_sending_mqtt_commands_and_optimistic(
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("effect") == "colorloop"
assert state.attributes.get(light.ATTR_COLOR_MODE) == "hs"
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
@ -1048,7 +1048,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
assert state.attributes.get(light.ATTR_COLOR_MODE) is None
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
@ -1066,7 +1066,7 @@ async def test_sending_mqtt_commands_and_optimistic(
assert mqtt_mock.async_publish.call_count == 3
mqtt_mock.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 10
assert state.attributes.get("rgb_color") == (80, 40, 20)
assert state.attributes.get(light.ATTR_COLOR_MODE) == "rgb"
@ -1086,7 +1086,7 @@ async def test_sending_mqtt_commands_and_optimistic(
assert mqtt_mock.async_publish.call_count == 3
mqtt_mock.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 20
assert state.attributes.get("rgbw_color") == (80, 40, 20, 10)
assert state.attributes.get(light.ATTR_COLOR_MODE) == "rgbw"
@ -1106,7 +1106,7 @@ async def test_sending_mqtt_commands_and_optimistic(
assert mqtt_mock.async_publish.call_count == 3
mqtt_mock.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 40
assert state.attributes.get("rgbww_color") == (80, 40, 20, 10, 8)
assert state.attributes.get(light.ATTR_COLOR_MODE) == "rgbww"
@ -1124,7 +1124,7 @@ async def test_sending_mqtt_commands_and_optimistic(
assert mqtt_mock.async_publish.call_count == 3
mqtt_mock.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 50
assert state.attributes.get("hs_color") == (359.0, 78.0)
assert state.attributes.get(light.ATTR_COLOR_MODE) == "hs"
@ -1142,7 +1142,7 @@ async def test_sending_mqtt_commands_and_optimistic(
assert mqtt_mock.async_publish.call_count == 3
mqtt_mock.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 60
assert state.attributes.get("xy_color") == (0.2, 0.3)
assert state.attributes.get(light.ATTR_COLOR_MODE) == "xy"
@ -1158,7 +1158,7 @@ async def test_sending_mqtt_commands_and_optimistic(
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 60
assert state.attributes.get("color_temp") == 125
assert state.attributes.get(light.ATTR_COLOR_MODE) == "color_temp"
@ -1204,7 +1204,7 @@ async def test_sending_mqtt_rgb_command_with_template(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["rgb_color"] == (255, 128, 64)
@ -1247,7 +1247,7 @@ async def test_sending_mqtt_rgbw_command_with_template(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["rgbw_color"] == (255, 128, 64, 32)
@ -1290,7 +1290,7 @@ async def test_sending_mqtt_rgbww_command_with_template(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["rgbww_color"] == (255, 128, 64, 32, 16)
@ -1332,7 +1332,7 @@ async def test_sending_mqtt_color_temp_command_with_template(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["color_temp"] == 100
@ -2116,7 +2116,7 @@ async def test_explicit_color_mode(
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") is None
assert state.attributes.get("brightness") is None
assert state.attributes.get("color_temp") is None
@ -2131,7 +2131,7 @@ async def test_explicit_color_mode(
async_fire_mqtt_message(hass, "test_light_rgb/status", "0")
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
async_fire_mqtt_message(hass, "test_light_rgb/brightness/status", "100")
@ -2256,7 +2256,7 @@ async def test_explicit_color_mode_templated(
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") is None
assert state.attributes.get("color_temp") is None
assert state.attributes.get("hs_color") is None
@ -2265,7 +2265,7 @@ async def test_explicit_color_mode_templated(
async_fire_mqtt_message(hass, "test_light_rgb/status", "0")
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
async_fire_mqtt_message(hass, "test_light_rgb/brightness/status", "100")
@ -2354,7 +2354,7 @@ async def test_white_state_update(
'{"POWER":"ON","Dimmer":50,"Color":"0,0,0,128","White":50}',
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 128
assert state.attributes.get("rgb_color") is None
assert state.attributes.get(light.ATTR_COLOR_MODE) == "white"
@ -2366,7 +2366,7 @@ async def test_white_state_update(
'{"POWER":"ON","Dimmer":50,"Color":"128,64,32,0","White":0}',
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 128
assert state.attributes.get("rgb_color") == (128, 64, 32)
assert state.attributes.get(light.ATTR_COLOR_MODE) == "rgb"
@ -3428,7 +3428,7 @@ async def test_sending_mqtt_brightness_command_with_template(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["brightness"] == 100
@ -3476,7 +3476,7 @@ async def test_sending_mqtt_effect_command_with_template(
any_order=True,
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("effect") == "colorloop"
@ -3516,7 +3516,7 @@ async def test_sending_mqtt_hs_command_with_template(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["hs_color"] == (30, 100)
@ -3559,7 +3559,7 @@ async def test_sending_mqtt_xy_command_with_template(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["xy_color"] == (0.151, 0.343)

View file

@ -93,8 +93,6 @@ from homeassistant.components.mqtt.models import PublishPayloadType
from homeassistant.const import (
ATTR_ASSUMED_STATE,
ATTR_SUPPORTED_FEATURES,
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
)
from homeassistant.core import HomeAssistant, State
@ -432,7 +430,7 @@ async def test_single_color_mode(
)
color_modes = [light.ColorMode.COLOR_TEMP]
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
assert state.attributes.get(light.ATTR_COLOR_TEMP) == 192
@ -455,7 +453,7 @@ async def test_turn_on_with_unknown_color_mode_optimistic(
assert state.attributes.get("color_mode") == light.ColorMode.UNKNOWN
assert state.attributes.get("brightness") is None
assert state.attributes.get("color_temp") is None
assert state.state == STATE_ON
assert state.state == light.LightState.ON
# Turn on the light with brightness or color_temp attributes
await common.async_turn_on(hass, "light.test", brightness=50, color_temp=192)
@ -463,7 +461,7 @@ async def test_turn_on_with_unknown_color_mode_optimistic(
assert state.attributes.get("color_mode") == light.ColorMode.COLOR_TEMP
assert state.attributes.get("brightness") == 50
assert state.attributes.get("color_temp") == 192
assert state.state == STATE_ON
assert state.state == light.LightState.ON
@pytest.mark.parametrize(
@ -493,7 +491,7 @@ async def test_controlling_state_with_unknown_color_mode(
'{"state": "ON"}',
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get(light.ATTR_COLOR_TEMP) is None
assert state.attributes.get(light.ATTR_BRIGHTNESS) is None
assert state.attributes.get(light.ATTR_COLOR_MODE) == light.ColorMode.UNKNOWN
@ -505,7 +503,7 @@ async def test_controlling_state_with_unknown_color_mode(
'{"state": "ON", "brightness": 50, "color_mode": "color_temp", "color_temp": 192}',
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get(light.ATTR_COLOR_TEMP) == 192
assert state.attributes.get(light.ATTR_BRIGHTNESS) == 50
@ -575,7 +573,7 @@ async def test_no_color_brightness_color_temp_if_no_topics(
async_fire_mqtt_message(hass, "test_light_rgb", '{"state":"ON"}')
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") is None
assert state.attributes.get("brightness") is None
assert state.attributes.get("color_temp") is None
@ -586,7 +584,7 @@ async def test_no_color_brightness_color_temp_if_no_topics(
async_fire_mqtt_message(hass, "test_light_rgb", '{"state":"OFF"}')
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
async_fire_mqtt_message(hass, "test_light_rgb", '{"state": null}')
@ -650,7 +648,7 @@ async def test_controlling_state_via_topic(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (255, 255, 255)
assert state.attributes.get("brightness") == 255
assert state.attributes.get("color_temp") is None # rgb color has priority
@ -670,7 +668,7 @@ async def test_controlling_state_via_topic(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (
255,
253,
@ -686,7 +684,7 @@ async def test_controlling_state_via_topic(
async_fire_mqtt_message(hass, "test_light_rgb", '{"state":"OFF"}')
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
async_fire_mqtt_message(hass, "test_light_rgb", '{"state":"ON", "brightness":100}')
@ -747,7 +745,7 @@ async def test_controlling_state_via_topic(
'"effect":"colorloop"}',
)
light_state = hass.states.get("light.test")
assert light_state.state == STATE_ON
assert light_state.state == light.LightState.ON
assert light_state.attributes.get("brightness") == 128
async_fire_mqtt_message(
@ -756,7 +754,7 @@ async def test_controlling_state_via_topic(
'{"state":"OFF","brightness":0}',
)
light_state = hass.states.get("light.test")
assert light_state.state == STATE_OFF
assert light_state.state == light.LightState.OFF
assert light_state.attributes.get("brightness") is None
# test previous zero brightness received was ignored and brightness is restored
@ -817,7 +815,7 @@ async def test_controlling_state_via_topic2(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 255
assert state.attributes.get("color_mode") == "rgbww"
assert state.attributes.get("color_temp") is None
@ -831,7 +829,7 @@ async def test_controlling_state_via_topic2(
# Light turned off
async_fire_mqtt_message(hass, "test_light_rgb", '{"state":"OFF"}')
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
# Light turned on, brightness 100
async_fire_mqtt_message(hass, "test_light_rgb", '{"state":"ON", "brightness":100}')
@ -987,7 +985,7 @@ async def test_controlling_the_state_with_legacy_color_handling(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 255
assert state.attributes.get("color_mode") == "hs"
assert state.attributes.get("color_temp") is None
@ -1009,7 +1007,7 @@ async def test_controlling_the_state_with_legacy_color_handling(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 255
assert state.attributes.get("color_mode") == "color_temp"
assert state.attributes.get("color_temp") == 353
@ -1061,7 +1059,7 @@ async def test_sending_mqtt_commands_and_optimistic(
mqtt_mock = await mqtt_mock_entry()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 95
assert state.attributes.get("hs_color") == (100, 100)
assert state.attributes.get("effect") == "random"
@ -1081,7 +1079,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
await common.async_turn_on(hass, "light.test", color_temp=90)
@ -1093,7 +1091,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("color_mode") == light.ColorMode.COLOR_TEMP
assert state.attributes.get("color_temp") == 90
@ -1104,7 +1102,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
mqtt_mock.reset_mock()
await common.async_turn_on(
@ -1141,7 +1139,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("color_mode") == light.ColorMode.HS
assert state.attributes["brightness"] == 50
assert state.attributes["hs_color"] == (359.0, 78.0)
@ -1160,7 +1158,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("color_mode") == light.ColorMode.HS
assert state.attributes["brightness"] == 50
assert state.attributes["hs_color"] == (30.118, 100)
@ -1216,7 +1214,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
mqtt_mock = await mqtt_mock_entry()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
expected_features = (
light.SUPPORT_EFFECT | light.SUPPORT_FLASH | light.SUPPORT_TRANSITION
)
@ -1241,7 +1239,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
# Turn the light on with color temperature
await common.async_turn_on(hass, "light.test", color_temp=90)
@ -1253,7 +1251,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
# Turn the light off
await common.async_turn_off(hass, "light.test")
@ -1262,12 +1260,12 @@ async def test_sending_mqtt_commands_and_optimistic2(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
# Set hs color
await common.async_turn_on(hass, "light.test", brightness=75, hs_color=[359, 78])
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["brightness"] == 75
assert state.attributes["color_mode"] == "hs"
assert state.attributes["hs_color"] == (359, 78)
@ -1288,7 +1286,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
# Set rgb color
await common.async_turn_on(hass, "light.test", rgb_color=[255, 128, 0])
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["brightness"] == 75
assert state.attributes["color_mode"] == "rgb"
assert state.attributes["hs_color"] == (30.118, 100.0)
@ -1307,7 +1305,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
# Set rgbw color
await common.async_turn_on(hass, "light.test", rgbw_color=[255, 128, 0, 123])
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["brightness"] == 75
assert state.attributes["color_mode"] == "rgbw"
assert state.attributes["rgbw_color"] == (255, 128, 0, 123)
@ -1328,7 +1326,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
# Set rgbww color
await common.async_turn_on(hass, "light.test", rgbww_color=[255, 128, 0, 45, 32])
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["brightness"] == 75
assert state.attributes["color_mode"] == "rgbww"
assert state.attributes["rgbww_color"] == (255, 128, 0, 45, 32)
@ -1351,7 +1349,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
hass, "light.test", brightness=50, xy_color=[0.123, 0.223]
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["brightness"] == 50
assert state.attributes["color_mode"] == "xy"
assert state.attributes["hs_color"] == (196.471, 100.0)
@ -1372,7 +1370,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
# Set to white
await common.async_turn_on(hass, "light.test", white=75)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["brightness"] == 75
assert state.attributes["color_mode"] == "white"
assert state.attributes["hs_color"] is None
@ -1391,7 +1389,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
# Set to white, brightness also present in turn_on
await common.async_turn_on(hass, "light.test", brightness=60, white=80)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes["brightness"] == 60
assert state.attributes["color_mode"] == "white"
assert state.attributes["hs_color"] is None
@ -1892,7 +1890,7 @@ async def test_effect(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("effect") is None
await common.async_turn_on(hass, "light.test", effect="rainbow")
@ -1905,7 +1903,7 @@ async def test_effect(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("effect") == "rainbow"
await common.async_turn_on(hass, "light.test", effect="colorloop")
@ -1918,7 +1916,7 @@ async def test_effect(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("effect") == "colorloop"
@ -1957,7 +1955,7 @@ async def test_flash_short_and_long(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
await common.async_turn_on(hass, "light.test", flash="long")
@ -1966,7 +1964,7 @@ async def test_flash_short_and_long(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
await common.async_turn_off(hass, "light.test", flash="short")
@ -1975,7 +1973,7 @@ async def test_flash_short_and_long(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
await common.async_turn_off(hass, "light.test", flash="long")
@ -1984,7 +1982,7 @@ async def test_flash_short_and_long(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
@pytest.mark.parametrize(
@ -2022,7 +2020,7 @@ async def test_transition(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
await common.async_turn_off(hass, "light.test", transition=30)
@ -2034,7 +2032,7 @@ async def test_transition(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
@pytest.mark.parametrize(
@ -2069,7 +2067,7 @@ async def test_brightness_scale(
async_fire_mqtt_message(hass, "test_light_bright_scale", '{"state":"ON"}')
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") is None
# Turn on the light with brightness
@ -2078,7 +2076,7 @@ async def test_brightness_scale(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 255
# Turn on the light with half brightness
@ -2087,7 +2085,7 @@ async def test_brightness_scale(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 129
# Test limmiting max brightness
@ -2096,7 +2094,7 @@ async def test_brightness_scale(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 255
@ -2135,7 +2133,7 @@ async def test_white_scale(
async_fire_mqtt_message(hass, "test_light_bright_scale", '{"state":"ON"}')
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") is None
# Turn on the light with brightness
@ -2146,7 +2144,7 @@ async def test_white_scale(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 255
# Turn on the light with white - white_scale is NOT used
@ -2157,7 +2155,7 @@ async def test_white_scale(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 129
@ -2209,7 +2207,7 @@ async def test_invalid_values(
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (255, 255, 255)
assert state.attributes.get("brightness") == 255
assert state.attributes.get("color_temp") is None
@ -2222,7 +2220,7 @@ async def test_invalid_values(
# Color should not have changed
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (255, 255, 255)
# Bad HS color values
@ -2234,7 +2232,7 @@ async def test_invalid_values(
# Color should not have changed
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (255, 255, 255)
# Bad RGB color values
@ -2246,7 +2244,7 @@ async def test_invalid_values(
# Color should not have changed
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (255, 255, 255)
# Bad XY color values
@ -2258,7 +2256,7 @@ async def test_invalid_values(
# Color should not have changed
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (255, 255, 255)
# Bad brightness values
@ -2268,7 +2266,7 @@ async def test_invalid_values(
# Brightness should not have changed
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 255
# Unset color and set a valid color temperature
@ -2276,7 +2274,7 @@ async def test_invalid_values(
hass, "test_light_rgb", '{"state":"ON", "color": null, "color_temp": 100}'
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("color_temp") == 100
# Bad color temperature
@ -2286,7 +2284,7 @@ async def test_invalid_values(
# Color temperature should not have changed
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("color_temp") == 100

View file

@ -39,8 +39,6 @@ from homeassistant.components.mqtt.models import PublishPayloadType
from homeassistant.const import (
ATTR_ASSUMED_STATE,
ATTR_SUPPORTED_FEATURES,
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
)
from homeassistant.core import HomeAssistant, State
@ -209,7 +207,7 @@ async def test_single_color_mode(
async_fire_mqtt_message(hass, "test_light", "on,50,192")
color_modes = [light.ColorMode.COLOR_TEMP]
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
assert state.attributes.get(light.ATTR_COLOR_TEMP) == 192
@ -256,7 +254,7 @@ async def test_state_change_via_topic(
async_fire_mqtt_message(hass, "test_light_rgb", "on")
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") is None
assert state.attributes.get("brightness") is None
assert state.attributes.get("color_temp") is None
@ -264,7 +262,7 @@ async def test_state_change_via_topic(
async_fire_mqtt_message(hass, "test_light_rgb", "off")
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
async_fire_mqtt_message(hass, "test_light_rgb", "None")
@ -321,7 +319,7 @@ async def test_state_brightness_color_effect_temp_change_via_topic(
async_fire_mqtt_message(hass, "test_light_rgb", "on,255,145,255-128-64,")
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (255, 128, 63)
assert state.attributes.get("brightness") == 255
assert state.attributes.get("color_temp") is None # rgb color has priority
@ -331,7 +329,7 @@ async def test_state_brightness_color_effect_temp_change_via_topic(
async_fire_mqtt_message(hass, "test_light_rgb", "on,255,145,None-None-None,")
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (
246,
244,
@ -356,7 +354,7 @@ async def test_state_brightness_color_effect_temp_change_via_topic(
async_fire_mqtt_message(hass, "test_light_rgb", "off")
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
# lower the brightness
async_fire_mqtt_message(hass, "test_light_rgb", "on,100")
@ -440,7 +438,7 @@ async def test_sending_mqtt_commands_and_optimistic(
mqtt_mock = await mqtt_mock_entry()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("hs_color") == (100, 100)
assert state.attributes.get("effect") == "random"
assert state.attributes.get("color_temp") is None # hs_color has priority
@ -452,7 +450,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
await common.async_turn_on(hass, "light.test")
mqtt_mock.async_publish.assert_called_once_with(
@ -460,7 +458,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
# Set color_temp
await common.async_turn_on(hass, "light.test", color_temp=70)
@ -469,7 +467,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("color_temp") == 70
# Set full brightness
@ -479,7 +477,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
# Full brightness - no scaling of RGB values sent over MQTT
await common.async_turn_on(hass, "light.test", rgb_color=[255, 128, 0])
@ -488,7 +486,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (255, 128, 0)
# Full brightness - normalization of RGB values sent over MQTT
@ -498,7 +496,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (255, 127, 0)
# Set half brightness
@ -508,7 +506,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
# Half brightness - scaling of RGB values sent over MQTT
await common.async_turn_on(hass, "light.test", rgb_color=[0, 255, 128])
@ -517,7 +515,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (0, 255, 128)
# Half brightness - normalization+scaling of RGB values sent over MQTT
@ -527,7 +525,7 @@ async def test_sending_mqtt_commands_and_optimistic(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("rgb_color") == (0, 255, 127)
@ -688,7 +686,7 @@ async def test_effect(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert not state.attributes.get("effect")
await common.async_turn_on(hass, "light.test", effect="rainbow")
@ -697,7 +695,7 @@ async def test_effect(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("effect") == "rainbow"
await common.async_turn_on(hass, "light.test", effect="colorloop")
@ -705,7 +703,7 @@ async def test_effect(
"test_light_rgb/set", "on,colorloop", 0, False
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("effect") == "colorloop"
@ -742,7 +740,7 @@ async def test_flash(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
await common.async_turn_on(hass, "light.test", flash="short")
mqtt_mock.async_publish.assert_called_once_with(
@ -750,14 +748,14 @@ async def test_flash(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
await common.async_turn_on(hass, "light.test", flash="long")
mqtt_mock.async_publish.assert_called_once_with(
"test_light_rgb/set", "on,long", 0, False
)
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
@pytest.mark.parametrize(
@ -794,14 +792,14 @@ async def test_transition(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
await common.async_turn_off(hass, "light.test", transition=20.0)
mqtt_mock.async_publish.assert_called_once_with(
"test_light_rgb/set", "off,20", 1, False
)
state = hass.states.get("light.test")
assert state.state == STATE_OFF
assert state.state == light.LightState.OFF
@pytest.mark.parametrize(
@ -854,7 +852,7 @@ async def test_invalid_values(
async_fire_mqtt_message(hass, "test_light_rgb", "on,255,215,255-255-255,rainbow")
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("brightness") == 255
assert state.attributes.get("color_temp") is None # hs_color has priority
assert state.attributes.get("rgb_color") == (255, 255, 255)
@ -865,7 +863,7 @@ async def test_invalid_values(
# state should not have changed
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
# bad brightness values
async_fire_mqtt_message(hass, "test_light_rgb", "on,off,255-255-255")
@ -884,7 +882,7 @@ async def test_invalid_values(
# Unset color and set a valid color temperature
async_fire_mqtt_message(hass, "test_light_rgb", "on,,215,None-None-None")
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.state == light.LightState.ON
assert state.attributes.get("color_temp") == 215
# bad color temp values

View file

@ -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

View file

@ -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(

View file

@ -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

View file

@ -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"

View file

@ -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
)

View file

@ -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

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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()

View file

@ -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,

View file

@ -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(

View file

@ -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

View file

@ -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],

View file

@ -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(

View file

@ -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()

View file

@ -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),
]
)