Skip to content

Commit f07c307

Browse files
ActionHOSchTsemin.buljevic
authored and
semin.buljevic
committed
driver/power: add backend for Phoenix Contact FL 2303-8SP1 SPE switch
Co-authored-by: Jan Lübbe <[email protected]> Signed-off-by: Semin Buljevic <[email protected]> Rename phoenix_fl_switch.py to phoenixcontact_fl_2300.py Signed-off-by: semin.buljevic <[email protected]>
1 parent 8f46a37 commit f07c307

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

doc/configuration.rst

+4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ Currently available are:
195195
``netio_kshell``
196196
Controls a NETIO 4C PDU via a Telnet interface.
197197

198+
``phoenixcontact_fl_2300``
199+
Controls a single-pair-ethernet powerswitch via telnet.
200+
Tested on a FL SWITCH 2303-8SP1 with FW-version 3.27.01 BETA
201+
198202
``raritan``
199203
Controls Raritan PDUs via SNMP.
200204

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
'''
2+
This Driver was tested on a FL SWITCH 2303-8SP1 with FW-version 3.27.01 BETA
3+
file phoenixcontact_fl_2300.py
4+
author Raffael Krakau
5+
date 2023-08-24
6+
7+
Copyright 2023 JUMO GmbH & Co. KG
8+
'''
9+
import pexpect
10+
11+
PORT = 23
12+
13+
14+
def __login_telnet(tn):
15+
"""
16+
Login user with set credentials
17+
18+
@param tn : pyexpect-telnet-object
19+
"""
20+
username = "admin"
21+
password = "private"
22+
23+
# login user with password
24+
tn.expect(b'User: ')
25+
tn.send(bytes(f'{username}\r\n', "utf-8"))
26+
tn.expect(b'Password: ')
27+
tn.send(bytes(f'{password}\r\n', "utf-8"))
28+
29+
30+
def power_set(host, port, index: int, value: bool):
31+
"""
32+
Set power state by socket port number (e.g. 1 - 8) and an value {'enable', 'disable'}.
33+
34+
- values:
35+
- disable(False): Turn OFF,
36+
- enable(True): Turn ON
37+
"""
38+
action = "enable" if value else "disable"
39+
40+
with pexpect.spawn(f"telnet {host} {port}", timeout=1) as tn:
41+
# login user with password
42+
__login_telnet(tn)
43+
44+
# set value
45+
tn.send(f'pse port {index} power {action}\r\n'.encode())
46+
47+
tn.expect(b'OK')
48+
49+
tn.send(b"quit\r\n")
50+
tn.expect(pexpect.EOF)
51+
52+
53+
def power_get(host, port, index: int) -> bool:
54+
"""
55+
Get current state of a given socket number.
56+
- host: spe-switch-device adress
57+
- port: standard is 23
58+
- index: depends on spe-switch-device 1-n (n is the number of spe-switch-ports)
59+
"""
60+
status = None
61+
62+
with pexpect.spawn(f"telnet {host} {port}", timeout=1) as tn:
63+
# login user with password
64+
__login_telnet(tn)
65+
66+
# get value
67+
tn.send(bytes(f'show pse port port-no {index}\r\n', "utf-8"))
68+
69+
status = tn.expect(['disable', 'enable'])
70+
71+
tn.send(b"quit\r\n")
72+
tn.expect(pexpect.EOF)
73+
74+
return True if status == 1 else False

0 commit comments

Comments
 (0)