mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Implement device state change
This commit is contained in:
parent
d769bc85a7
commit
7a8d72de3f
1 changed files with 21 additions and 0 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue