diff --git a/miio/integrations/yeelight/__init__.py b/miio/integrations/yeelight/__init__.py index bc67f9248..896812944 100644 --- a/miio/integrations/yeelight/__init__.py +++ b/miio/integrations/yeelight/__init__.py @@ -8,18 +8,13 @@ from miio.exceptions import DeviceException from miio.utils import int_to_rgb, rgb_to_int -from .spec_helper import YeelightSpecHelper +from .spec_helper import YeelightSpecHelper, YeelightSubLightType class YeelightException(DeviceException): pass -class YeelightSubLightType(IntEnum): - Main = 1 - Background = 2 - - SUBLIGHT_PROP_PREFIX = { YeelightSubLightType.Main: "", YeelightSubLightType.Background: "bg_", @@ -325,7 +320,7 @@ def status(self) -> YeelightStatus: def on(self, transition=0, mode=0): """Power on.""" """ - set_power ["on|off", "smooth", time_in_ms, mode] + set_power ["on|off", "sudden|smooth", time_in_ms, mode] where mode: 0: last mode 1: normal mode diff --git a/miio/integrations/yeelight/spec_helper.py b/miio/integrations/yeelight/spec_helper.py index 8a459198e..e794964cb 100644 --- a/miio/integrations/yeelight/spec_helper.py +++ b/miio/integrations/yeelight/spec_helper.py @@ -1,5 +1,6 @@ import logging import os +from enum import IntEnum from typing import Dict, NamedTuple import attr @@ -8,6 +9,11 @@ _LOGGER = logging.getLogger(__name__) +class YeelightSubLightType(IntEnum): + Main = 0 + Background = 1 + + class ColorTempRange(NamedTuple): """Color temperature range.""" @@ -15,13 +21,17 @@ class ColorTempRange(NamedTuple): max: int +@attr.s(auto_attribs=True) +class YeelightLampInfo: + color_temp: ColorTempRange + supports_color: bool + + @attr.s(auto_attribs=True) class YeelightModelInfo: model: str - color_temp: ColorTempRange night_light: bool - background_light: bool - supports_color: bool + lamps: Dict[YeelightSubLightType, YeelightLampInfo] class YeelightSpecHelper: @@ -33,20 +43,33 @@ def __init__(self): def _parse_specs_yaml(self): generic_info = YeelightModelInfo( - "generic", ColorTempRange(1700, 6500), False, False, False + "generic", + False, + { + YeelightSubLightType.Main: YeelightLampInfo( + ColorTempRange(1700, 6500), False + ) + }, ) YeelightSpecHelper._models["generic"] = generic_info # read the yaml file to populate the internal model cache with open(os.path.dirname(__file__) + "/specs.yaml") as filedata: models = yaml.safe_load(filedata) for key, value in models.items(): - info = YeelightModelInfo( - key, - ColorTempRange(*value["color_temp"]), - value["night_light"], - value["background_light"], - value["supports_color"], - ) + lamps = { + YeelightSubLightType.Main: YeelightLampInfo( + ColorTempRange(*value["color_temp"]), + value["supports_color"], + ) + } + + if "background" in value: + lamps[YeelightSubLightType.Background] = YeelightLampInfo( + ColorTempRange(*value["background"]["color_temp"]), + value["background"]["supports_color"], + ) + + info = YeelightModelInfo(key, value["night_light"], lamps) YeelightSpecHelper._models[key] = info @property diff --git a/miio/integrations/yeelight/specs.yaml b/miio/integrations/yeelight/specs.yaml index b5aa88312..c34e1104a 100644 --- a/miio/integrations/yeelight/specs.yaml +++ b/miio/integrations/yeelight/specs.yaml @@ -1,180 +1,159 @@ yeelink.light.bslamp1: - color_temp: [1700, 6500] night_light: False - background_light: False + color_temp: [1700, 6500] supports_color: True yeelink.light.bslamp2: - color_temp: [1700, 6500] night_light: True - background_light: False + color_temp: [1700, 6500] supports_color: True yeelink.light.bslamp3: - color_temp: [1700, 6500] night_light: True - background_light: False + color_temp: [1700, 6500] supports_color: True yeelink.light.ceil26: - color_temp: [2700, 6500] night_light: True - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.ceila: - color_temp: [2700, 6500] night_light: True - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.ceiling1: - color_temp: [2700, 6500] night_light: True - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.ceiling2: - color_temp: [2700, 6500] night_light: True - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.ceiling3: - color_temp: [2700, 6500] night_light: True - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.ceiling4: - color_temp: [2700, 6500] night_light: True - background_light: True + color_temp: [2700, 6500] supports_color: False + background: + color_temp: [1700, 6500] + supports_color: True yeelink.light.ceiling5: - color_temp: [2700, 6500] night_light: True - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.ceiling6: - color_temp: [2700, 6500] night_light: True - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.ceiling10: - color_temp: [2700, 6500] night_light: True - background_light: True + color_temp: [2700, 6500] supports_color: False + background: + color_temp: [1700, 6500] + supports_color: True yeelink.light.ceiling13: - color_temp: [2700, 6500] night_light: True - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.ceiling15: - color_temp: [2700, 6500] night_light: True - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.ceiling18: - color_temp: [2700, 6500] night_light: True - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.ceiling19: - color_temp: [2700, 6500] night_light: True - background_light: True + color_temp: [2700, 6500] supports_color: False + background: + color_temp: [1700, 6500] + supports_color: True yeelink.light.ceiling20: - color_temp: [2700, 6500] night_light: True - background_light: True + color_temp: [2700, 6500] supports_color: False + background: + color_temp: [1700, 6500] + supports_color: True yeelink.light.ceiling22: - color_temp: [2700, 6500] night_light: True - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.ceiling24: - color_temp: [2700, 6500] night_light: True - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.color1: - color_temp: [1700, 6500] night_light: False - background_light: False + color_temp: [1700, 6500] supports_color: True yeelink.light.color2: - color_temp: [2700, 6500] night_light: False - background_light: False + color_temp: [2700, 6500] supports_color: True yeelink.light.color4: - color_temp: [1700, 6500] night_light: False - background_light: False + color_temp: [1700, 6500] supports_color: True yeelink.light.colorc: - color_temp: [2700, 6500] night_light: False - background_light: False + color_temp: [2700, 6500] supports_color: True yeelink.light.color: - color_temp: [1700, 6500] night_light: False - background_light: False + color_temp: [1700, 6500] supports_color: True yeelink.light.ct_bulb: - color_temp: [2700, 6500] night_light: False - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.ct2: - color_temp: [2700, 6500] night_light: False - background_light: False + color_temp: [2700, 6500] supports_color: False yeelink.light.lamp1: - color_temp: [2700, 5000] night_light: False - background_light: False + color_temp: [2700, 5000] supports_color: False yeelink.light.lamp4: - color_temp: [2600, 5000] night_light: False - background_light: False + color_temp: [2600, 5000] supports_color: False yeelink.light.lamp15: - color_temp: [2700, 6500] night_light: False - background_light: True + color_temp: [2700, 6500] supports_color: False + background: + color_temp: [1700, 6500] + supports_color: True yeelink.light.mono1: - color_temp: [2700, 2700] night_light: False - background_light: False + color_temp: [2700, 2700] supports_color: False yeelink.light.mono5: - color_temp: [2700, 2700] night_light: False - background_light: False + color_temp: [2700, 2700] supports_color: False yeelink.light.mono: - color_temp: [2700, 2700] night_light: False - background_light: False + color_temp: [2700, 2700] supports_color: False yeelink.light.monob: - color_temp: [2700, 2700] night_light: False - background_light: False + color_temp: [2700, 2700] supports_color: False yeelink.light.strip1: - color_temp: [1700, 6500] night_light: False - background_light: False + color_temp: [1700, 6500] supports_color: True yeelink.light.strip2: - color_temp: [2700, 6500] night_light: False - background_light: False + color_temp: [2700, 6500] supports_color: True yeelink.light.strip4: - color_temp: [2700, 6500] night_light: False - background_light: False + color_temp: [2700, 6500] supports_color: True diff --git a/miio/integrations/yeelight/tests/test_yeelight_spec_helper.py b/miio/integrations/yeelight/tests/test_yeelight_spec_helper.py index 5683aba19..e6a92dc9b 100644 --- a/miio/integrations/yeelight/tests/test_yeelight_spec_helper.py +++ b/miio/integrations/yeelight/tests/test_yeelight_spec_helper.py @@ -1,21 +1,25 @@ -from ..spec_helper import ColorTempRange, YeelightSpecHelper +from ..spec_helper import ColorTempRange, YeelightSpecHelper, YeelightSubLightType def test_get_model_info(): spec_helper = YeelightSpecHelper() model_info = spec_helper.get_model_info("yeelink.light.bslamp1") assert model_info.model == "yeelink.light.bslamp1" - assert model_info.color_temp == ColorTempRange(1700, 6500) assert model_info.night_light is False - assert model_info.background_light is False - assert model_info.supports_color is True + assert model_info.lamps[YeelightSubLightType.Main].color_temp == ColorTempRange( + 1700, 6500 + ) + assert model_info.lamps[YeelightSubLightType.Main].supports_color is True + assert YeelightSubLightType.Background not in model_info.lamps def test_get_unknown_model_info(): spec_helper = YeelightSpecHelper() model_info = spec_helper.get_model_info("notreal") assert model_info.model == "generic" - assert model_info.color_temp == ColorTempRange(1700, 6500) assert model_info.night_light is False - assert model_info.background_light is False - assert model_info.supports_color is False + assert model_info.lamps[YeelightSubLightType.Main].color_temp == ColorTempRange( + 1700, 6500 + ) + assert model_info.lamps[YeelightSubLightType.Main].supports_color is False + assert YeelightSubLightType.Background not in model_info.lamps