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):
|
||||
try:
|
||||
check_input_error(tn)
|
||||
tn = get_telnet_connection(powerbar)
|
||||
tn.write(f"{command}\r\n".encode('ascii'))
|
||||
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}")
|
||||
if powerbars[powerbar]['method'] == "telnet":
|
||||
command = run_telnet_command(powerbar,f"on {outlet}")
|
||||
if command:
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = "on"
|
||||
if command:
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = "on"
|
||||
|
||||
state = powerbars[powerbar]['outlets'][outlet].get('state', 'unknown')
|
||||
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}")
|
||||
|
||||
if powerbars[powerbar]['method'] == "telnet":
|
||||
|
||||
command = run_telnet_command(powerbar,f"{action} {outlets}")
|
||||
if command:
|
||||
for outlet in device['outlets']:
|
||||
if outlet in powerbars[powerbar]['outlets']:
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = action
|
||||
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates')
|
||||
print(f"Turned {action} powerbar {powerbar} outlet {outlet}")
|
||||
return jsonify({'status': "200"})
|
||||
|
||||
if command:
|
||||
for outlet in device['outlets']:
|
||||
if outlet in powerbars[powerbar]['outlets']:
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = action
|
||||
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates')
|
||||
print(f"Turned {action} powerbar {powerbar} outlet {outlet}")
|
||||
return jsonify({'status': "200"})
|
||||
|
||||
return jsonify({'status': "500"})
|
||||
except Exception as E:
|
||||
|
|
Loading…
Reference in a new issue