Use light enums in shelly (#70790)

This commit is contained in:
epenet 2022-04-26 14:29:56 +02:00 committed by GitHub
parent 13fc6ee426
commit 5af496682b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,10 +12,9 @@ from homeassistant.components.light import (
ATTR_RGB_COLOR, ATTR_RGB_COLOR,
ATTR_RGBW_COLOR, ATTR_RGBW_COLOR,
ATTR_TRANSITION, ATTR_TRANSITION,
SUPPORT_EFFECT,
SUPPORT_TRANSITION,
ColorMode, ColorMode,
LightEntity, LightEntity,
LightEntityFeature,
brightness_supported, brightness_supported,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -158,7 +157,7 @@ class BlockShellyLight(ShellyBlockEntity, LightEntity):
self._attr_supported_color_modes.add(ColorMode.ONOFF) self._attr_supported_color_modes.add(ColorMode.ONOFF)
if hasattr(block, "effect"): if hasattr(block, "effect"):
self._attr_supported_features |= SUPPORT_EFFECT self._attr_supported_features |= LightEntityFeature.EFFECT
if wrapper.model in MODELS_SUPPORTING_LIGHT_TRANSITION: if wrapper.model in MODELS_SUPPORTING_LIGHT_TRANSITION:
match = FIRMWARE_PATTERN.search(wrapper.device.settings.get("fw", "")) match = FIRMWARE_PATTERN.search(wrapper.device.settings.get("fw", ""))
@ -166,7 +165,7 @@ class BlockShellyLight(ShellyBlockEntity, LightEntity):
match is not None match is not None
and int(match[0]) >= LIGHT_TRANSITION_MIN_FIRMWARE_DATE and int(match[0]) >= LIGHT_TRANSITION_MIN_FIRMWARE_DATE
): ):
self._attr_supported_features |= SUPPORT_TRANSITION self._attr_supported_features |= LightEntityFeature.TRANSITION
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
@ -264,7 +263,7 @@ class BlockShellyLight(ShellyBlockEntity, LightEntity):
@property @property
def effect_list(self) -> list[str] | None: def effect_list(self) -> list[str] | None:
"""Return the list of supported effects.""" """Return the list of supported effects."""
if not self.supported_features & SUPPORT_EFFECT: if not self.supported_features & LightEntityFeature.EFFECT:
return None return None
if self.wrapper.model == "SHBLB-1": if self.wrapper.model == "SHBLB-1":
@ -275,7 +274,7 @@ class BlockShellyLight(ShellyBlockEntity, LightEntity):
@property @property
def effect(self) -> str | None: def effect(self) -> str | None:
"""Return the current effect.""" """Return the current effect."""
if not self.supported_features & SUPPORT_EFFECT: if not self.supported_features & LightEntityFeature.EFFECT:
return None return None
if self.control_result: if self.control_result: