test
All checks were successful
Deploy powerbar.ti Frontend Portal / Deploy-Tinance2-Frontend-Portal-Production (push) Successful in 37s
All checks were successful
Deploy powerbar.ti Frontend Portal / Deploy-Tinance2-Frontend-Portal-Production (push) Successful in 37s
This commit is contained in:
parent
bcb97819f1
commit
63e957a5a6
2 changed files with 11 additions and 10 deletions
|
@ -24,6 +24,7 @@ def run_telnet_command(powerbar, command):
|
||||||
|
|
||||||
for _ in range(retries):
|
for _ in range(retries):
|
||||||
try:
|
try:
|
||||||
|
check_input_error(tn)
|
||||||
tn = get_telnet_connection(powerbar)
|
tn = get_telnet_connection(powerbar)
|
||||||
tn.write(f"{command}\r\n".encode('ascii'))
|
tn.write(f"{command}\r\n".encode('ascii'))
|
||||||
tn.close()
|
tn.close()
|
||||||
|
|
20
app/views.py
20
app/views.py
|
@ -135,8 +135,8 @@ def powerbar_control(powerbar, outlet, action):
|
||||||
print(f"Turning On powerbar {powerbar} outlet {outlet}")
|
print(f"Turning On powerbar {powerbar} outlet {outlet}")
|
||||||
if powerbars[powerbar]['method'] == "telnet":
|
if powerbars[powerbar]['method'] == "telnet":
|
||||||
command = run_telnet_command(powerbar,f"on {outlet}")
|
command = run_telnet_command(powerbar,f"on {outlet}")
|
||||||
if command:
|
if command:
|
||||||
powerbars[powerbar]['outlets'][outlet]['state'] = "on"
|
powerbars[powerbar]['outlets'][outlet]['state'] = "on"
|
||||||
|
|
||||||
state = powerbars[powerbar]['outlets'][outlet].get('state', 'unknown')
|
state = powerbars[powerbar]['outlets'][outlet].get('state', 'unknown')
|
||||||
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : state}, namespace='/powerupdates')
|
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : state}, namespace='/powerupdates')
|
||||||
|
@ -220,15 +220,15 @@ def powebar_group_action(group, action):
|
||||||
print(f"Turning {action} powerbar {powerbar} outlet {outlets}")
|
print(f"Turning {action} powerbar {powerbar} outlet {outlets}")
|
||||||
|
|
||||||
if powerbars[powerbar]['method'] == "telnet":
|
if powerbars[powerbar]['method'] == "telnet":
|
||||||
|
|
||||||
command = run_telnet_command(powerbar,f"{action} {outlets}")
|
command = run_telnet_command(powerbar,f"{action} {outlets}")
|
||||||
if command:
|
|
||||||
for outlet in device['outlets']:
|
if command:
|
||||||
if outlet in powerbars[powerbar]['outlets']:
|
for outlet in device['outlets']:
|
||||||
powerbars[powerbar]['outlets'][outlet]['state'] = action
|
if outlet in powerbars[powerbar]['outlets']:
|
||||||
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates')
|
powerbars[powerbar]['outlets'][outlet]['state'] = action
|
||||||
print(f"Turned {action} powerbar {powerbar} outlet {outlet}")
|
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates')
|
||||||
return jsonify({'status': "200"})
|
print(f"Turned {action} powerbar {powerbar} outlet {outlet}")
|
||||||
|
return jsonify({'status': "200"})
|
||||||
|
|
||||||
return jsonify({'status': "500"})
|
return jsonify({'status': "500"})
|
||||||
except Exception as E:
|
except Exception as E:
|
||||||
|
|
Loading…
Reference in a new issue