Improve type hints in light [s-z] (#75946)

This commit is contained in:
epenet 2022-07-31 13:50:24 +02:00 committed by GitHub
parent 90458ee200
commit 11a19c2612
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 79 additions and 60 deletions

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
from scsgate.tasks import ToggleStatusTask
import voluptuous as vol
@ -76,7 +77,7 @@ class SCSGateLight(LightEntity):
"""Return true if light is on."""
return self._toggled
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the device on."""
self._scsgate.append_task(ToggleStatusTask(target=self._scs_id, toggled=True))
@ -84,7 +85,7 @@ class SCSGateLight(LightEntity):
self._toggled = True
self.schedule_update_ha_state()
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the device off."""
self._scsgate.append_task(ToggleStatusTask(target=self._scs_id, toggled=False))

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
import aiohttp
@ -47,16 +48,16 @@ class SisyphusLight(LightEntity):
self._name = name
self._table = table
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Add listeners after this object has been initialized."""
self._table.add_listener(self.async_write_ha_state)
async def async_update(self):
async def async_update(self) -> None:
"""Force update the table state."""
await self._table.refresh()
@property
def available(self):
def available(self) -> bool:
"""Return true if the table is responding to heartbeats."""
return self._table.is_connected
@ -80,12 +81,12 @@ class SisyphusLight(LightEntity):
"""Return the current brightness of the table's ring light."""
return self._table.brightness * 255
async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Put the table to sleep."""
await self._table.sleep()
_LOGGER.debug("Sisyphus table %s: sleep")
async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Wake up the table if necessary, optionally changes brightness."""
if not self.is_on:
await self._table.wakeup()

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import asyncio
from collections.abc import Sequence
from typing import Any
from pysmartthings import Capability
@ -96,7 +97,7 @@ class SmartThingsLight(SmartThingsEntity, LightEntity):
return features
async def async_turn_on(self, **kwargs) -> None:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
tasks = []
# Color temperature
@ -121,7 +122,7 @@ class SmartThingsLight(SmartThingsEntity, LightEntity):
# the entity state ahead of receiving the confirming push updates
self.async_schedule_update_ha_state(True)
async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
# Switch/transition
if (
@ -136,7 +137,7 @@ class SmartThingsLight(SmartThingsEntity, LightEntity):
# the entity state ahead of receiving the confirming push updates
self.async_schedule_update_ha_state(True)
async def async_update(self):
async def async_update(self) -> None:
"""Update entity attributes when the device status has changed."""
# Brightness and transition
if self._supported_features & SUPPORT_BRIGHTNESS:

View file

@ -1,4 +1,6 @@
"""Platform for light integration."""
from typing import Any
from smarttub import SpaLight
from homeassistant.components.light import (
@ -125,7 +127,7 @@ class SmartTubLight(SmartTubEntity, LightEntity):
return SpaLight.LightMode[effect.upper()]
async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
mode = self._effect_to_light_mode(kwargs.get(ATTR_EFFECT, DEFAULT_LIGHT_EFFECT))
@ -136,7 +138,7 @@ class SmartTubLight(SmartTubEntity, LightEntity):
await self.light.set_mode(mode, intensity)
await self.coordinator.async_request_refresh()
async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
await self.light.set_mode(SpaLight.LightMode.OFF, 0)
await self.coordinator.async_request_refresh()

View file

@ -1,5 +1,6 @@
"""Support for Tellstick lights using Tellstick Net."""
import logging
from typing import Any
from homeassistant.components import light, tellduslive
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
@ -58,7 +59,7 @@ class TelldusLiveLight(TelldusLiveEntity, LightEntity):
"""Return true if light is on."""
return self.device.is_on
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
brightness = kwargs.get(ATTR_BRIGHTNESS, self._last_brightness)
if brightness == 0:
@ -70,7 +71,7 @@ class TelldusLiveLight(TelldusLiveEntity, LightEntity):
self.device.dim(level=brightness)
self.changed()
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
self.device.turn_off()
self.changed()

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
import tikteck
import voluptuous as vol
@ -111,7 +112,7 @@ class TikteckLight(LightEntity):
"""Set the bulb state."""
return self._bulb.set_state(red, green, blue, brightness)
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the specified light on."""
self._state = True
@ -128,7 +129,7 @@ class TikteckLight(LightEntity):
self.set_state(rgb[0], rgb[1], rgb[2], self.brightness)
self.schedule_update_ha_state()
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the specified light off."""
self._state = False
self.set_state(0, 0, 0, 0)

View file

@ -140,7 +140,7 @@ class TwinklyLight(LightEntity):
return attributes
async def async_turn_on(self, **kwargs) -> None:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn device on."""
if ATTR_BRIGHTNESS in kwargs:
brightness = int(int(kwargs[ATTR_BRIGHTNESS]) / 2.55)
@ -183,7 +183,7 @@ class TwinklyLight(LightEntity):
if not self._is_on:
await self._client.turn_on()
async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn device off."""
await self._client.turn_off()

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
from unifiled import unifiled
import voluptuous as vol
@ -98,7 +99,7 @@ class UnifiLedLight(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."""
self._api.setdevicebrightness(
self._unique_id,
@ -106,11 +107,11 @@ class UnifiLedLight(LightEntity):
)
self._api.setdeviceoutput(self._unique_id, 1)
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off."""
self._api.setdeviceoutput(self._unique_id, 0)
def update(self):
def update(self) -> None:
"""Update the light states."""
self._state = self._api.getlightstate(self._unique_id)
self._brightness = self._api.convertfrom100to255(

View file

@ -1,4 +1,6 @@
"""Platform for UPB light integration."""
from typing import Any
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_FLASH,
@ -85,7 +87,7 @@ class UpbLight(UpbAttachedEntity, LightEntity):
"""Get the current brightness."""
return self._brightness != 0
async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the light."""
if flash := kwargs.get(ATTR_FLASH):
await self.async_light_blink(0.5 if flash == "short" else 1.5)
@ -94,7 +96,7 @@ class UpbLight(UpbAttachedEntity, LightEntity):
brightness = round(kwargs.get(ATTR_BRIGHTNESS, 255) / 2.55)
self._element.turn_on(brightness, rate)
async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the device."""
rate = kwargs.get(ATTR_TRANSITION, -1)
self._element.turn_off(rate)
@ -114,7 +116,7 @@ class UpbLight(UpbAttachedEntity, LightEntity):
blink_rate = int(blink_rate * 60) # Convert seconds to 60 hz pulses
self._element.blink(blink_rate)
async def async_update(self):
async def async_update(self) -> None:
"""Request the device to update its status."""
self._element.update_status()

View file

@ -1,6 +1,8 @@
"""Support for Velux lights."""
from __future__ import annotations
from typing import Any
from pyvlx import Intensity, LighteningDevice
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
@ -43,7 +45,7 @@ class VeluxLight(VeluxEntity, LightEntity):
"""Return true if light is on."""
return not self.node.intensity.off and self.node.intensity.known
async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Instruct the light to turn on."""
if ATTR_BRIGHTNESS in kwargs:
intensity_percent = int(100 - kwargs[ATTR_BRIGHTNESS] / 255 * 100)
@ -54,6 +56,6 @@ class VeluxLight(VeluxEntity, LightEntity):
else:
await self.node.turn_on(wait_for_completion=True)
async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off."""
await self.node.turn_off(wait_for_completion=True)

View file

@ -88,7 +88,7 @@ class VeraLight(VeraDevice[veraApi.VeraDimmer], LightEntity):
self._state = True
self.schedule_update_ha_state(True)
def turn_off(self, **kwargs: Any):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
self.vera_device.switch_off()
self._state = False

View file

@ -1,5 +1,6 @@
"""Support for VeSync bulbs and wall dimmers."""
import logging
from typing import Any
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
@ -83,7 +84,7 @@ class VeSyncBaseLight(VeSyncDevice, LightEntity):
# convert percent brightness to ha expected range
return round((max(1, brightness_value) / 100) * 255)
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the device on."""
attribute_adjustment_only = False
# set white temperature

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import logging
from subprocess import STDOUT, CalledProcessError, check_output
from typing import Any
import voluptuous as vol
@ -87,7 +88,7 @@ class X10Light(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."""
if self._is_cm11a:
x10_command(f"on {self._id}")
@ -96,7 +97,7 @@ class X10Light(LightEntity):
self._brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
self._state = True
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off."""
if self._is_cm11a:
x10_command(f"off {self._id}")
@ -104,7 +105,7 @@ class X10Light(LightEntity):
x10_command(f"foff {self._id}")
self._state = False
def update(self):
def update(self) -> None:
"""Fetch update state."""
if self._is_cm11a:
self._state = bool(get_unit_status(self._id))

View file

@ -2,6 +2,7 @@
import binascii
import logging
import struct
from typing import Any
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
@ -113,7 +114,7 @@ class XiaomiGatewayLight(XiaomiDevice, LightEntity):
self._state = True
self.schedule_update_ha_state()
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
if self._write_to_hub(self._sid, **{self._data_key: 0}):
self._state = False

View file

@ -7,6 +7,7 @@ from datetime import timedelta
from functools import partial
import logging
from math import ceil
from typing import Any
from miio import (
Ceil,
@ -292,7 +293,7 @@ class XiaomiPhilipsAbstractLight(XiaomiMiioEntity, LightEntity):
return False
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]
@ -311,11 +312,11 @@ class XiaomiPhilipsAbstractLight(XiaomiMiioEntity, LightEntity):
else:
await self._try_command("Turning the light on failed.", self._device.on)
async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
await self._try_command("Turning the light off failed.", self._device.off)
async def async_update(self):
async def async_update(self) -> None:
"""Fetch state from the device."""
try:
state = await self.hass.async_add_executor_job(self._device.status)
@ -341,7 +342,7 @@ class XiaomiPhilipsGenericLight(XiaomiPhilipsAbstractLight):
self._state_attrs.update({ATTR_SCENE: None, ATTR_DELAYED_TURN_OFF: None})
async def async_update(self):
async def async_update(self) -> None:
"""Fetch state from the device."""
try:
state = await self.hass.async_add_executor_job(self._device.status)
@ -430,7 +431,7 @@ class XiaomiPhilipsBulb(XiaomiPhilipsGenericLight):
"""Return the warmest color_temp that this light supports."""
return 333
async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
if ATTR_COLOR_TEMP in kwargs:
color_temp = kwargs[ATTR_COLOR_TEMP]
@ -497,7 +498,7 @@ class XiaomiPhilipsBulb(XiaomiPhilipsGenericLight):
else:
await self._try_command("Turning the light on failed.", self._device.on)
async def async_update(self):
async def async_update(self) -> None:
"""Fetch state from the device."""
try:
state = await self.hass.async_add_executor_job(self._device.status)
@ -556,7 +557,7 @@ class XiaomiPhilipsCeilingLamp(XiaomiPhilipsBulb):
"""Return the warmest color_temp that this light supports."""
return 370
async def async_update(self):
async def async_update(self) -> None:
"""Fetch state from the device."""
try:
state = await self.hass.async_add_executor_job(self._device.status)
@ -602,7 +603,7 @@ class XiaomiPhilipsEyecareLamp(XiaomiPhilipsGenericLight):
{ATTR_REMINDER: None, ATTR_NIGHT_LIGHT_MODE: None, ATTR_EYECARE_MODE: None}
)
async def async_update(self):
async def async_update(self) -> None:
"""Fetch state from the device."""
try:
state = await self.hass.async_add_executor_job(self._device.status)
@ -714,7 +715,7 @@ class XiaomiPhilipsEyecareLampAmbientLight(XiaomiPhilipsAbstractLight):
unique_id = f"{unique_id}-ambient"
super().__init__(name, device, entry, unique_id)
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]
@ -739,13 +740,13 @@ class XiaomiPhilipsEyecareLampAmbientLight(XiaomiPhilipsAbstractLight):
"Turning the ambient light on failed.", self._device.ambient_on
)
async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
await self._try_command(
"Turning the ambient light off failed.", self._device.ambient_off
)
async def async_update(self):
async def async_update(self) -> None:
"""Fetch state from the device."""
try:
state = await self.hass.async_add_executor_job(self._device.status)
@ -805,7 +806,7 @@ class XiaomiPhilipsMoonlightLamp(XiaomiPhilipsBulb):
return ColorMode.HS
return ColorMode.COLOR_TEMP
async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
if ATTR_COLOR_TEMP in kwargs:
color_temp = kwargs[ATTR_COLOR_TEMP]
@ -905,7 +906,7 @@ class XiaomiPhilipsMoonlightLamp(XiaomiPhilipsBulb):
else:
await self._try_command("Turning the light on failed.", self._device.on)
async def async_update(self):
async def async_update(self) -> None:
"""Fetch state from the device."""
try:
state = await self.hass.async_add_executor_job(self._device.status)
@ -996,7 +997,7 @@ class XiaomiGatewayLight(LightEntity):
"""Return the hs color value."""
return self._hs
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
if ATTR_HS_COLOR in kwargs:
rgb = color.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
@ -1012,7 +1013,7 @@ class XiaomiGatewayLight(LightEntity):
self.schedule_update_ha_state()
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
self._gateway.light.set_rgb(0, self._rgb)
self.schedule_update_ha_state()
@ -1071,7 +1072,7 @@ class XiaomiGatewayBulb(XiaomiGatewayDevice, LightEntity):
"""Return max cct."""
return self._sub_device.status["cct_max"]
async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Instruct the light to turn on."""
await self.hass.async_add_executor_job(self._sub_device.on)
@ -1087,6 +1088,6 @@ class XiaomiGatewayBulb(XiaomiGatewayDevice, LightEntity):
self._sub_device.set_brightness, brightness
)
async def async_turn_off(self, **kwargsf):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off."""
await self.hass.async_add_executor_job(self._sub_device.off)

View file

@ -4,6 +4,7 @@ from __future__ import annotations
import asyncio
import logging
import math
from typing import Any
import voluptuous as vol
import yeelight
@ -442,7 +443,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
self._async_cancel_pending_state_check()
self.async_write_ha_state()
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Handle entity which will be added."""
self.async_on_remove(
async_dispatcher_connect(
@ -585,7 +586,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
"""Return yeelight device."""
return self._device
async def async_update(self):
async def async_update(self) -> None:
"""Update light properties."""
await self.device.async_update(True)
@ -774,7 +775,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
power_mode=self._turn_on_power_mode,
)
async def async_turn_on(self, **kwargs) -> None:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the bulb on."""
brightness = kwargs.get(ATTR_BRIGHTNESS)
colortemp = kwargs.get(ATTR_COLOR_TEMP)
@ -836,7 +837,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
"""Turn off with a given transition duration wrapped with _async_cmd."""
await self._bulb.async_turn_off(duration=duration, light_type=self.light_type)
async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off."""
if not self.is_on:
return

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
import voluptuous as vol
import yeelightsunflower
@ -87,7 +88,7 @@ class SunflowerBulb(LightEntity):
"""Return the color property."""
return color_util.color_RGB_to_hs(*self._rgb_color)
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Instruct the light to turn on, optionally set colour/brightness."""
# when no arguments, just turn light on (full brightness)
if not kwargs:
@ -104,11 +105,11 @@ class SunflowerBulb(LightEntity):
bright = int(kwargs[ATTR_BRIGHTNESS] / 255 * 100)
self._light.set_brightness(bright)
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off."""
self._light.turn_off()
def update(self):
def update(self) -> None:
"""Fetch new state data for this light and update local values."""
self._light.update()
self._available = self._light.available

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
import voluptuous as vol
from zengge import zengge
@ -123,7 +124,7 @@ class ZenggeLight(LightEntity):
"""Set the white state."""
return self._bulb.set_white(white)
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the specified light on."""
self._state = True
self._bulb.on()
@ -153,12 +154,12 @@ class ZenggeLight(LightEntity):
)
self._set_rgb(*rgb)
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the specified light off."""
self._state = False
self._bulb.off()
def update(self):
def update(self) -> None:
"""Synchronise internal state with the actual light state."""
rgb = self._bulb.get_colour()
hsv = color_util.color_RGB_to_hsv(*rgb)

View file

@ -52,7 +52,7 @@ class ZWaveMeRGB(ZWaveMeEntity, LightEntity):
"""Turn the device on."""
self.controller.zwave_api.send_command(self.device.id, "off")
def turn_on(self, **kwargs: Any):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the device on."""
color = kwargs.get(ATTR_RGB_COLOR)