mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use LightEntityFeature enum in smartthings (#71057)
This commit is contained in:
parent
2fb16fd06c
commit
6bb685eaba
@ -14,8 +14,8 @@ from homeassistant.components.light import (
|
|||||||
SUPPORT_BRIGHTNESS,
|
SUPPORT_BRIGHTNESS,
|
||||||
SUPPORT_COLOR,
|
SUPPORT_COLOR,
|
||||||
SUPPORT_COLOR_TEMP,
|
SUPPORT_COLOR_TEMP,
|
||||||
SUPPORT_TRANSITION,
|
|
||||||
LightEntity,
|
LightEntity,
|
||||||
|
LightEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -86,7 +86,7 @@ class SmartThingsLight(SmartThingsEntity, LightEntity):
|
|||||||
features = 0
|
features = 0
|
||||||
# Brightness and transition
|
# Brightness and transition
|
||||||
if Capability.switch_level in self._device.capabilities:
|
if Capability.switch_level in self._device.capabilities:
|
||||||
features |= SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
|
features |= SUPPORT_BRIGHTNESS | LightEntityFeature.TRANSITION
|
||||||
# Color Temperature
|
# Color Temperature
|
||||||
if Capability.color_temperature in self._device.capabilities:
|
if Capability.color_temperature in self._device.capabilities:
|
||||||
features |= SUPPORT_COLOR_TEMP
|
features |= SUPPORT_COLOR_TEMP
|
||||||
@ -124,7 +124,10 @@ class SmartThingsLight(SmartThingsEntity, LightEntity):
|
|||||||
async def async_turn_off(self, **kwargs) -> None:
|
async def async_turn_off(self, **kwargs) -> None:
|
||||||
"""Turn the light off."""
|
"""Turn the light off."""
|
||||||
# Switch/transition
|
# Switch/transition
|
||||||
if self._supported_features & SUPPORT_TRANSITION and ATTR_TRANSITION in kwargs:
|
if (
|
||||||
|
self._supported_features & LightEntityFeature.TRANSITION
|
||||||
|
and ATTR_TRANSITION in kwargs
|
||||||
|
):
|
||||||
await self.async_set_level(0, int(kwargs[ATTR_TRANSITION]))
|
await self.async_set_level(0, int(kwargs[ATTR_TRANSITION]))
|
||||||
else:
|
else:
|
||||||
await self._device.switch_off(set_status=True)
|
await self._device.switch_off(set_status=True)
|
||||||
|
@ -16,7 +16,7 @@ from homeassistant.components.light import (
|
|||||||
SUPPORT_BRIGHTNESS,
|
SUPPORT_BRIGHTNESS,
|
||||||
SUPPORT_COLOR,
|
SUPPORT_COLOR,
|
||||||
SUPPORT_COLOR_TEMP,
|
SUPPORT_COLOR_TEMP,
|
||||||
SUPPORT_TRANSITION,
|
LightEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
|
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
@ -82,7 +82,7 @@ async def test_entity_state(hass, light_devices):
|
|||||||
assert state.state == "on"
|
assert state.state == "on"
|
||||||
assert (
|
assert (
|
||||||
state.attributes[ATTR_SUPPORTED_FEATURES]
|
state.attributes[ATTR_SUPPORTED_FEATURES]
|
||||||
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
|
== SUPPORT_BRIGHTNESS | LightEntityFeature.TRANSITION
|
||||||
)
|
)
|
||||||
assert isinstance(state.attributes[ATTR_BRIGHTNESS], int)
|
assert isinstance(state.attributes[ATTR_BRIGHTNESS], int)
|
||||||
assert state.attributes[ATTR_BRIGHTNESS] == 255
|
assert state.attributes[ATTR_BRIGHTNESS] == 255
|
||||||
@ -92,7 +92,7 @@ async def test_entity_state(hass, light_devices):
|
|||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
assert (
|
assert (
|
||||||
state.attributes[ATTR_SUPPORTED_FEATURES]
|
state.attributes[ATTR_SUPPORTED_FEATURES]
|
||||||
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | SUPPORT_COLOR
|
== SUPPORT_BRIGHTNESS | LightEntityFeature.TRANSITION | SUPPORT_COLOR
|
||||||
)
|
)
|
||||||
|
|
||||||
# Color Dimmer 2
|
# Color Dimmer 2
|
||||||
@ -100,7 +100,10 @@ async def test_entity_state(hass, light_devices):
|
|||||||
assert state.state == "on"
|
assert state.state == "on"
|
||||||
assert (
|
assert (
|
||||||
state.attributes[ATTR_SUPPORTED_FEATURES]
|
state.attributes[ATTR_SUPPORTED_FEATURES]
|
||||||
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | SUPPORT_COLOR | SUPPORT_COLOR_TEMP
|
== SUPPORT_BRIGHTNESS
|
||||||
|
| LightEntityFeature.TRANSITION
|
||||||
|
| SUPPORT_COLOR
|
||||||
|
| SUPPORT_COLOR_TEMP
|
||||||
)
|
)
|
||||||
assert state.attributes[ATTR_BRIGHTNESS] == 255
|
assert state.attributes[ATTR_BRIGHTNESS] == 255
|
||||||
assert state.attributes[ATTR_HS_COLOR] == (273.6, 55.0)
|
assert state.attributes[ATTR_HS_COLOR] == (273.6, 55.0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user