Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use LightEntityFeature enum in smartthings #71057

Merged
merged 1 commit into from Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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