Skip to content

Commit d7c426e

Browse files
authored
Merge pull request #4 from brentru/add-toggle
Add toggle method
2 parents 7685e70 + 5beca82 commit d7c426e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

adafruit_hue.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ def set_light(self, light_id, **kwargs):
164164
resp = self._put('{0}/lights/{1}/state'.format(self._username_url, light_id), kwargs)
165165
return resp
166166

167+
def toggle_light(self, light_id):
168+
"""Gets and toggles the current state of a specified light.
169+
:param int light_id: Light identifier.
170+
"""
171+
light_state = self.get_light(light_id)
172+
light_state = not light_state['state']['on']
173+
resp = self.set_light(light_id, on=light_state)
174+
return resp
175+
167176
def get_light(self, light_id):
168177
"""Gets the attributes and state of a provided light.
169178
:param int light_id: Light identifier.

0 commit comments

Comments
 (0)