Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 35 additions & 0 deletions pifx/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,41 @@ def set_state(self, selector='all',
method='put', endpoint='lights/{}/state',
endpoint_args=[selector], argument_tuples=argument_tuples)

def set_states(self, states=[{'selector': 'all',

@cydrobolt cydrobolt Aug 8, 2021

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This default argument seems potentially error-prone. See https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments

It might be better to write states=None and then if states is None: states = [] in the method itself.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cydrobolt I have updated the method to remove the mutable default argument. I added a usage example in the docstring so users will hopefully know how to call it. Let me know if you'd like to see any other changes!

'power': None, 'color': None, 'brightness': None, 'duration': None}]):
"""Given a list of states, set the state of one or more lights.
States 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).
"""
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