ti-powerbar/app/utils.py
Matthew Frost 4062918ebb
All checks were successful
Deploy powerbar.ti Frontend Portal / Deploy-Tinance2-Frontend-Portal-Production (push) Successful in 6s
gets default state on reboot
2023-11-20 11:33:19 +01:00

28 lines
836 B
Python

import telnetlib
import re
def get_baytech_status_outlet(hostname,port):
try:
# Create a Telnet object and connect to the host
tn = telnetlib.Telnet(hostname, port)
# Send the command you want to execute
command = "status"
tn.write(command.encode('ascii') + b"\r\n")
# Read the output until you receive the prompt or a timeout occurs
output = tn.read_until(b"<prompt>", timeout=5).decode('ascii')
# Close the Telnet connection
tn.close()
pattern = r"(\d+)\)\.\.\.Outlet\s+(\d+)\s+:\s+(\w+)"
outlets = {}
matches = re.findall(pattern, output)
for match in matches:
number = int(match[1])
status = match[2]
outlets[number] = status
return outlets
except:
return None