mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Impement color setter with transition
This commit is contained in:
parent
0f4d5b9eac
commit
44339f3dc1
1 changed files with 45 additions and 0 deletions
|
@ -42,6 +42,13 @@ class Const:
|
|||
LAMP_ON = {"on": True, "transitiontime": 0}
|
||||
LAMP_OFF = {"on": False, "transitiontime": 0}
|
||||
|
||||
COLOR_WHITE = {"sat": 0}
|
||||
COLOR_RED = {"hue": 0, "sat": 254}
|
||||
COLOR_GREEN = {"hue": 25500, "sat": 254}
|
||||
COLOR_ORANGE = {"hue": 12000, "sat": 254}
|
||||
COLOR_PINK = {"hue": 12000, "sat": 254}
|
||||
COLOR_BLUE = {"hue": 46920, "sat": 254}
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
|
@ -322,3 +329,41 @@ def call_effect(*args, **kwargs):
|
|||
res[dev_id] = _set(dev_id, {"effect": kwargs.get("type", "none")})
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def call_color(*args, **kwargs):
|
||||
'''
|
||||
Set a color to the lamp.
|
||||
|
||||
Options:
|
||||
|
||||
* **id**: Specifies a device ID. Can be comma-separated ids or all, if omitted.
|
||||
* **color**: Fixed color. Values are: red, green, blue, orange, pink, white. Default white.
|
||||
* **transition**: Transition 0~200.
|
||||
|
||||
CLE Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' hue.color
|
||||
salt '*' hue.color id=1
|
||||
salt '*' hue.color id=1,2,3 oolor=red transition=30
|
||||
'''
|
||||
res = dict()
|
||||
|
||||
colormap = {
|
||||
'red': Const.COLOR_RED,
|
||||
'green': Const.COLOR_GREEN,
|
||||
'blue': Const.COLOR_BLUE,
|
||||
'orange': Const.COLOR_ORANGE,
|
||||
'pink': Const.COLOR_PINK,
|
||||
'white': Const.COLOR_WHITE,
|
||||
}
|
||||
|
||||
devices = _get_lights()
|
||||
for dev_id in ('id' not in kwargs and sorted(devices.keys()) or _get_devices(kwargs)):
|
||||
color = colormap.get(kwargs.get("color", 'white'), Const.COLOR_WHITE)
|
||||
color.update({"transitiontime": max(min(kwargs.get("transition", 0), 200), 0)})
|
||||
res[dev_id] = _set(dev_id, color)
|
||||
|
||||
return res
|
||||
|
|
Loading…
Add table
Reference in a new issue