state
This commit is contained in:
parent
45a0b72266
commit
b98f192efc
1 changed files with 18 additions and 0 deletions
18
app/views.py
18
app/views.py
|
@ -50,6 +50,7 @@ def powerbar_control(powerbar, outlet, action):
|
|||
tn = telnetlib.Telnet(powerbars[powerbar]['host'], powerbars[powerbar]['port'])
|
||||
tn.write(f"on {outlet}\r\n".encode('ascii'))
|
||||
tn.close()
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = 'on'
|
||||
print(f"Turned on powerbar {powerbar} outlet {outlet}")
|
||||
except Exception as e:
|
||||
print(f"Telnet error: {e}")
|
||||
|
@ -61,6 +62,7 @@ def powerbar_control(powerbar, outlet, action):
|
|||
tn = telnetlib.Telnet(powerbars[powerbar]['host'], powerbars[powerbar]['port'])
|
||||
tn.write(f"off {outlet}\r\n".encode('ascii'))
|
||||
tn.close()
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = 'off'
|
||||
print(f"Turned off powerbar {powerbar} outlet {outlet}")
|
||||
except Exception as e:
|
||||
print(f"Telnet error: {e}")
|
||||
|
@ -68,3 +70,19 @@ def powerbar_control(powerbar, outlet, action):
|
|||
|
||||
return "200"
|
||||
|
||||
|
||||
@routes.route('/powerbar_state/<string:powerbar>/<int:outlet>')
|
||||
def powerbar_state(powerbar, outlet):
|
||||
print(f"powerbar: {powerbar}")
|
||||
print(f"outlet: {outlet}")
|
||||
|
||||
if not vaild_power_bar(powerbar):
|
||||
print("Invalid powerbar")
|
||||
abort(404)
|
||||
|
||||
if not vaild_outlet(powerbar, outlet):
|
||||
print("Invalid outlet")
|
||||
abort(404)
|
||||
|
||||
state = powerbars[powerbar]['outlets'][outlet].get('state', 'unknown')
|
||||
return state
|
||||
|
|
Loading…
Reference in a new issue