Improve type hints in light [a-i] (#75936)

* Improve type hints in ads light

* Improve type hints in avea light

* Improve type hints in avion light

* Improve type hints in broadlink light

* More type hints

* One more
This commit is contained in:
epenet 2022-07-31 20:46:13 +02:00 committed by GitHub
parent c795597511
commit 20fec104e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 88 additions and 61 deletions

View file

@ -1,6 +1,8 @@
"""Support for ADS light sources."""
from __future__ import annotations
from typing import Any
import pyads
import voluptuous as vol
@ -66,7 +68,7 @@ class AdsLight(AdsEntity, LightEntity):
self._attr_color_mode = ColorMode.ONOFF
self._attr_supported_color_modes = {ColorMode.ONOFF}
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Register device notification."""
await self.async_initialize_device(self._ads_var, pyads.PLCTYPE_BOOL)
@ -87,7 +89,7 @@ class AdsLight(AdsEntity, LightEntity):
"""Return True if the entity is on."""
return self._state_dict[STATE_KEY_STATE]
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the light on or set a specific dimmer value."""
brightness = kwargs.get(ATTR_BRIGHTNESS)
self._ads_hub.write_by_name(self._ads_var, True, pyads.PLCTYPE_BOOL)
@ -97,6 +99,6 @@ class AdsLight(AdsEntity, LightEntity):
self._ads_var_brightness, brightness, pyads.PLCTYPE_UINT
)
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
self._ads_hub.write_by_name(self._ads_var, False, pyads.PLCTYPE_BOOL)

View file

@ -1,6 +1,8 @@
"""Support for the Elgato Avea lights."""
from __future__ import annotations
from typing import Any
import avea # pylint: disable=import-error
from homeassistant.components.light import (
@ -46,7 +48,7 @@ class AveaLight(LightEntity):
self._attr_name = light.name
self._attr_brightness = light.brightness
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Instruct the light to turn on."""
if not kwargs:
self._light.set_brightness(4095)
@ -58,11 +60,11 @@ class AveaLight(LightEntity):
rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
self._light.set_rgb(rgb[0], rgb[1], rgb[2])
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off."""
self._light.set_brightness(0)
def update(self):
def update(self) -> None:
"""Fetch new state data for this light.
This is the only method that should fetch new data for Home Assistant.

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import importlib
import time
from typing import Any
import voluptuous as vol
@ -103,7 +104,7 @@ class AvionLight(LightEntity):
self._switch.connect()
return True
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the specified or all lights on."""
if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None:
self._attr_brightness = brightness
@ -111,7 +112,7 @@ class AvionLight(LightEntity):
self.set_state(self.brightness)
self._attr_is_on = True
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the specified or all lights off."""
self.set_state(0)
self._attr_is_on = False

View file

@ -1,5 +1,6 @@
"""Support for Broadlink lights."""
import logging
from typing import Any
from broadlink.exceptions import BroadlinkException
@ -88,7 +89,7 @@ class BroadlinkLight(BroadlinkEntity, LightEntity):
# Scenes are not yet supported.
self._attr_color_mode = ColorMode.UNKNOWN
async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the light."""
state = {"pwr": 1}
@ -122,7 +123,7 @@ class BroadlinkLight(BroadlinkEntity, LightEntity):
await self._async_set_state(state)
async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the light."""
await self._async_set_state({"pwr": 0})

View file

@ -4,6 +4,7 @@ from __future__ import annotations
import asyncio
from datetime import timedelta
import logging
from typing import Any
from pyControl4.error_handling import C4Exception
from pyControl4.light import C4Light
@ -197,7 +198,7 @@ class Control4Light(Control4Entity, LightEntity):
return LightEntityFeature.TRANSITION
return 0
async def async_turn_on(self, **kwargs) -> None:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on."""
c4_light = self.create_api_object()
if self._is_dimmer:
@ -220,7 +221,7 @@ class Control4Light(Control4Entity, LightEntity):
await asyncio.sleep(delay_time)
await self.coordinator.async_request_refresh()
async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
c4_light = self.create_api_object()
if self._is_dimmer:

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
# pylint: disable=import-error
from decora_wifi import DecoraWiFiSession
@ -111,7 +112,7 @@ class DecoraWifiLight(LightEntity):
return {self.color_mode}
@property
def supported_features(self):
def supported_features(self) -> int:
"""Return supported features."""
if self._switch.canSetLevel:
return LightEntityFeature.TRANSITION
@ -137,9 +138,9 @@ class DecoraWifiLight(LightEntity):
"""Return true if switch is on."""
return self._switch.power == "ON"
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Instruct the switch to turn on & adjust brightness."""
attribs = {"power": "ON"}
attribs: dict[str, Any] = {"power": "ON"}
if ATTR_BRIGHTNESS in kwargs:
min_level = self._switch.data.get("minLevel", 0)
@ -157,7 +158,7 @@ class DecoraWifiLight(LightEntity):
except ValueError:
_LOGGER.error("Failed to turn on myLeviton switch")
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Instruct the switch to turn off."""
attribs = {"power": "OFF"}
try:
@ -165,7 +166,7 @@ class DecoraWifiLight(LightEntity):
except ValueError:
_LOGGER.error("Failed to turn off myLeviton switch")
def update(self):
def update(self) -> None:
"""Fetch new state data for this switch."""
try:
self._switch.refresh()

View file

@ -1,5 +1,7 @@
"""Support for Dynalite channels as lights."""
from typing import Any
from homeassistant.components.light import ColorMode, LightEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -35,10 +37,10 @@ class DynaliteLight(DynaliteBase, LightEntity):
"""Return true if device is on."""
return self._device.is_on
async def async_turn_on(self, **kwargs) -> None:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
await self._device.async_turn_on(**kwargs)
async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
await self._device.async_turn_off(**kwargs)

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import math
from typing import Any
from enocean.utils import combine_hex
import voluptuous as vol
@ -80,7 +81,7 @@ class EnOceanLight(EnOceanEntity, LightEntity):
"""If light is on."""
return self._on_state
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the light source on or sets a specific dimmer value."""
if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None:
self._brightness = brightness
@ -94,7 +95,7 @@ class EnOceanLight(EnOceanEntity, LightEntity):
self.send_command(command, [], 0x01)
self._on_state = True
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the light source off."""
command = [0xA5, 0x02, 0x00, 0x01, 0x09]
command.extend(self._sender_id)

View file

@ -1,6 +1,8 @@
"""Support for Eufy lights."""
from __future__ import annotations
from typing import Any
import lakeside
from homeassistant.components.light import (
@ -59,7 +61,7 @@ class EufyLight(LightEntity):
self._attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS}
self._bulb.connect()
def update(self):
def update(self) -> None:
"""Synchronise state from the bulb."""
self._bulb.update()
if self._bulb.power:
@ -93,12 +95,12 @@ class EufyLight(LightEntity):
return int(self._brightness * 255 / 100)
@property
def min_mireds(self):
def min_mireds(self) -> int:
"""Return minimum supported color temperature."""
return kelvin_to_mired(EUFY_MAX_KELVIN)
@property
def max_mireds(self):
def max_mireds(self) -> int:
"""Return maximum supported color temperature."""
return kelvin_to_mired(EUFY_MIN_KELVIN)
@ -116,7 +118,7 @@ class EufyLight(LightEntity):
return self._hs
@property
def color_mode(self) -> str | None:
def color_mode(self) -> ColorMode:
"""Return the color mode of the light."""
if self._type == "T1011":
return ColorMode.BRIGHTNESS
@ -127,7 +129,7 @@ class EufyLight(LightEntity):
return ColorMode.COLOR_TEMP
return ColorMode.HS
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the specified light on."""
brightness = kwargs.get(ATTR_BRIGHTNESS)
colortemp = kwargs.get(ATTR_COLOR_TEMP)
@ -169,7 +171,7 @@ class EufyLight(LightEntity):
power=True, brightness=brightness, temperature=temp, colors=rgb
)
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the specified light off."""
try:
self._bulb.set_state(power=False)

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
from homeassistant.config_entries import ConfigEntry
@ -82,14 +83,14 @@ class FirmataLight(FirmataPinEntity, LightEntity):
"""Return the brightness of the light."""
return self._api.state
async def async_turn_on(self, **kwargs) -> None:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on light."""
level = kwargs.get(ATTR_BRIGHTNESS, self._last_on_level)
await self._api.set_level(level)
self.async_write_ha_state()
self._last_on_level = level
async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off light."""
await self._api.set_level(0)
self.async_write_ha_state()

View file

@ -1,6 +1,8 @@
"""Support for lights."""
from __future__ import annotations
from typing import Any
from fjaraskupan import COMMAND_LIGHT_ON_OFF, Device
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
@ -45,7 +47,7 @@ class Light(CoordinatorEntity[Coordinator], LightEntity):
self._attr_unique_id = device.address
self._attr_device_info = device_info
async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
if ATTR_BRIGHTNESS in kwargs:
await self._device.send_dim(int(kwargs[ATTR_BRIGHTNESS] * (100.0 / 255.0)))
@ -54,7 +56,7 @@ class Light(CoordinatorEntity[Coordinator], LightEntity):
await self._device.send_command(COMMAND_LIGHT_ON_OFF)
self.coordinator.async_set_updated_data(self._device.state)
async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
if self.is_on:
await self._device.send_command(COMMAND_LIGHT_ON_OFF)

View file

@ -1,6 +1,8 @@
"""Support for FutureNow Ethernet unit outputs as Lights."""
from __future__ import annotations
from typing import Any
import pyfnip
import voluptuous as vol
@ -106,18 +108,18 @@ class FutureNowLight(LightEntity):
return self._brightness
@property
def color_mode(self) -> str:
def color_mode(self) -> ColorMode:
"""Return the color mode of the light."""
if self._dimmable:
return ColorMode.BRIGHTNESS
return ColorMode.ONOFF
@property
def supported_color_modes(self) -> set[str] | None:
def supported_color_modes(self) -> set[ColorMode]:
"""Flag supported color modes."""
return {self.color_mode}
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
if self._dimmable:
level = kwargs.get(ATTR_BRIGHTNESS, self._last_brightness)
@ -125,13 +127,13 @@ class FutureNowLight(LightEntity):
level = 255
self._light.turn_on(to_futurenow_level(level))
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
self._light.turn_off()
if self._brightness:
self._last_brightness = self._brightness
def update(self):
def update(self) -> None:
"""Fetch new state data for this light."""
state = int(self._light.is_on())
self._state = bool(state)

View file

@ -4,6 +4,7 @@ from __future__ import annotations
from datetime import timedelta
import logging
import os
from typing import Any
import greenwavereality as greenwave
import voluptuous as vol
@ -99,17 +100,17 @@ class GreenwaveLight(LightEntity):
"""Return true if light is on."""
return self._state
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Instruct the light to turn on."""
temp_brightness = int((kwargs.get(ATTR_BRIGHTNESS, 255) / 255) * 100)
greenwave.set_brightness(self._host, self._did, temp_brightness, self._token)
greenwave.turn_on(self._host, self._did, self._token)
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off."""
greenwave.turn_off(self._host, self._did, self._token)
def update(self):
def update(self) -> None:
"""Fetch new state data for this light."""
self._gatewaydata.update()
bulbs = self._gatewaydata.greenwave

View file

@ -1,6 +1,8 @@
"""Support for Homematic lights."""
from __future__ import annotations
from typing import Any
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
@ -80,9 +82,9 @@ class HMLight(HMDevice, LightEntity):
return color_modes
@property
def supported_features(self):
def supported_features(self) -> int:
"""Flag supported features."""
features = LightEntityFeature.TRANSITION
features: int = LightEntityFeature.TRANSITION
if "PROGRAM" in self._hmdevice.WRITENODE:
features |= LightEntityFeature.EFFECT
return features
@ -117,7 +119,7 @@ class HMLight(HMDevice, LightEntity):
return None
return self._hmdevice.get_effect()
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the light on and/or change color or color effect settings."""
if ATTR_TRANSITION in kwargs:
self._hmdevice.setValue("RAMP_TIME", kwargs[ATTR_TRANSITION], self._channel)
@ -146,7 +148,7 @@ class HMLight(HMDevice, LightEntity):
if ATTR_EFFECT in kwargs:
self._hmdevice.set_effect(kwargs[ATTR_EFFECT])
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
if ATTR_TRANSITION in kwargs:
self._hmdevice.setValue("RAMP_TIME", kwargs[ATTR_TRANSITION], self._channel)

View file

@ -81,11 +81,11 @@ class HomematicipLight(HomematicipGenericEntity, LightEntity):
"""Return true if light is on."""
return self._device.on
async def async_turn_on(self, **kwargs) -> None:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
await self._device.turn_on()
async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
await self._device.turn_off()
@ -125,7 +125,7 @@ class HomematicipMultiDimmer(HomematicipGenericEntity, LightEntity):
(self._device.functionalChannels[self._channel].dimLevel or 0.0) * 255
)
async def async_turn_on(self, **kwargs) -> None:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the dimmer on."""
if ATTR_BRIGHTNESS in kwargs:
await self._device.set_dim_level(
@ -134,7 +134,7 @@ class HomematicipMultiDimmer(HomematicipGenericEntity, LightEntity):
else:
await self._device.set_dim_level(1, self._channel)
async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the dimmer off."""
await self._device.set_dim_level(0, self._channel)
@ -213,7 +213,7 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
"""Return a unique ID."""
return f"{self.__class__.__name__}_{self._post}_{self._device.id}"
async def async_turn_on(self, **kwargs) -> None:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
# Use hs_color from kwargs,
# if not applicable use current hs_color.
@ -241,7 +241,7 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
rampTime=transition,
)
async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
simple_rgb_color = self._func_channel.simpleRGBColorState
transition = kwargs.get(ATTR_TRANSITION, 0.5)

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
from pyhomeworks.pyhomeworks import HW_LIGHT_CHANGED
@ -50,7 +51,7 @@ class HomeworksLight(HomeworksDevice, LightEntity):
self._level = 0
self._prev_level = 0
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Call when entity is added to hass."""
signal = f"homeworks_entity_{self._addr}"
_LOGGER.debug("connecting %s", signal)
@ -59,7 +60,7 @@ class HomeworksLight(HomeworksDevice, LightEntity):
)
self._controller.request_dimmer_level(self._addr)
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn on the light."""
if ATTR_BRIGHTNESS in kwargs:
new_level = kwargs[ATTR_BRIGHTNESS]
@ -69,7 +70,7 @@ class HomeworksLight(HomeworksDevice, LightEntity):
new_level = self._prev_level
self._set_brightness(new_level)
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn off the light."""
self._set_brightness(0)

View file

@ -1,6 +1,8 @@
"""Support for Aqualink pool lights."""
from __future__ import annotations
from typing import Any
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_EFFECT,
@ -46,7 +48,7 @@ class HassAqualinkLight(AqualinkEntity, LightEntity):
return self.dev.is_on
@refresh_system
async def async_turn_on(self, **kwargs) -> None:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the light.
This handles brightness and light effects for lights that do support
@ -63,7 +65,7 @@ class HassAqualinkLight(AqualinkEntity, LightEntity):
await await_or_reraise(self.dev.turn_on())
@refresh_system
async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the light."""
await await_or_reraise(self.dev.turn_off())
@ -93,7 +95,7 @@ class HassAqualinkLight(AqualinkEntity, LightEntity):
return ColorMode.ONOFF
@property
def supported_color_modes(self) -> set[str] | None:
def supported_color_modes(self) -> set[ColorMode]:
"""Flag supported color modes."""
return {self.color_mode}

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import math
from typing import Any
from iglo import Lamp
from iglo.lamp import MODE_WHITE
@ -86,14 +87,14 @@ class IGloLamp(LightEntity):
return color_util.color_temperature_kelvin_to_mired(self._lamp.state()["white"])
@property
def min_mireds(self):
def min_mireds(self) -> int:
"""Return the coldest color_temp that this light supports."""
return math.ceil(
color_util.color_temperature_kelvin_to_mired(self._lamp.max_kelvin)
)
@property
def max_mireds(self):
def max_mireds(self) -> int:
"""Return the warmest color_temp that this light supports."""
return math.ceil(
color_util.color_temperature_kelvin_to_mired(self._lamp.min_kelvin)
@ -119,7 +120,7 @@ class IGloLamp(LightEntity):
"""Return true if light is on."""
return self._lamp.state()["on"]
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
if not self.is_on:
self._lamp.switch(True)
@ -145,6 +146,6 @@ class IGloLamp(LightEntity):
self._lamp.effect(effect)
return
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
self._lamp.switch(False)

View file

@ -1,6 +1,8 @@
"""Support for IHC lights."""
from __future__ import annotations
from typing import Any
from ihcsdk.ihccontroller import IHCController
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
@ -90,7 +92,7 @@ class IhcLight(IHCDevice, LightEntity):
"""Return true if light is on."""
return self._state
async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
if ATTR_BRIGHTNESS in kwargs:
brightness = kwargs[ATTR_BRIGHTNESS]
@ -108,7 +110,7 @@ class IhcLight(IHCDevice, LightEntity):
else:
await async_set_bool(self.hass, self.ihc_controller, self.ihc_id, True)
async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
if self._dimmable:
await async_set_int(self.hass, self.ihc_controller, self.ihc_id, 0)