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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use LightEntityFeature enum in mqtt #71055

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions homeassistant/components/mqtt/light/schema_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
SUPPORT_EFFECT,
SUPPORT_WHITE_VALUE,
ColorMode,
LightEntity,
LightEntityFeature,
valid_supported_color_modes,
)
from homeassistant.const import (
Expand Down Expand Up @@ -799,7 +799,8 @@ def supported_features(self):
"""Flag supported features."""
supported_features = 0
supported_features |= (
self._topic[CONF_EFFECT_COMMAND_TOPIC] is not None and SUPPORT_EFFECT
self._topic[CONF_EFFECT_COMMAND_TOPIC] is not None
and LightEntityFeature.EFFECT
)
if not self._legacy_mode:
return supported_features
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/mqtt/light/schema_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
SUPPORT_EFFECT,
SUPPORT_FLASH,
SUPPORT_TRANSITION,
SUPPORT_WHITE_VALUE,
VALID_COLOR_MODES,
ColorMode,
LightEntity,
LightEntityFeature,
legacy_supported_features,
valid_supported_color_modes,
)
Expand Down Expand Up @@ -215,8 +213,10 @@ def _setup_from_config(self, config):
for key in (CONF_FLASH_TIME_SHORT, CONF_FLASH_TIME_LONG)
}

self._supported_features = SUPPORT_TRANSITION | SUPPORT_FLASH
self._supported_features |= config[CONF_EFFECT] and SUPPORT_EFFECT
self._supported_features = (
LightEntityFeature.TRANSITION | LightEntityFeature.FLASH
)
self._supported_features |= config[CONF_EFFECT] and LightEntityFeature.EFFECT
if not self._config[CONF_COLOR_MODE]:
self._supported_features |= config[CONF_BRIGHTNESS] and SUPPORT_BRIGHTNESS
self._supported_features |= config[CONF_COLOR_TEMP] and SUPPORT_COLOR_TEMP
Expand Down Expand Up @@ -355,7 +355,7 @@ def state_received(msg):
except ValueError:
_LOGGER.warning("Invalid color temp value received")

if self._supported_features and SUPPORT_EFFECT:
if self._supported_features and LightEntityFeature.EFFECT:
with suppress(KeyError):
self._effect = values["effect"]

Expand Down
8 changes: 3 additions & 5 deletions homeassistant/components/mqtt/light/schema_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
SUPPORT_EFFECT,
SUPPORT_FLASH,
SUPPORT_TRANSITION,
SUPPORT_WHITE_VALUE,
LightEntity,
LightEntityFeature,
)
from homeassistant.const import (
CONF_NAME,
Expand Down Expand Up @@ -442,7 +440,7 @@ async def async_turn_off(self, **kwargs):
@property
def supported_features(self):
"""Flag supported features."""
features = SUPPORT_FLASH | SUPPORT_TRANSITION
features = LightEntityFeature.FLASH | LightEntityFeature.TRANSITION
if self._templates[CONF_BRIGHTNESS_TEMPLATE] is not None:
features = features | SUPPORT_BRIGHTNESS
if (
Expand All @@ -452,7 +450,7 @@ def supported_features(self):
):
features = features | SUPPORT_COLOR | SUPPORT_BRIGHTNESS
if self._config.get(CONF_EFFECT_LIST) is not None:
features = features | SUPPORT_EFFECT
features = features | LightEntityFeature.EFFECT
if self._templates[CONF_COLOR_TEMP_TEMPLATE] is not None:
features = features | SUPPORT_COLOR_TEMP
if self._templates[CONF_WHITE_VALUE_TEMPLATE] is not None:
Expand Down