Use LightEntityFeature enum in mqtt (#71055)
This commit is contained in:
parent
f08615fc76
commit
09d61edd9f
3 changed files with 12 additions and 13 deletions
|
@ -23,10 +23,10 @@ from homeassistant.components.light import (
|
||||||
SUPPORT_BRIGHTNESS,
|
SUPPORT_BRIGHTNESS,
|
||||||
SUPPORT_COLOR,
|
SUPPORT_COLOR,
|
||||||
SUPPORT_COLOR_TEMP,
|
SUPPORT_COLOR_TEMP,
|
||||||
SUPPORT_EFFECT,
|
|
||||||
SUPPORT_WHITE_VALUE,
|
SUPPORT_WHITE_VALUE,
|
||||||
ColorMode,
|
ColorMode,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
|
LightEntityFeature,
|
||||||
valid_supported_color_modes,
|
valid_supported_color_modes,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -799,7 +799,8 @@ class MqttLight(MqttEntity, LightEntity, RestoreEntity):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
supported_features = 0
|
supported_features = 0
|
||||||
supported_features |= (
|
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:
|
if not self._legacy_mode:
|
||||||
return supported_features
|
return supported_features
|
||||||
|
|
|
@ -24,13 +24,11 @@ from homeassistant.components.light import (
|
||||||
SUPPORT_BRIGHTNESS,
|
SUPPORT_BRIGHTNESS,
|
||||||
SUPPORT_COLOR,
|
SUPPORT_COLOR,
|
||||||
SUPPORT_COLOR_TEMP,
|
SUPPORT_COLOR_TEMP,
|
||||||
SUPPORT_EFFECT,
|
|
||||||
SUPPORT_FLASH,
|
|
||||||
SUPPORT_TRANSITION,
|
|
||||||
SUPPORT_WHITE_VALUE,
|
SUPPORT_WHITE_VALUE,
|
||||||
VALID_COLOR_MODES,
|
VALID_COLOR_MODES,
|
||||||
ColorMode,
|
ColorMode,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
|
LightEntityFeature,
|
||||||
legacy_supported_features,
|
legacy_supported_features,
|
||||||
valid_supported_color_modes,
|
valid_supported_color_modes,
|
||||||
)
|
)
|
||||||
|
@ -215,8 +213,10 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
|
||||||
for key in (CONF_FLASH_TIME_SHORT, CONF_FLASH_TIME_LONG)
|
for key in (CONF_FLASH_TIME_SHORT, CONF_FLASH_TIME_LONG)
|
||||||
}
|
}
|
||||||
|
|
||||||
self._supported_features = SUPPORT_TRANSITION | SUPPORT_FLASH
|
self._supported_features = (
|
||||||
self._supported_features |= config[CONF_EFFECT] and SUPPORT_EFFECT
|
LightEntityFeature.TRANSITION | LightEntityFeature.FLASH
|
||||||
|
)
|
||||||
|
self._supported_features |= config[CONF_EFFECT] and LightEntityFeature.EFFECT
|
||||||
if not self._config[CONF_COLOR_MODE]:
|
if not self._config[CONF_COLOR_MODE]:
|
||||||
self._supported_features |= config[CONF_BRIGHTNESS] and SUPPORT_BRIGHTNESS
|
self._supported_features |= config[CONF_BRIGHTNESS] and SUPPORT_BRIGHTNESS
|
||||||
self._supported_features |= config[CONF_COLOR_TEMP] and SUPPORT_COLOR_TEMP
|
self._supported_features |= config[CONF_COLOR_TEMP] and SUPPORT_COLOR_TEMP
|
||||||
|
@ -355,7 +355,7 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.warning("Invalid color temp value received")
|
_LOGGER.warning("Invalid color temp value received")
|
||||||
|
|
||||||
if self._supported_features and SUPPORT_EFFECT:
|
if self._supported_features and LightEntityFeature.EFFECT:
|
||||||
with suppress(KeyError):
|
with suppress(KeyError):
|
||||||
self._effect = values["effect"]
|
self._effect = values["effect"]
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,9 @@ from homeassistant.components.light import (
|
||||||
SUPPORT_BRIGHTNESS,
|
SUPPORT_BRIGHTNESS,
|
||||||
SUPPORT_COLOR,
|
SUPPORT_COLOR,
|
||||||
SUPPORT_COLOR_TEMP,
|
SUPPORT_COLOR_TEMP,
|
||||||
SUPPORT_EFFECT,
|
|
||||||
SUPPORT_FLASH,
|
|
||||||
SUPPORT_TRANSITION,
|
|
||||||
SUPPORT_WHITE_VALUE,
|
SUPPORT_WHITE_VALUE,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
|
LightEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
|
@ -442,7 +440,7 @@ class MqttLightTemplate(MqttEntity, LightEntity, RestoreEntity):
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
features = SUPPORT_FLASH | SUPPORT_TRANSITION
|
features = LightEntityFeature.FLASH | LightEntityFeature.TRANSITION
|
||||||
if self._templates[CONF_BRIGHTNESS_TEMPLATE] is not None:
|
if self._templates[CONF_BRIGHTNESS_TEMPLATE] is not None:
|
||||||
features = features | SUPPORT_BRIGHTNESS
|
features = features | SUPPORT_BRIGHTNESS
|
||||||
if (
|
if (
|
||||||
|
@ -452,7 +450,7 @@ class MqttLightTemplate(MqttEntity, LightEntity, RestoreEntity):
|
||||||
):
|
):
|
||||||
features = features | SUPPORT_COLOR | SUPPORT_BRIGHTNESS
|
features = features | SUPPORT_COLOR | SUPPORT_BRIGHTNESS
|
||||||
if self._config.get(CONF_EFFECT_LIST) is not None:
|
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:
|
if self._templates[CONF_COLOR_TEMP_TEMPLATE] is not None:
|
||||||
features = features | SUPPORT_COLOR_TEMP
|
features = features | SUPPORT_COLOR_TEMP
|
||||||
if self._templates[CONF_WHITE_VALUE_TEMPLATE] is not None:
|
if self._templates[CONF_WHITE_VALUE_TEMPLATE] is not None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue