really state handling
All checks were successful
Deploy powerbar.ti Frontend Portal / Deploy-Tinance2-Frontend-Portal-Production (push) Successful in 38s
All checks were successful
Deploy powerbar.ti Frontend Portal / Deploy-Tinance2-Frontend-Portal-Production (push) Successful in 38s
This commit is contained in:
parent
4c4c6ba545
commit
04628383d1
2 changed files with 34 additions and 29 deletions
|
@ -23,11 +23,12 @@ def run_telnet_command(powerbar, command):
|
|||
|
||||
if check_input_error(tn):
|
||||
tn.write(f"{command}\r\n".encode('ascii'))
|
||||
tn.close()
|
||||
return True
|
||||
|
||||
tn.close()
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"Telnet error: {e}")
|
||||
print(f"Run Telnet Command Rrror: {e}")
|
||||
return False
|
||||
|
||||
|
||||
|
@ -41,6 +42,7 @@ def get_baytech_status_outlet_telnet(powerbar):
|
|||
if check_input_error(tn):
|
||||
tn.write(command.encode('ascii') + b"\r\n")
|
||||
else:
|
||||
tn.close()
|
||||
return None
|
||||
# Read the output until you receive the prompt or a timeout occurs
|
||||
output = tn.read_until(b"<prompt>", timeout=5).decode('ascii')
|
||||
|
|
57
app/views.py
57
app/views.py
|
@ -93,31 +93,33 @@ def powerbar_control(powerbar, outlet, action):
|
|||
print(f"Turning {action} powerbar {powerbar} outlet {outlet}")
|
||||
|
||||
if powerbars[powerbar]['method'] == "telnet":
|
||||
run_telnet_command(powerbar,f"{action} {outlet}")
|
||||
command = run_telnet_command(powerbar,f"{action} {outlet}")
|
||||
|
||||
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}")
|
||||
if command:
|
||||
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}")
|
||||
|
||||
except Exception as E:
|
||||
print(f"Telnet error: {E}")
|
||||
return jsonify({'error': 'Telnet error'}), 500
|
||||
print(f"Endpoint Exception Error: {E}")
|
||||
return jsonify({'error': 'Endpoint Exception Error'}), 500
|
||||
|
||||
if action == 'cycle':
|
||||
run_telnet_command(powerbar,f"off {outlet}")
|
||||
print(f"Turning Off powerbar {powerbar} outlet {outlet}")
|
||||
|
||||
if powerbars[powerbar]['method'] == "telnet":
|
||||
print(f"Turning Off powerbar {powerbar} outlet {outlet}")
|
||||
command = run_telnet_command(powerbar,f"off {outlet}")
|
||||
if command:
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = "off"
|
||||
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates')
|
||||
time.sleep(5)
|
||||
print(f"Turning On powerbar {powerbar} outlet {outlet}")
|
||||
|
||||
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = "off"
|
||||
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates')
|
||||
time.sleep(5)
|
||||
|
||||
print(f"Turning On powerbar {powerbar} outlet {outlet}")
|
||||
if powerbars[powerbar]['method'] == "telnet":
|
||||
run_telnet_command(powerbar,f"on {outlet}")
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = "on"
|
||||
|
||||
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates')
|
||||
command = run_telnet_command(powerbar,f"on {outlet}")
|
||||
if command:
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = "on"
|
||||
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates')
|
||||
|
||||
if action == 'toggle':
|
||||
print(powerbars[powerbar]['outlets'][outlet]['state'])
|
||||
|
@ -125,18 +127,19 @@ def powerbar_control(powerbar, outlet, action):
|
|||
|
||||
print(f"Turning Off powerbar {powerbar} outlet {outlet}")
|
||||
if powerbars[powerbar]['method'] == "telnet":
|
||||
run_telnet_command(powerbar,f"off {outlet}")
|
||||
command = run_telnet_command(powerbar,f"off {outlet}")
|
||||
if command:
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = "off"
|
||||
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates')
|
||||
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = "off"
|
||||
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates')
|
||||
elif powerbars[powerbar]['outlets'][outlet]['state'] == "off":
|
||||
|
||||
print(f"Turning On powerbar {powerbar} outlet {outlet}")
|
||||
if powerbars[powerbar]['method'] == "telnet":
|
||||
run_telnet_command(powerbar,f"on {outlet}")
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = "on"
|
||||
|
||||
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates')
|
||||
command = run_telnet_command(powerbar,f"on {outlet}")
|
||||
if command:
|
||||
powerbars[powerbar]['outlets'][outlet]['state'] = "on"
|
||||
app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates')
|
||||
|
||||
return jsonify({'state': powerbars[powerbar]['outlets'][outlet].get('state', 'unknown')})
|
||||
|
||||
|
@ -230,8 +233,8 @@ def powebar_group_action(group, action):
|
|||
|
||||
return jsonify({'status': "200"})
|
||||
except Exception as E:
|
||||
print(f"Telnet error: {E}")
|
||||
return jsonify({'error': 'Telnet error'}), 500
|
||||
print(f"Endpoint Exception Error: {E}")
|
||||
return jsonify({'error': 'Endpoint Exception Error'}), 500
|
||||
|
||||
@routes.route('/groups')
|
||||
def powebar_groups():
|
||||
|
|
Loading…
Reference in a new issue