ti-powerbar/app/jobs.py
Matthew Frost ac0e14fd6b
All checks were successful
Deploy powerbar.ti Frontend Portal / Deploy-Tinance2-Frontend-Portal-Production (push) Successful in 39s
powebar polling
2024-02-07 18:18:33 +01:00

35 lines
No EOL
1.1 KiB
Python

from flask_apscheduler import APScheduler
from app.settings import powerbars
from app.utils import run_telnet_command
scheduler = APScheduler()
@scheduler.task('interval', id='do_periodic_serial_job', seconds=3)
def periodic_serial_job():
print("Running Sync Job")
for powerbar in powerbars:
on_command = "On "
off_command = "Off "
print(f"Checking powerbar state {powerbar}")
for outlet in powerbars[powerbar]['outlets']:
outlet_status = powerbars[powerbar]['outlets'][outlet].get('state', 'unknown')
if outlet_status is not "unknown":
if outlet_status == "on":
on_command += f"{outlet},"
if outlet_status == "off":
off_command += f"{outlet},"
print(f"Turning on outlets: {on_command.rstrip(',')}")
if on_command is not "On ":
print("Running On command")
# 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(','))