(Late) initial commit, finalized controler for communication between TSE box serial interface and MQTT
This commit is contained in:
commit
7227decc36
5 changed files with 116 additions and 0 deletions
35
tse_serial/tse_serial_interpreter.py
Normal file
35
tse_serial/tse_serial_interpreter.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class RelayState:
|
||||
relay_id: int
|
||||
state: bool
|
||||
|
||||
|
||||
def resp_to_relay_state(cmd: str) -> RelayState:
|
||||
state = True if cmd.find("ON") > -1 else False
|
||||
#state = False if cmd.find("OFF") > -1 and state == None else None
|
||||
|
||||
r_state = RelayState(0, state)
|
||||
id = 0
|
||||
|
||||
if cmd.startswith("T"):
|
||||
id = int(cmd[1]) + (8 if cmd[2] == "B" else 0)
|
||||
elif cmd.startswith("re_"):
|
||||
id = int(cmd[3]) + (8 if cmd[4] == "B" else 0)
|
||||
|
||||
r_state = RelayState(id, state)
|
||||
return r_state
|
||||
|
||||
|
||||
def relay_state_to_cmd(r_state: RelayState) -> str:
|
||||
#r[NUM][CMD]
|
||||
cmd = 8 if r_state.state else 9
|
||||
id = r_state.relay_id
|
||||
# banka B
|
||||
if id > 8:
|
||||
cmd -= 2
|
||||
id -= 8
|
||||
return f"r{id}{cmd}"
|
||||
#return "r" + str(id) + str(cmd)
|
Loading…
Add table
Add a link
Reference in a new issue