Yeelight fix updates on hsv mode (#9093)
* cast strings to integers for hsv_to_rgb conversion, fixes #6473 * remove type_checking, flake8 does not like that. * use hsv_to_rgb to convert to correct rgb valuepull/9027/merge
parent
27b0d648a6
commit
55a44b0a1c
|
@ -6,6 +6,7 @@ https://home-assistant.io/components/light.yeelight/
|
|||
"""
|
||||
import logging
|
||||
import colorsys
|
||||
from typing import Tuple
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -89,6 +90,14 @@ YEELIGHT_EFFECT_LIST = [
|
|||
EFFECT_STOP]
|
||||
|
||||
|
||||
# Travis-CI runs too old astroid https://github.com/PyCQA/pylint/issues/1212
|
||||
# pylint: disable=invalid-sequence-index
|
||||
def hsv_to_rgb(hsv: Tuple[float, float, float]) -> Tuple[int, int, int]:
|
||||
"""Convert HSV tuple (degrees, %, %) to RGB (values 0-255)."""
|
||||
red, green, blue = colorsys.hsv_to_rgb(hsv[0]/360, hsv[1]/100, hsv[2]/100)
|
||||
return int(red * 255), int(green * 255), int(blue * 255)
|
||||
|
||||
|
||||
def _cmd(func):
|
||||
"""Define a wrapper to catch exceptions from the bulb."""
|
||||
def _wrap(self, *args, **kwargs):
|
||||
|
@ -192,10 +201,10 @@ class YeelightLight(Light):
|
|||
if color_mode == 2: # color temperature
|
||||
return color_temperature_to_rgb(self.color_temp)
|
||||
if color_mode == 3: # hsv
|
||||
hue = self._properties.get('hue')
|
||||
sat = self._properties.get('sat')
|
||||
val = self._properties.get('bright')
|
||||
return colorsys.hsv_to_rgb(hue, sat, val)
|
||||
hue = int(self._properties.get('hue'))
|
||||
sat = int(self._properties.get('sat'))
|
||||
val = int(self._properties.get('bright'))
|
||||
return hsv_to_rgb((hue, sat, val))
|
||||
|
||||
rgb = int(rgb)
|
||||
blue = rgb & 0xff
|
||||
|
@ -214,7 +223,7 @@ class YeelightLight(Light):
|
|||
return self._bulb.last_properties
|
||||
|
||||
@property
|
||||
def _bulb(self) -> object:
|
||||
def _bulb(self) -> 'yeelight.Bulb':
|
||||
import yeelight
|
||||
if self._bulb_device is None:
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue