Skip to content

Allow kwargs for set_color #3

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

Merged
merged 3 commits into from
May 20, 2019
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
26 changes: 7 additions & 19 deletions adafruit_lifx.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,53 +123,41 @@ def toggle_light(self, selector, all_lights=False, duration=0):
"""
if all_lights:
selector = 'all'
path = LIFX_URL+selector+'/toggle'
data = {'duration':duration}
return self._post(path, data)
return self._post(LIFX_URL+selector+'/toggle', data)

def move_effect(self, selector, move_direction, period, power_on):
"""Performs a linear move effect on a light, or lights.
:param str move_direction: Move direction, forward or backward.
:param double period: Time in second per effect cycle.
:param bool power_on: Turn on a light before performing the move.
"""
path = LIFX_URL+selector+'/effects/move'
data = {'direction':move_direction,
'period':period,
'power_on':power_on}
return self._post(path, data)
return self._post(LIFX_URL+selector+'/effects/move', data)

def effects_off(self, selector, power_off=False):
"""Turns off any running effects on the selected device.
:param dict selector: Selector to control which lights are requested.
:param bool power_off: If true, the devices will also be turned off.
"""
path = LIFX_URL+selector+'/effects/off'
data = {'power_off', power_off}
return self._post(path, data)
return self._post(LIFX_URL+selector+'/effects/off', data)

def set_brightness(self, selector, brightness):
"""Sets the state of the lights within the selector.
:param dict selector: Selector to control which lights are requested.
:param double brightness: Brightness level of the light, from 0.0 to 1.0.
"""
path = LIFX_URL+selector+'/state'
data = {'brightness':brightness}
return self._put(path, data)
return self._put(LIFX_URL+selector+'/state', data)

def set_color(self, selector, power, color, brightness=1.0):
def set_color(self, selector, **kwargs):
"""Sets the state of the light's color within the selector.
:param dict selector: Selector to control which lights are requested.
:param str power: Sets the power state of the light (on/off).
:param str color: Color to set the light to (https://api.developer.lifx.com/v1/docs/colors).
:param double brightness: Brightness level of the light from 0.0 to 1.0.
Valid arguments: https://api.developer.lifx.com/docs/set-state
"""
path = LIFX_URL+selector+'/state'
data = {'power':power,
'color':color,
'brightness':brightness
}
return self._put(path, data)
return self._put(LIFX_URL+selector+'/state', kwargs)

def list_lights(self):
"""Enumerates all the lights associated with the LIFX Cloud Account
Expand Down
2 changes: 1 addition & 1 deletion examples/lifx_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
colors = ['yellow', 'blue', 'white']
for color in colors:
print('Setting light to: ', color)
lifx.set_color(lifx_light, 'on', color, brightness=light_brightness)
lifx.set_color(lifx_light, power='on', color=color, brightness=light_brightness)

# Turn off the light
print('Turning off light...')
Expand Down