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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,6 +7,7 @@ from datetime import timedelta
from functools import partial from functools import partial
import logging import logging
from math import ceil from math import ceil
from typing import Any
from miio import ( from miio import (
Ceil, Ceil,
@ -292,7 +293,7 @@ class XiaomiPhilipsAbstractLight(XiaomiMiioEntity, LightEntity):
return False return False
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]
@ -311,11 +312,11 @@ class XiaomiPhilipsAbstractLight(XiaomiMiioEntity, LightEntity):
else: else:
await self._try_command("Turning the light on failed.", self._device.on) 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.""" """Turn the light off."""
await self._try_command("Turning the light off failed.", self._device.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.""" """Fetch state from the device."""
try: try:
state = await self.hass.async_add_executor_job(self._device.status) 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}) 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.""" """Fetch state from the device."""
try: try:
state = await self.hass.async_add_executor_job(self._device.status) 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 the warmest color_temp that this light supports."""
return 333 return 333
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_COLOR_TEMP in kwargs: if ATTR_COLOR_TEMP in kwargs:
color_temp = kwargs[ATTR_COLOR_TEMP] color_temp = kwargs[ATTR_COLOR_TEMP]
@ -497,7 +498,7 @@ class XiaomiPhilipsBulb(XiaomiPhilipsGenericLight):
else: else:
await self._try_command("Turning the light on failed.", self._device.on) 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.""" """Fetch state from the device."""
try: try:
state = await self.hass.async_add_executor_job(self._device.status) 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 the warmest color_temp that this light supports."""
return 370 return 370
async def async_update(self): async def async_update(self) -> None:
"""Fetch state from the device.""" """Fetch state from the device."""
try: try:
state = await self.hass.async_add_executor_job(self._device.status) 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} {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.""" """Fetch state from the device."""
try: try:
state = await self.hass.async_add_executor_job(self._device.status) state = await self.hass.async_add_executor_job(self._device.status)
@ -714,7 +715,7 @@ class XiaomiPhilipsEyecareLampAmbientLight(XiaomiPhilipsAbstractLight):
unique_id = f"{unique_id}-ambient" unique_id = f"{unique_id}-ambient"
super().__init__(name, device, entry, unique_id) 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.""" """Turn the light on."""
if ATTR_BRIGHTNESS in kwargs: if ATTR_BRIGHTNESS in kwargs:
brightness = kwargs[ATTR_BRIGHTNESS] brightness = kwargs[ATTR_BRIGHTNESS]
@ -739,13 +740,13 @@ class XiaomiPhilipsEyecareLampAmbientLight(XiaomiPhilipsAbstractLight):
"Turning the ambient light on failed.", self._device.ambient_on "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.""" """Turn the light off."""
await self._try_command( await self._try_command(
"Turning the ambient light off failed.", self._device.ambient_off "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.""" """Fetch state from the device."""
try: try:
state = await self.hass.async_add_executor_job(self._device.status) state = await self.hass.async_add_executor_job(self._device.status)
@ -805,7 +806,7 @@ class XiaomiPhilipsMoonlightLamp(XiaomiPhilipsBulb):
return ColorMode.HS return ColorMode.HS
return ColorMode.COLOR_TEMP return ColorMode.COLOR_TEMP
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_COLOR_TEMP in kwargs: if ATTR_COLOR_TEMP in kwargs:
color_temp = kwargs[ATTR_COLOR_TEMP] color_temp = kwargs[ATTR_COLOR_TEMP]
@ -905,7 +906,7 @@ class XiaomiPhilipsMoonlightLamp(XiaomiPhilipsBulb):
else: else:
await self._try_command("Turning the light on failed.", self._device.on) 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.""" """Fetch state from the device."""
try: try:
state = await self.hass.async_add_executor_job(self._device.status) state = await self.hass.async_add_executor_job(self._device.status)
@ -996,7 +997,7 @@ class XiaomiGatewayLight(LightEntity):
"""Return the hs color value.""" """Return the hs color value."""
return self._hs return self._hs
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Turn the light on.""" """Turn the light on."""
if ATTR_HS_COLOR in kwargs: if ATTR_HS_COLOR in kwargs:
rgb = color.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) rgb = color.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
@ -1012,7 +1013,7 @@ class XiaomiGatewayLight(LightEntity):
self.schedule_update_ha_state() self.schedule_update_ha_state()
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn the light off.""" """Turn the light off."""
self._gateway.light.set_rgb(0, self._rgb) self._gateway.light.set_rgb(0, self._rgb)
self.schedule_update_ha_state() self.schedule_update_ha_state()
@ -1071,7 +1072,7 @@ class XiaomiGatewayBulb(XiaomiGatewayDevice, LightEntity):
"""Return max cct.""" """Return max cct."""
return self._sub_device.status["cct_max"] 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.""" """Instruct the light to turn on."""
await self.hass.async_add_executor_job(self._sub_device.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 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.""" """Instruct the light to turn off."""
await self.hass.async_add_executor_job(self._sub_device.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 asyncio
import logging import logging
import math import math
from typing import Any
import voluptuous as vol import voluptuous as vol
import yeelight import yeelight
@ -442,7 +443,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
self._async_cancel_pending_state_check() self._async_cancel_pending_state_check()
self.async_write_ha_state() 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.""" """Handle entity which will be added."""
self.async_on_remove( self.async_on_remove(
async_dispatcher_connect( async_dispatcher_connect(
@ -585,7 +586,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
"""Return yeelight device.""" """Return yeelight device."""
return self._device return self._device
async def async_update(self): async def async_update(self) -> None:
"""Update light properties.""" """Update light properties."""
await self.device.async_update(True) await self.device.async_update(True)
@ -774,7 +775,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
power_mode=self._turn_on_power_mode, 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.""" """Turn the bulb on."""
brightness = kwargs.get(ATTR_BRIGHTNESS) brightness = kwargs.get(ATTR_BRIGHTNESS)
colortemp = kwargs.get(ATTR_COLOR_TEMP) 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.""" """Turn off with a given transition duration wrapped with _async_cmd."""
await self._bulb.async_turn_off(duration=duration, light_type=self.light_type) 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.""" """Turn off."""
if not self.is_on: if not self.is_on:
return return

View file

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

View file

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

View file

@ -52,7 +52,7 @@ class ZWaveMeRGB(ZWaveMeEntity, LightEntity):
"""Turn the device on.""" """Turn the device on."""
self.controller.zwave_api.send_command(self.device.id, "off") 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.""" """Turn the device on."""
color = kwargs.get(ATTR_RGB_COLOR) color = kwargs.get(ATTR_RGB_COLOR)