From 61af82223f04548225d991b1ec04e3ce9ab9a526 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 19 Aug 2022 10:58:51 +0200 Subject: [PATCH] Improve type hint in blebox light entity (#77013) * Improve type hint in blebox light entity * Adjust * Adjust supported_features * Adjust effect_list property * Improve base class --- homeassistant/components/blebox/__init__.py | 5 +++-- homeassistant/components/blebox/light.py | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/blebox/__init__.py b/homeassistant/components/blebox/__init__.py index ff907d728b78..0f4bd1c14906 100644 --- a/homeassistant/components/blebox/__init__.py +++ b/homeassistant/components/blebox/__init__.py @@ -3,6 +3,7 @@ import logging from blebox_uniapi.box import Box from blebox_uniapi.error import Error +from blebox_uniapi.feature import Feature from blebox_uniapi.session import ApiHost from homeassistant.config_entries import ConfigEntry @@ -83,7 +84,7 @@ def create_blebox_entities( class BleBoxEntity(Entity): """Implements a common class for entities representing a BleBox feature.""" - def __init__(self, feature): + def __init__(self, feature: Feature) -> None: """Initialize a BleBox entity.""" self._feature = feature self._attr_name = feature.full_name @@ -97,7 +98,7 @@ class BleBoxEntity(Entity): sw_version=product.firmware_version, ) - async def async_update(self): + async def async_update(self) -> None: """Update the entity state.""" try: await self._feature.async_update() diff --git a/homeassistant/components/blebox/light.py b/homeassistant/components/blebox/light.py index 8202186d86d6..c1245d52fec6 100644 --- a/homeassistant/components/blebox/light.py +++ b/homeassistant/components/blebox/light.py @@ -56,11 +56,14 @@ COLOR_MODE_MAP = { class BleBoxLightEntity(BleBoxEntity, LightEntity): """Representation of BleBox lights.""" - def __init__(self, feature): + _feature: blebox_uniapi.light.Light + + def __init__(self, feature: blebox_uniapi.light.Light) -> None: """Initialize a BleBox light.""" super().__init__(feature) self._attr_supported_color_modes = {self.color_mode} - self._attr_supported_features = LightEntityFeature.EFFECT + if feature.effect_list: + self._attr_supported_features = LightEntityFeature.EFFECT @property def is_on(self) -> bool: @@ -91,7 +94,7 @@ class BleBoxLightEntity(BleBoxEntity, LightEntity): return color_mode_tmp @property - def effect_list(self) -> list[str] | None: + def effect_list(self) -> list[str]: """Return the list of supported effects.""" return self._feature.effect_list @@ -125,7 +128,7 @@ class BleBoxLightEntity(BleBoxEntity, LightEntity): return None return tuple(blebox_uniapi.light.Light.rgb_hex_to_rgb_list(rgbww_hex)) - async def async_turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs: Any) -> None: """Turn the light on.""" rgbw = kwargs.get(ATTR_RGBW_COLOR)