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

Add light specs for yeelight #1163

Merged
merged 11 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 2 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

SUPPORTED_MODELS = ["yeelink.light.color1"]
from .spec_helper import YeelightSpecHelper


class YeelightException(DeviceException):
Expand Down Expand Up @@ -259,7 +259,7 @@ class Yeelight(Device):
which however requires enabling the developer mode on the bulbs.
"""

_supported_models = SUPPORTED_MODELS
_supported_models = YeelightSpecHelper.supported_models()

@command(default_output=format_output("", "{result.cli_format}"))
def status(self) -> YeelightStatus:
Expand Down
59 changes: 59 additions & 0 deletions miio/integrations/yeelight/spec_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import logging
import os
from dataclasses import dataclass
from typing import NamedTuple

import yaml

_LOGGER = logging.getLogger(__name__)

GENERIC_MODEL_SPEC_DICT = {
"color_temp": (1700, 6500),
"has_night_light": False,
"has_background_light": False,
"supports_color": False,
}


class YeelightColorTempRange(NamedTuple):
rytilahti marked this conversation as resolved.
Show resolved Hide resolved
"""Color temperature range."""

min: int
max: int


@dataclass
class YeelightModelInfo:
rytilahti marked this conversation as resolved.
Show resolved Hide resolved
model: str
color_temp: YeelightColorTempRange
has_night_light: bool
has_background_light: bool
supports_color: bool

def __init__(self, model, spec):
self.model = model
self.color_temp = YeelightColorTempRange(*spec.get("color_temp", (1700, 6500)))
self.has_night_light = spec.get("night_light", False)
self.has_background_light = spec.get("background_light", False)
self.supports_color = spec.get("supports_color", False)


class YeelightSpecHelper:
@staticmethod
def specs() -> dict:
with open(os.path.dirname(__file__) + "/specs.yaml") as filedata:
return yaml.safe_load(filedata)

@staticmethod
def supported_models():
return YeelightSpecHelper.specs().keys()

@staticmethod
def get_model_info(model) -> YeelightModelInfo:
if model not in YeelightSpecHelper.specs():
_LOGGER.warning(
"Unknown model %s, please open an issue and supply features for this light. Returning generic information.",
model,
)
return YeelightModelInfo("generic", GENERIC_MODEL_SPEC_DICT)
return YeelightModelInfo(model, YeelightSpecHelper.specs().get(model))
180 changes: 180 additions & 0 deletions miio/integrations/yeelight/specs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
yeelink.light.bslamp1:
color_temp: [1700, 6500]
night_light: False
background_light: False
supports_color: True
yeelink.light.bslamp2:
color_temp: [1700, 6500]
night_light: True
background_light: False
supports_color: True
yeelink.light.bslamp3:
color_temp: [1700, 6500]
night_light: True
background_light: False
supports_color: True
yeelink.light.ceil26:
color_temp: [2700, 6500]
night_light: True
background_light: False
supports_color: False
yeelink.light.ceila:
color_temp: [2700, 6500]
night_light: True
background_light: False
supports_color: False
yeelink.light.ceiling1:
color_temp: [2700, 6500]
night_light: True
background_light: False
supports_color: False
yeelink.light.ceiling2:
color_temp: [2700, 6500]
night_light: True
background_light: False
supports_color: False
yeelink.light.ceiling3:
color_temp: [2700, 6500]
night_light: True
background_light: False
supports_color: False
yeelink.light.ceiling4:
color_temp: [2700, 6500]
night_light: True
background_light: True
supports_color: False
yeelink.light.ceiling5:
color_temp: [2700, 6500]
night_light: True
background_light: False
supports_color: False
yeelink.light.ceiling6:
color_temp: [2700, 6500]
night_light: True
background_light: False
supports_color: False
yeelink.light.ceiling10:
color_temp: [2700, 6500]
night_light: True
background_light: True
supports_color: False
yeelink.light.ceiling13:
color_temp: [2700, 6500]
night_light: True
background_light: False
supports_color: False
yeelink.light.ceiling15:
color_temp: [2700, 6500]
night_light: True
background_light: False
supports_color: False
yeelink.light.ceiling18:
color_temp: [2700, 6500]
night_light: True
background_light: False
supports_color: False
yeelink.light.ceiling19:
color_temp: [2700, 6500]
night_light: True
background_light: True
supports_color: False
yeelink.light.ceiling20:
color_temp: [2700, 6500]
night_light: True
background_light: True
supports_color: False
yeelink.light.ceiling22:
color_temp: [2700, 6500]
night_light: True
background_light: False
supports_color: False
yeelink.light.ceiling24:
color_temp: [2700, 6500]
night_light: True
background_light: False
supports_color: False
yeelink.light.color1:
color_temp: [1700, 6500]
night_light: False
background_light: False
supports_color: True
yeelink.light.color2:
color_temp: [2700, 6500]
night_light: False
background_light: False
supports_color: True
yeelink.light.color4:
color_temp: [1700, 6500]
night_light: False
background_light: False
supports_color: True
yeelink.light.colorc:
color_temp: [2700, 6500]
night_light: False
background_light: False
supports_color: True
yeelink.light.color:
color_temp: [1700, 6500]
night_light: False
background_light: False
supports_color: True
yeelink.light.ct_bulb:
color_temp: [2700, 6500]
night_light: False
background_light: False
supports_color: False
yeelink.light.ct2:
color_temp: [2700, 6500]
night_light: False
background_light: False
supports_color: False
yeelink.light.lamp1:
color_temp: [2700, 5000]
night_light: False
background_light: False
supports_color: False
yeelink.light.lamp4:
color_temp: [2600, 5000]
night_light: False
background_light: False
supports_color: False
yeelink.light.lamp15:
color_temp: [2700, 6500]
night_light: False
background_light: True
supports_color: False
yeelink.light.mono1:
color_temp: [2700, 2700]
night_light: False
background_light: False
supports_color: False
yeelink.light.mono5:
color_temp: [2700, 2700]
night_light: False
background_light: False
supports_color: False
yeelink.light.mono:
color_temp: [2700, 2700]
night_light: False
background_light: False
supports_color: False
yeelink.light.monob:
color_temp: [2700, 2700]
night_light: False
background_light: False
supports_color: False
yeelink.light.strip1:
color_temp: [1700, 6500]
night_light: False
background_light: False
supports_color: True
yeelink.light.strip2:
color_temp: [2700, 6500]
night_light: False
background_light: False
supports_color: True
yeelink.light.strip4:
color_temp: [2700, 6500]
night_light: False
background_light: False
supports_color: True
19 changes: 19 additions & 0 deletions miio/integrations/yeelight/tests/test_yeelight_spec_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from ..spec_helper import YeelightColorTempRange, YeelightSpecHelper


def test_get_model_info():
model_info = YeelightSpecHelper.get_model_info("yeelink.light.bslamp1")
assert model_info.model == "yeelink.light.bslamp1"
assert model_info.color_temp == YeelightColorTempRange(1700, 6500)
assert model_info.has_night_light is False
assert model_info.has_background_light is False
assert model_info.supports_color is True


def test_get_unknown_model_info():
model_info = YeelightSpecHelper.get_model_info("notreal")
assert model_info.model == "generic"
assert model_info.color_temp == YeelightColorTempRange(1700, 6500)
assert model_info.has_night_light is False
assert model_info.has_background_light is False
assert model_info.supports_color is False