mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Improve type hints in blinksticklight lights (#75999)
This commit is contained in:
parent
fbe22d4fe7
commit
be4f9598f9
@ -1,6 +1,8 @@
|
||||
"""Support for Blinkstick lights."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from blinkstick import blinkstick
|
||||
import voluptuous as vol
|
||||
|
||||
@ -57,15 +59,15 @@ class BlinkStickLight(LightEntity):
|
||||
self._stick = stick
|
||||
self._attr_name = name
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Read back the device state."""
|
||||
rgb_color = self._stick.get_color()
|
||||
hsv = color_util.color_RGB_to_hsv(*rgb_color)
|
||||
self._attr_hs_color = hsv[:2]
|
||||
self._attr_brightness = hsv[2]
|
||||
self._attr_is_on = self.brightness > 0
|
||||
self._attr_brightness = int(hsv[2])
|
||||
self._attr_is_on = self.brightness is not None and self.brightness > 0
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
def turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the device on."""
|
||||
if ATTR_HS_COLOR in kwargs:
|
||||
self._attr_hs_color = kwargs[ATTR_HS_COLOR]
|
||||
@ -73,13 +75,15 @@ class BlinkStickLight(LightEntity):
|
||||
self._attr_brightness = kwargs[ATTR_BRIGHTNESS]
|
||||
else:
|
||||
self._attr_brightness = 255
|
||||
assert self.brightness is not None
|
||||
self._attr_is_on = self.brightness > 0
|
||||
|
||||
assert self.hs_color
|
||||
rgb_color = color_util.color_hsv_to_RGB(
|
||||
self.hs_color[0], self.hs_color[1], self.brightness / 255 * 100
|
||||
)
|
||||
self._stick.set_color(red=rgb_color[0], green=rgb_color[1], blue=rgb_color[2])
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
def turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the device off."""
|
||||
self._stick.turn_off()
|
||||
|
Loading…
x
Reference in New Issue
Block a user