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.""" """Support for ADS light sources."""
from __future__ import annotations from __future__ import annotations
from typing import Any
import pyads import pyads
import voluptuous as vol import voluptuous as vol
@ -66,7 +68,7 @@ class AdsLight(AdsEntity, LightEntity):
self._attr_color_mode = ColorMode.ONOFF self._attr_color_mode = ColorMode.ONOFF
self._attr_supported_color_modes = {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.""" """Register device notification."""
await self.async_initialize_device(self._ads_var, pyads.PLCTYPE_BOOL) 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 True if the entity is on."""
return self._state_dict[STATE_KEY_STATE] 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.""" """Turn the light on or set a specific dimmer value."""
brightness = kwargs.get(ATTR_BRIGHTNESS) brightness = kwargs.get(ATTR_BRIGHTNESS)
self._ads_hub.write_by_name(self._ads_var, True, pyads.PLCTYPE_BOOL) 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 self._ads_var_brightness, brightness, pyads.PLCTYPE_UINT
) )
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn the light off.""" """Turn the light off."""
self._ads_hub.write_by_name(self._ads_var, False, pyads.PLCTYPE_BOOL) 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.""" """Support for the Elgato Avea lights."""
from __future__ import annotations from __future__ import annotations
from typing import Any
import avea # pylint: disable=import-error import avea # pylint: disable=import-error
from homeassistant.components.light import ( from homeassistant.components.light import (
@ -46,7 +48,7 @@ class AveaLight(LightEntity):
self._attr_name = light.name self._attr_name = light.name
self._attr_brightness = light.brightness self._attr_brightness = light.brightness
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Instruct the light to turn on.""" """Instruct the light to turn on."""
if not kwargs: if not kwargs:
self._light.set_brightness(4095) self._light.set_brightness(4095)
@ -58,11 +60,11 @@ class AveaLight(LightEntity):
rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
self._light.set_rgb(rgb[0], rgb[1], rgb[2]) 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.""" """Instruct the light to turn off."""
self._light.set_brightness(0) self._light.set_brightness(0)
def update(self): def update(self) -> None:
"""Fetch new state data for this light. """Fetch new state data for this light.
This is the only method that should fetch new data for Home Assistant. 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 importlib
import time import time
from typing import Any
import voluptuous as vol import voluptuous as vol
@ -103,7 +104,7 @@ class AvionLight(LightEntity):
self._switch.connect() self._switch.connect()
return True return True
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Turn the specified or all lights on.""" """Turn the specified or all lights on."""
if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None: if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None:
self._attr_brightness = brightness self._attr_brightness = brightness
@ -111,7 +112,7 @@ class AvionLight(LightEntity):
self.set_state(self.brightness) self.set_state(self.brightness)
self._attr_is_on = True self._attr_is_on = True
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn the specified or all lights off.""" """Turn the specified or all lights off."""
self.set_state(0) self.set_state(0)
self._attr_is_on = False self._attr_is_on = False

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,8 @@
"""Support for lights.""" """Support for lights."""
from __future__ import annotations from __future__ import annotations
from typing import Any
from fjaraskupan import COMMAND_LIGHT_ON_OFF, Device from fjaraskupan import COMMAND_LIGHT_ON_OFF, Device
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity 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_unique_id = device.address
self._attr_device_info = device_info 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.""" """Turn the light on."""
if ATTR_BRIGHTNESS in kwargs: if ATTR_BRIGHTNESS in kwargs:
await self._device.send_dim(int(kwargs[ATTR_BRIGHTNESS] * (100.0 / 255.0))) 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) await self._device.send_command(COMMAND_LIGHT_ON_OFF)
self.coordinator.async_set_updated_data(self._device.state) 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.""" """Turn the entity off."""
if self.is_on: if self.is_on:
await self._device.send_command(COMMAND_LIGHT_ON_OFF) await self._device.send_command(COMMAND_LIGHT_ON_OFF)

View file

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

View file

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

View file

@ -1,6 +1,8 @@
"""Support for Homematic lights.""" """Support for Homematic lights."""
from __future__ import annotations from __future__ import annotations
from typing import Any
from homeassistant.components.light import ( from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP, ATTR_COLOR_TEMP,
@ -80,9 +82,9 @@ class HMLight(HMDevice, LightEntity):
return color_modes return color_modes
@property @property
def supported_features(self): def supported_features(self) -> int:
"""Flag supported features.""" """Flag supported features."""
features = LightEntityFeature.TRANSITION features: int = LightEntityFeature.TRANSITION
if "PROGRAM" in self._hmdevice.WRITENODE: if "PROGRAM" in self._hmdevice.WRITENODE:
features |= LightEntityFeature.EFFECT features |= LightEntityFeature.EFFECT
return features return features
@ -117,7 +119,7 @@ class HMLight(HMDevice, LightEntity):
return None return None
return self._hmdevice.get_effect() 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.""" """Turn the light on and/or change color or color effect settings."""
if ATTR_TRANSITION in kwargs: if ATTR_TRANSITION in kwargs:
self._hmdevice.setValue("RAMP_TIME", kwargs[ATTR_TRANSITION], self._channel) self._hmdevice.setValue("RAMP_TIME", kwargs[ATTR_TRANSITION], self._channel)
@ -146,7 +148,7 @@ class HMLight(HMDevice, LightEntity):
if ATTR_EFFECT in kwargs: if ATTR_EFFECT in kwargs:
self._hmdevice.set_effect(kwargs[ATTR_EFFECT]) self._hmdevice.set_effect(kwargs[ATTR_EFFECT])
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn the light off.""" """Turn the light off."""
if ATTR_TRANSITION in kwargs: if ATTR_TRANSITION in kwargs:
self._hmdevice.setValue("RAMP_TIME", kwargs[ATTR_TRANSITION], self._channel) 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 true if light is on."""
return self._device.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.""" """Turn the light on."""
await self._device.turn_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.""" """Turn the light off."""
await self._device.turn_off() await self._device.turn_off()
@ -125,7 +125,7 @@ class HomematicipMultiDimmer(HomematicipGenericEntity, LightEntity):
(self._device.functionalChannels[self._channel].dimLevel or 0.0) * 255 (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.""" """Turn the dimmer on."""
if ATTR_BRIGHTNESS in kwargs: if ATTR_BRIGHTNESS in kwargs:
await self._device.set_dim_level( await self._device.set_dim_level(
@ -134,7 +134,7 @@ class HomematicipMultiDimmer(HomematicipGenericEntity, LightEntity):
else: else:
await self._device.set_dim_level(1, self._channel) 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.""" """Turn the dimmer off."""
await self._device.set_dim_level(0, self._channel) await self._device.set_dim_level(0, self._channel)
@ -213,7 +213,7 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
"""Return a unique ID.""" """Return a unique ID."""
return f"{self.__class__.__name__}_{self._post}_{self._device.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.""" """Turn the light on."""
# Use hs_color from kwargs, # Use hs_color from kwargs,
# if not applicable use current hs_color. # if not applicable use current hs_color.
@ -241,7 +241,7 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
rampTime=transition, rampTime=transition,
) )
async def async_turn_off(self, **kwargs) -> None: async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off.""" """Turn the light off."""
simple_rgb_color = self._func_channel.simpleRGBColorState simple_rgb_color = self._func_channel.simpleRGBColorState
transition = kwargs.get(ATTR_TRANSITION, 0.5) transition = kwargs.get(ATTR_TRANSITION, 0.5)

View file

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

View file

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

View file

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

View file

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