diff --git a/app/views.py b/app/views.py index e275576..baeb112 100644 --- a/app/views.py +++ b/app/views.py @@ -166,18 +166,19 @@ def powebar_group_action(group, action): if action in ['on', 'off']: try: - tn = telnetlib.Telnet(powerbars[powerbar]['host'], powerbars[powerbar]['port']) + for device in group["devices"]: powerbar = device["powerbar"] + tn = telnetlib.Telnet(powerbars[powerbar]['host'], powerbars[powerbar]['port']) print(f"Powerbar: {powerbar}") outlets = ",".join([str(x) for x in device['outlets']]) print(f"Turning {action} powerbar {powerbar} outlet {outlets}") tn.write(f"{action} {outlets}\r\n".encode('ascii')) + tn.close() for outlet in outlets: powerbars[powerbar]['outlets'][outlet]['state'] = action print(f"Turned {action} powerbar {powerbar} outlet {outlet}") - tn.close() return jsonify({'status': "200"}) except Exception as E: print(f"Telnet error: {E}")