Skip to content

Add toggle method #4

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 1 commit into from
Apr 12, 2019
Merged
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
9 changes: 9 additions & 0 deletions adafruit_hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ def set_light(self, light_id, **kwargs):
resp = self._put('{0}/lights/{1}/state'.format(self._username_url, light_id), kwargs)
return resp

def toggle_light(self, light_id):
"""Gets and toggles the current state of a specified light.
:param int light_id: Light identifier.
"""
light_state = self.get_light(light_id)
light_state = not light_state['state']['on']
resp = self.set_light(light_id, on=light_state)
return resp

def get_light(self, light_id):
"""Gets the attributes and state of a provided light.
:param int light_id: Light identifier.
Expand Down