Skip to content

Commit

Permalink
Use LightEntityFeature enum in smartthings (#71057)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Apr 29, 2022
1 parent 2fb16fd commit 6bb685e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions homeassistant/components/smartthings/light.py
Expand Up @@ -14,8 +14,8 @@
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
SUPPORT_TRANSITION,
LightEntity,
LightEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -86,7 +86,7 @@ def _determine_features(self):
features = 0
# Brightness and transition
if Capability.switch_level in self._device.capabilities:
features |= SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
features |= SUPPORT_BRIGHTNESS | LightEntityFeature.TRANSITION
# Color Temperature
if Capability.color_temperature in self._device.capabilities:
features |= SUPPORT_COLOR_TEMP
Expand Down Expand Up @@ -124,7 +124,10 @@ async def async_turn_on(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs) -> None:
"""Turn the light off."""
# 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]))
else:
await self._device.switch_off(set_status=True)
Expand Down
11 changes: 7 additions & 4 deletions tests/components/smartthings/test_light.py
Expand Up @@ -16,7 +16,7 @@
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
SUPPORT_TRANSITION,
LightEntityFeature,
)
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
from homeassistant.config_entries import ConfigEntryState
Expand Down Expand Up @@ -82,7 +82,7 @@ async def test_entity_state(hass, light_devices):
assert state.state == "on"
assert (
state.attributes[ATTR_SUPPORTED_FEATURES]
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
== SUPPORT_BRIGHTNESS | LightEntityFeature.TRANSITION
)
assert isinstance(state.attributes[ATTR_BRIGHTNESS], int)
assert state.attributes[ATTR_BRIGHTNESS] == 255
Expand All @@ -92,15 +92,18 @@ async def test_entity_state(hass, light_devices):
assert state.state == "off"
assert (
state.attributes[ATTR_SUPPORTED_FEATURES]
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | SUPPORT_COLOR
== SUPPORT_BRIGHTNESS | LightEntityFeature.TRANSITION | SUPPORT_COLOR
)

# Color Dimmer 2
state = hass.states.get("light.color_dimmer_2")
assert state.state == "on"
assert (
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_HS_COLOR] == (273.6, 55.0)
Expand Down

0 comments on commit 6bb685e

Please sign in to comment.