From b78cc4066a15f1a3bb9ba2a40f133086dfa80ceb Mon Sep 17 00:00:00 2001 From: Matthew Frost Date: Wed, 7 Feb 2024 18:29:54 +0100 Subject: [PATCH] teest --- app/jobs.py | 6 +++--- app/views.py | 36 +++++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/jobs.py b/app/jobs.py index c8038d7..651eafa 100644 --- a/app/jobs.py +++ b/app/jobs.py @@ -4,7 +4,7 @@ from app.utils import run_telnet_command scheduler = APScheduler() -@scheduler.task('interval', id='do_periodic_serial_job', seconds=3) +@scheduler.task('interval', id='do_periodic_serial_job', seconds=4) def periodic_serial_job(): print("Running Sync Job") for powerbar in powerbars: @@ -27,9 +27,9 @@ def periodic_serial_job(): if on_command is not "On ": print("Running On command") - # run_telnet_command(powerbar, on_command.rstrip(',')) + run_telnet_command(powerbar, on_command.rstrip(',')) print(f"Turning off outlets: {off_command.rstrip(',')}") if off_command is not "Off ": print("Running Off command") - # run_telnet_command(powerbar, off_command.rstrip(',')) \ No newline at end of file + run_telnet_command(powerbar, off_command.rstrip(',')) \ No newline at end of file diff --git a/app/views.py b/app/views.py index 0015345..7d82883 100644 --- a/app/views.py +++ b/app/views.py @@ -92,6 +92,9 @@ def powerbar_control(powerbar, outlet, action): if powerbars[powerbar]['method'] == "telnet": command = run_telnet_command(powerbar,f"{action} {outlet}") + if powerbars[powerbar]['method'] == "batch_telnet": + command = True + if command: powerbars[powerbar]['outlets'][outlet]['state'] = action app.socketio.emit('power-event',{'powerbar': powerbar, 'outlet' : outlet, 'action' : action}, namespace='/powerupdates') @@ -106,16 +109,24 @@ def powerbar_control(powerbar, outlet, action): if powerbars[powerbar]['method'] == "telnet": 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}") + + if powerbars[powerbar]['method'] == "batch_telnet": + command = True + + 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}") if powerbars[powerbar]['method'] == "telnet": command = run_telnet_command(powerbar,f"on {outlet}") - if command: - powerbars[powerbar]['outlets'][outlet]['state'] = "on" + + if powerbars[powerbar]['method'] == "batch_telnet": + command = True + + if command: + powerbars[powerbar]['outlets'][outlet]['state'] = "on" if action == 'toggle': print(powerbars[powerbar]['outlets'][outlet]['state']) @@ -124,6 +135,10 @@ def powerbar_control(powerbar, outlet, action): print(f"Turning Off powerbar {powerbar} outlet {outlet}") if powerbars[powerbar]['method'] == "telnet": command = run_telnet_command(powerbar,f"off {outlet}") + + if powerbars[powerbar]['method'] == "batch_telnet": + command = True + if command: powerbars[powerbar]['outlets'][outlet]['state'] = "off" @@ -132,6 +147,10 @@ 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 powerbars[powerbar]['method'] == "batch_telnet": + command = True + if command: powerbars[powerbar]['outlets'][outlet]['state'] = "on" @@ -219,6 +238,9 @@ def powebar_group_action(group, action): if powerbars[powerbar]['method'] == "telnet": command = run_telnet_command(powerbar,f"{action} {outlets}") + if powerbars[powerbar]['method'] == "batch_telnet": + command = True + if command: for outlet in device['outlets']: if outlet in powerbars[powerbar]['outlets']: