Implement device state change

This commit is contained in:
Bo Maryniuk 2015-10-12 23:47:42 +02:00 committed by C. R. Oldham
parent d769bc85a7
commit 7a8d72de3f

View file

@ -44,6 +44,7 @@ def grains_refresh():
return GRAINS_CACHE
def ping(*args, **kw):
'''
Ping the lamps.
@ -60,6 +61,26 @@ def shutdown(opts, *args, **kw):
return True
def _set(lamp_id, state):
'''
Set state to the device by ID.
:param lamp_id:
:param state:
:return:
'''
res = json.loads(requests.put(CONFIG['url']+"/lights/"
+ str(lamp_id) + "/state", json=state).content)
res = len(res) > 1 and res[-1] or res[0]
if res.get('success'):
res = {'result': True}
elif res.get('error'):
res = {'result': False,
'description': res['error']['description'],
'type': res['error']['type']}
return res
def _get_devices(params):
'''
Parse device(s) ID(s) from the common params.