added systemd service config files and misc changes, still need to finish writing the reworked tse box controller

This commit is contained in:
0xEmm 2024-11-07 17:07:29 +01:00
parent 81218eb21a
commit e595fb97ce
10 changed files with 131 additions and 8 deletions

View file

@ -4,8 +4,10 @@ import aioserial
import aiomqtt
from tse_serial_interpreter import *
room = 'p1' #TODO make be do get fronm file of configuration
aser: aioserial.AioSerial = aioserial.AioSerial(
port='/dev/cu.usbserial-14240',
port='/dev/cu.usbserial-14240', #TODO not hardcode it
baudrate=1200,
parity=serial.PARITY_NONE,
bytesize=serial.EIGHTBITS,
@ -13,13 +15,43 @@ aser: aioserial.AioSerial = aioserial.AioSerial(
)
# TODO adjust serial on actual TSE interface
mapping = {
"master": 1,
"audio": 2,
"projectors": 3,
"platno_glavni_dol": 5,
"platno_glavni_gor": 6,
"platno_stranski_dol": 7,
"platno_stranski_gor": 8,
"sencilo_dol": 9,
"sencilo_gor": 10
#ostalo reserved
}
reverse_lookup = {v: k for k, v in mapping.items()}
def parse_topic_from_mqtt(topic: str):
topicArr = topic.split()
async def task_status2mqtt(statusClient: aiomqtt.Client):
while True:
data = await aser.read_until_async()
data = data.decode(errors='ignore').strip()
print("TSE box sent: " + data)
relState = resp_to_relay_state(data)
publishTopic = f"p1/tseRelays/{relState.relay_id}/status"
command = reverse_lookup[relState.relay_id]
action = relState.state
#TODO havent figured out a clean way to
# get out the action from topic yet as they are
# not always on the same level
# probably just do it the most straight forward way
# with some more code
publishTopic = f"{room}/"
publishPayload = "ON" if relState.state else "OFF"
print("Publishing [" + publishPayload + "] to topic [" + publishTopic + "]")
await statusClient.publish(publishTopic, payload=publishPayload)
@ -34,7 +66,7 @@ async def task_command2serial(controlClient: aiomqtt.Client):
msgTopic = mesg.topic.value
cmnd = mesg.payload.decode()
print("Received: [" + msgTopic + "] payload: [" + cmnd + "]")
relay = int(mesg.topic.value.split("/")[-2])
relay = int(mesg.topic.value.split("/")[-2]) #TODO different by case
cmnd = cmnd == "ON"
relState = RelayState(relay, cmnd)
setRelay = relay_state_to_cmd(relState)