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 set_states method #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion pifx/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def perform_request(

if json_body:
res = self._s.request(
method=method, url=http_endpoint, json=data, headers=self.headers)
method=method, url=http_endpoint, json=json_body, headers=self.headers)
else:
res = self._s.request(
method=method, url=http_endpoint, data=data, headers=self.headers)
Expand Down
39 changes: 39 additions & 0 deletions pifx/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,45 @@ def set_state(self, selector='all',
method='put', endpoint='lights/{}/state',
endpoint_args=[selector], argument_tuples=argument_tuples)

def set_states(self, states=None):
"""Given a collection of "state" dictionaries, set the state of one or more lights.
State dictionaries may contain selector, power, color, brightness and duration parameters
as detailed below.
Selectors can be based on id, scene_id, group_id, label, etc.
Returns list of lightbulb statuses if successful.
See http://api.developer.lifx.com/v1/docs/selectors


selector: required String
The selector to limit which lights will run the effect.

power: String
e.g "on" or "off"

color: String
e.g #ff0000 or "red"
Color to set selected bulbs.
Hex color code, color name, saturation percentage, hue, RGB, etc.
See http://api.developer.lifx.com/v1/docs/colors

brightness: Double
e.g 0.5
Set brightness level from 0 to 1

duration: Double
e.g 10
Setting transition time, in seconds, from 0.0 to
3155760000.0 (100 years).

Example invocation:
pifx.set_states([{'selector': 'id:XXXYYYZZZZ', 'color': 'red'}, {'selector': 'id:AAABBBCCCCC', 'brightness': 0.8}])
"""
if states is None:
states = []
json_body = {"states": states}
return self.client.perform_request(
method='put', endpoint='lights/states', json_body=json_body)

def state_delta(self, selector='all',
power=None, duration=1.0, infrared=None, hue=None,
saturation=None, brightness=None, kelvin=None):
Expand Down