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
This commit is contained in:
epenet 2022-08-19 10:58:51 +02:00 committed by GitHub
parent cbeaea98d1
commit 61af82223f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -3,6 +3,7 @@ import logging
from blebox_uniapi.box import Box from blebox_uniapi.box import Box
from blebox_uniapi.error import Error from blebox_uniapi.error import Error
from blebox_uniapi.feature import Feature
from blebox_uniapi.session import ApiHost from blebox_uniapi.session import ApiHost
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -83,7 +84,7 @@ def create_blebox_entities(
class BleBoxEntity(Entity): class BleBoxEntity(Entity):
"""Implements a common class for entities representing a BleBox feature.""" """Implements a common class for entities representing a BleBox feature."""
def __init__(self, feature): def __init__(self, feature: Feature) -> None:
"""Initialize a BleBox entity.""" """Initialize a BleBox entity."""
self._feature = feature self._feature = feature
self._attr_name = feature.full_name self._attr_name = feature.full_name
@ -97,7 +98,7 @@ class BleBoxEntity(Entity):
sw_version=product.firmware_version, sw_version=product.firmware_version,
) )
async def async_update(self): async def async_update(self) -> None:
"""Update the entity state.""" """Update the entity state."""
try: try:
await self._feature.async_update() await self._feature.async_update()

View File

@ -56,11 +56,14 @@ COLOR_MODE_MAP = {
class BleBoxLightEntity(BleBoxEntity, LightEntity): class BleBoxLightEntity(BleBoxEntity, LightEntity):
"""Representation of BleBox lights.""" """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.""" """Initialize a BleBox light."""
super().__init__(feature) super().__init__(feature)
self._attr_supported_color_modes = {self.color_mode} 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 @property
def is_on(self) -> bool: def is_on(self) -> bool:
@ -91,7 +94,7 @@ class BleBoxLightEntity(BleBoxEntity, LightEntity):
return color_mode_tmp return color_mode_tmp
@property @property
def effect_list(self) -> list[str] | None: def effect_list(self) -> list[str]:
"""Return the list of supported effects.""" """Return the list of supported effects."""
return self._feature.effect_list return self._feature.effect_list
@ -125,7 +128,7 @@ class BleBoxLightEntity(BleBoxEntity, LightEntity):
return None return None
return tuple(blebox_uniapi.light.Light.rgb_hex_to_rgb_list(rgbww_hex)) 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.""" """Turn the light on."""
rgbw = kwargs.get(ATTR_RGBW_COLOR) rgbw = kwargs.get(ATTR_RGBW_COLOR)