From 63e957a5a67899c815585b0c84857988bd6396d5 Mon Sep 17 00:00:00 2001 From: Matthew Frost Date: Wed, 7 Feb 2024 16:44:32 +0100 Subject: [PATCH] test --- app/utils.py | 1 + app/views.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/utils.py b/app/utils.py index d9f4558..ea9603a 100644 --- a/app/utils.py +++ b/app/utils.py @@ -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() diff --git a/app/views.py b/app/views.py index 75556b6..71a48da 100644 --- a/app/views.py +++ b/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: