diff --git a/miio/integrations/yeelight/__init__.py b/miio/integrations/yeelight/__init__.py index 0010d74c8..88b9ee83b 100644 --- a/miio/integrations/yeelight/__init__.py +++ b/miio/integrations/yeelight/__init__.py @@ -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): @@ -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: @@ -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), @@ -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]) diff --git a/miio/integrations/yeelight/specs.yaml b/miio/integrations/yeelight/specs.yaml index b69b5ac0e..cd9c26fd1 100644 --- a/miio/integrations/yeelight/specs.yaml +++ b/miio/integrations/yeelight/specs.yaml @@ -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 @@ -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 diff --git a/miio/integrations/yeelight/tests/test_yeelight.py b/miio/integrations/yeelight/tests/test_yeelight.py index 453597cb1..c90582ad8 100644 --- a/miio/integrations/yeelight/tests/test_yeelight.py +++ b/miio/integrations/yeelight/tests/test_yeelight.py @@ -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 @@ -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