Skip to content

Add set_states method - #17

Open
grahamhome wants to merge 2 commits into
cydrobolt:masterfrom
grahamhome:set-states
Open

Add set_states method#17
grahamhome wants to merge 2 commits into
cydrobolt:masterfrom
grahamhome:set-states

Conversation

@grahamhome

Copy link
Copy Markdown

This PR simply adds a method for the Lifx "Set States" endpoint so that multiple lights can be set simultaneously. It also addresses a defect in "client.py" which was preventing json_body parameters from being sent in requests to the Lifx API.

@grahamhome

Copy link
Copy Markdown
Author

@cydrobolt I am really enjoying using your Pifx library. I needed to add a method for an endpoint that wasn't in the library. Will you consider accepting my PR? Please let me know if you'd like me to make any other changes to this PR. Thanks in advance!

Comment thread pifx/core.py Outdated
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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants