Skip to content

Commit

Permalink
yeelight: use and expose the color temp range from specs (#1247)
Browse files Browse the repository at this point in the history
* Fix color_temp value for my devices

* get max and min color_temp from model_info

* Fix black

* Test fix

* Color temp range improvement
- Add self.color_temp range as class property
- Now light type is a part of constructor property. It get chance more easier implement Background light

* Remove constructor extension

Co-authored-by: Teemu R. <tpr@iki.fi>

Co-authored-by: Teemu R. <tpr@iki.fi>
  • Loading branch information
Kirmas and rytilahti committed Dec 17, 2021
1 parent 68fc467 commit df52c19
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
14 changes: 12 additions & 2 deletions miio/integrations/yeelight/__init__.py
Expand Up @@ -8,7 +8,7 @@
from miio.exceptions import DeviceException
from miio.utils import int_to_rgb, rgb_to_int

from .spec_helper import YeelightSpecHelper, YeelightSubLightType
from .spec_helper import ColorTempRange, YeelightSpecHelper, YeelightSubLightType


class YeelightException(DeviceException):
Expand Down Expand Up @@ -272,6 +272,9 @@ def __init__(
Yeelight._supported_models = Yeelight._spec_helper.supported_models

self._model_info = Yeelight._spec_helper.get_model_info(self.model)
self._light_type = YeelightSubLightType.Main
self._light_info = self._model_info.lamps[self._light_type]
self._color_temp_range = self._light_info.color_temp

@command(default_output=format_output("", "{result.cli_format}"))
def status(self) -> YeelightStatus:
Expand Down Expand Up @@ -312,6 +315,10 @@ def status(self) -> YeelightStatus:

return YeelightStatus(dict(zip(properties, values)))

@property
def valid_temperature_range(self) -> ColorTempRange:
return self._color_temp_range

@command(
click.option("--transition", type=int, required=False, default=0),
click.option("--mode", type=int, required=False, default=0),
Expand Down Expand Up @@ -363,7 +370,10 @@ def set_brightness(self, level, transition=0):
)
def set_color_temp(self, level, transition=500):
"""Set color temp in kelvin."""
if level > 6500 or level < 1700:
if (
level > self.valid_temperature_range.max
or level < self.valid_temperature_range.min
):
raise YeelightException("Invalid color temperature: %s" % level)
if transition > 0:
return self.send("set_ct_abx", [level, "smooth", transition])
Expand Down
4 changes: 2 additions & 2 deletions miio/integrations/yeelight/specs.yaml
Expand Up @@ -80,7 +80,7 @@ yeelink.light.ceiling20:
supports_color: True
yeelink.light.ceiling22:
night_light: True
color_temp: [2700, 6500]
color_temp: [2600, 6100]
supports_color: False
yeelink.light.ceiling24:
night_light: True
Expand Down Expand Up @@ -159,7 +159,7 @@ yeelink.light.strip1:
supports_color: True
yeelink.light.strip2:
night_light: False
color_temp: [2700, 6500]
color_temp: [1700, 6500]
supports_color: True
yeelink.light.strip4:
night_light: False
Expand Down
12 changes: 12 additions & 0 deletions miio/integrations/yeelight/tests/test_yeelight.py
Expand Up @@ -2,6 +2,10 @@

import pytest

from miio.integrations.yeelight.spec_helper import (
YeelightSpecHelper,
YeelightSubLightType,
)
from miio.tests.dummies import DummyDevice

from .. import Yeelight, YeelightException, YeelightMode, YeelightStatus
Expand All @@ -25,6 +29,14 @@ def __init__(self, *args, **kwargs):
}

super().__init__(*args, **kwargs)
if Yeelight._spec_helper is None:
Yeelight._spec_helper = YeelightSpecHelper()
Yeelight._supported_models = Yeelight._spec_helper.supported_models

self._model_info = Yeelight._spec_helper.get_model_info(self.model)
self._light_type = YeelightSubLightType.Main
self._light_info = self._model_info.lamps[self._light_type]
self._color_temp_range = self._light_info.color_temp

def set_config(self, x):
key, value = x
Expand Down

0 comments on commit df52c19

Please sign in to comment.