Strictly type Nanoleaf (#56852)

This commit is contained in:
Milan Meulemans 2021-09-30 23:48:28 +02:00 committed by GitHub
parent dfb3a0c528
commit e757cb2ab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 10 deletions

View File

@ -68,6 +68,7 @@ homeassistant.components.media_player.*
homeassistant.components.modbus.* homeassistant.components.modbus.*
homeassistant.components.mysensors.* homeassistant.components.mysensors.*
homeassistant.components.nam.* homeassistant.components.nam.*
homeassistant.components.nanoleaf.*
homeassistant.components.neato.* homeassistant.components.neato.*
homeassistant.components.nest.* homeassistant.components.nest.*
homeassistant.components.netatmo.* homeassistant.components.netatmo.*

View File

@ -1,6 +1,8 @@
"""Support for Nanoleaf Lights.""" """Support for Nanoleaf Lights."""
from __future__ import annotations from __future__ import annotations
from typing import Any
from aionanoleaf import Nanoleaf, Unavailable from aionanoleaf import Nanoleaf, Unavailable
import voluptuous as vol import voluptuous as vol
@ -79,19 +81,19 @@ class NanoleafLight(LightEntity):
self._attr_max_mireds = 833 self._attr_max_mireds = 833
@property @property
def brightness(self): def brightness(self) -> int:
"""Return the brightness of the light.""" """Return the brightness of the light."""
return int(self._nanoleaf.brightness * 2.55) return int(self._nanoleaf.brightness * 2.55)
@property @property
def color_temp(self): def color_temp(self) -> int:
"""Return the current color temperature.""" """Return the current color temperature."""
return color_util.color_temperature_kelvin_to_mired( return color_util.color_temperature_kelvin_to_mired(
self._nanoleaf.color_temperature self._nanoleaf.color_temperature
) )
@property @property
def effect(self): def effect(self) -> str | None:
"""Return the current effect.""" """Return the current effect."""
# The API returns the *Solid* effect if the Nanoleaf is in HS or CT mode. # The API returns the *Solid* effect if the Nanoleaf is in HS or CT mode.
# The effects *Static* and *Dynamic* are not supported by Home Assistant. # The effects *Static* and *Dynamic* are not supported by Home Assistant.
@ -102,27 +104,27 @@ class NanoleafLight(LightEntity):
) )
@property @property
def effect_list(self): def effect_list(self) -> list[str]:
"""Return the list of supported effects.""" """Return the list of supported effects."""
return self._nanoleaf.effects_list return self._nanoleaf.effects_list
@property @property
def icon(self): def icon(self) -> str:
"""Return the icon to use in the frontend, if any.""" """Return the icon to use in the frontend, if any."""
return "mdi:triangle-outline" return "mdi:triangle-outline"
@property @property
def is_on(self): def is_on(self) -> bool:
"""Return true if light is on.""" """Return true if light is on."""
return self._nanoleaf.is_on return self._nanoleaf.is_on
@property @property
def hs_color(self): def hs_color(self) -> tuple[int, int]:
"""Return the color in HS.""" """Return the color in HS."""
return self._nanoleaf.hue, self._nanoleaf.saturation return self._nanoleaf.hue, self._nanoleaf.saturation
@property @property
def supported_features(self): def supported_features(self) -> int:
"""Flag supported features.""" """Flag supported features."""
return ( return (
SUPPORT_BRIGHTNESS SUPPORT_BRIGHTNESS
@ -132,7 +134,7 @@ class NanoleafLight(LightEntity):
| SUPPORT_TRANSITION | SUPPORT_TRANSITION
) )
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Instruct the light to turn on.""" """Instruct the light to turn on."""
brightness = kwargs.get(ATTR_BRIGHTNESS) brightness = kwargs.get(ATTR_BRIGHTNESS)
hs_color = kwargs.get(ATTR_HS_COLOR) hs_color = kwargs.get(ATTR_HS_COLOR)
@ -166,7 +168,7 @@ class NanoleafLight(LightEntity):
) )
await self._nanoleaf.set_effect(effect) await self._nanoleaf.set_effect(effect)
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off.""" """Instruct the light to turn off."""
transition = kwargs.get(ATTR_TRANSITION) transition = kwargs.get(ATTR_TRANSITION)
await self._nanoleaf.turn_off(transition) await self._nanoleaf.turn_off(transition)

View File

@ -759,6 +759,17 @@ no_implicit_optional = true
warn_return_any = true warn_return_any = true
warn_unreachable = true warn_unreachable = true
[mypy-homeassistant.components.nanoleaf.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.neato.*] [mypy-homeassistant.components.neato.*]
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true