Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yeelight: use and expose the color temp range from specs #1247

Merged
merged 7 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions miio/integrations/yeelight/__init__.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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]
rytilahti marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
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)
rytilahti marked this conversation as resolved.
Show resolved Hide resolved
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