Commit 1bbdab71 authored by Michał Ciemięga's avatar Michał Ciemięga Committed by Stavros Korokithakis

Break out light_type argument

parent b784db82
Pipeline #51149979 passed with stages
in 4 minutes and 30 seconds
......@@ -34,7 +34,7 @@ class BulbType(Enum):
WhiteTempMood = 3
class ControlType(IntEnum):
class LightType(IntEnum):
"""Type of light to control."""
Main = 0
......
......@@ -8,7 +8,7 @@ import struct
from future.utils import raise_from
from .decorator import decorator
from .enums import BulbType, ControlType, PowerMode
from .enums import BulbType, LightType, PowerMode
from .flow import Flow
from .utils import _clamp
......@@ -47,12 +47,13 @@ def _command(f, *args, **kw):
effect = kw.get("effect", self.effect)
duration = kw.get("duration", self.duration)
power_mode = kw.get("power_mode", self.power_mode)
control_type = kw.get("type", ControlType.Main)
method, params, kwargs = f(*args, **kw)
light_type = kwargs.get("light_type", LightType.Main)
# Prepend the control for different bulbs
if control_type == ControlType.Ambient:
if light_type == LightType.Ambient:
method = "bg_" + method
if method in [
......@@ -439,33 +440,36 @@ class Bulb(object):
return response
@_command
def set_color_temp(self, degrees, **kwargs):
def set_color_temp(self, degrees, light_type=LightType.Main, **kwargs):
"""
Set the bulb's color temperature.
:param int degrees: The degrees to set the color temperature to
(1700-6500).
:param yeelight.enums.LightType light_type: Light type to control.
"""
self.ensure_on()
degrees = _clamp(degrees, 1700, 6500)
return "set_ct_abx", [degrees], kwargs
return "set_ct_abx", [degrees], dict(kwargs, light_type=light_type)
@_command
def set_rgb(self, red, green, blue, **kwargs):
def set_rgb(self, red, green, blue, light_type=LightType.Main, **kwargs):
"""
Set the bulb's RGB value.
:param int red: The red value to set (0-255).
:param int red: The red value to set (0-255).
:param int green: The green value to set (0-255).
:param int blue: The blue value to set (0-255).
:param int blue: The blue value to set (0-255).
:param yeelight.enums.LightType light_type:
Light type to control.
"""
self.ensure_on()
red = _clamp(red, 0, 255)
green = _clamp(green, 0, 255)
blue = _clamp(blue, 0, 255)
return "set_rgb", [red * 65536 + green * 256 + blue], kwargs
return "set_rgb", [red * 65536 + green * 256 + blue], dict(kwargs, light_type=light_type)
@_command
def set_adjust(self, action, prop, **kwargs):
......@@ -486,7 +490,7 @@ class Bulb(object):
return "set_adjust", [action, prop], kwargs
@_command
def set_hsv(self, hue, saturation, value=None, **kwargs):
def set_hsv(self, hue, saturation, value=None, light_type=LightType.Main, **kwargs):
"""
Set the bulb's HSV value.
......@@ -495,6 +499,7 @@ class Bulb(object):
:param int value: The value to set (0-100). If omitted, the bulb's
brightness will remain the same as before the
change.
:param yeelight.enums.LightType light_type: Light type to control.
"""
self.ensure_on()
......@@ -504,7 +509,7 @@ class Bulb(object):
if value is None:
# If no value was passed, use ``set_hsv`` to preserve luminance.
return "set_hsv", [hue, saturation], kwargs
return "set_hsv", [hue, saturation], dict(kwargs, light_type=light_type)
else:
# Otherwise, use flow.
value = _clamp(value, 0, 100)
......@@ -518,34 +523,48 @@ class Bulb(object):
saturation = _clamp(saturation, 0, 100) / 100.0
red, green, blue = [int(round(col * 255)) for col in colorsys.hsv_to_rgb(hue, saturation, 1)]
rgb = red * 65536 + green * 256 + blue
return "start_cf", [1, 1, "%s, 1, %s, %s" % (duration, rgb, value)], kwargs
return "start_cf", [1, 1, "%s, 1, %s, %s" % (duration, rgb, value)], dict(kwargs, light_type=light_type)
@_command
def set_brightness(self, brightness, **kwargs):
def set_brightness(self, brightness, light_type=LightType.Main, **kwargs):
"""
Set the bulb's brightness.
:param int brightness: The brightness value to set (1-100).
:param yeelight.enums.LightType light_type: Light type to control.
"""
self.ensure_on()
brightness = _clamp(brightness, 1, 100)
return "set_bright", [brightness], kwargs
return "set_bright", [brightness], dict(kwargs, light_type=light_type)
@_command
def turn_on(self, **kwargs):
"""Turn the bulb on."""
return "set_power", ["on"], kwargs
def turn_on(self, light_type=LightType.Main, **kwargs):
"""
Turn the bulb on.
:param yeelight.enums.LightType light_type: Light type to control.
"""
return "set_power", ["on"], dict(kwargs, light_type=light_type)
@_command
def turn_off(self, **kwargs):
"""Turn the bulb off."""
return "set_power", ["off"], kwargs
def turn_off(self, light_type=LightType.Main, **kwargs):
"""
Turn the bulb off.
:param yeelight.enums.LightType light_type: Light type to control.
"""
return "set_power", ["off"], dict(kwargs, light_type=light_type)
@_command
def toggle(self, **kwargs):
"""Toggle the bulb on or off."""
return "toggle", [], kwargs
def toggle(self, light_type=LightType.Main, **kwargs):
"""
Toggle the bulb on or off.
:param yeelight.enums.LightType light_type: Light type to control.
"""
return "toggle", [], dict(kwargs, light_type=light_type)
@_command
def dev_toggle(self, **kwargs):
......@@ -553,14 +572,16 @@ class Bulb(object):
return "dev_toggle", [], kwargs
@_command
def set_default(self, **kwargs):
def set_default(self, light_type=LightType.Main, **kwargs):
"""
Set the bulb's current state as the default, which is what the bulb will be set to on power on.
If you get a "general error" setting this, yet the bulb reports as supporting `set_default` during
discovery, disable "auto save settings" in the YeeLight app.
:param yeelight.enums.LightType light_type: Light type to control.
"""
return "set_default", [], kwargs
return "set_default", [], dict(kwargs, light_type=light_type)
@_command
def set_name(self, name, **kwargs):
......@@ -572,7 +593,7 @@ class Bulb(object):
return "set_name", [name], kwargs
@_command
def start_flow(self, flow, **kwargs):
def start_flow(self, flow, light_type=LightType.Main, **kwargs):
"""
Start a flow.
......@@ -583,12 +604,20 @@ class Bulb(object):
self.ensure_on()
return ("start_cf", [flow.count * len(flow.transitions), flow.action.value, flow.expression], kwargs)
return (
"start_cf",
[flow.count * len(flow.transitions), flow.action.value, flow.expression],
dict(kwargs, light_type=light_type),
)
@_command
def stop_flow(self, **kwargs):
"""Stop a flow."""
return "stop_cf", [], kwargs
def stop_flow(self, light_type=LightType.Main, **kwargs):
"""
Stop a flow.
:param yeelight.enums.LightType light_type: Light type to control.
"""
return "stop_cf", [], dict(kwargs, light_type=light_type)
def start_music(self, port=0, ip=None):
"""
......@@ -691,7 +720,7 @@ class Bulb(object):
If the light is off it will be turned on.
:param yeelight.enums.PowerMode mode: The mode to swith to.
:param yeelight.enums.PowerMode mode: The mode to switch to.
"""
return self.turn_on(power_mode=mode)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment