small reworks in frontend and scripts, mostly finalized ansible deploy script -- still needs testing
This commit is contained in:
parent
f41dfc4f86
commit
e57f803a52
25 changed files with 440 additions and 90 deletions
|
@ -4,26 +4,42 @@ import aioserial
|
|||
import aiomqtt
|
||||
from tse_serial_interpreter import *
|
||||
from dataclasses import dataclass
|
||||
import os
|
||||
import sys
|
||||
import toml
|
||||
import serial.tools.list_ports
|
||||
|
||||
room = 'p01' #TODO make be do get fronm file of configuration
|
||||
|
||||
# serPath = '/dev/serial/by-id/'
|
||||
# devLst = os.listdir(serPath)
|
||||
# if len(devLst) < 1:
|
||||
# sys.exit("No serial device found.")
|
||||
# serDev = devLst[0]
|
||||
|
||||
portList = serial.tools.list_ports.comports()
|
||||
if portList < 1:
|
||||
sys.exit("No serial port found")
|
||||
#TODO if multiple ports idk, shouldn't ever happen but still
|
||||
(serport, serdesc, serhwid) = portList[0]
|
||||
|
||||
|
||||
aser: aioserial.AioSerial = aioserial.AioSerial(
|
||||
port='/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port0',
|
||||
#id say not hardcode it ampak kinda nimamo izbire
|
||||
port=serport,
|
||||
baudrate=1200,
|
||||
parity=serial.PARITY_NONE,
|
||||
bytesize=serial.EIGHTBITS,
|
||||
stopbits=serial.STOPBITS_ONE
|
||||
)
|
||||
|
||||
#TODO get this from file da ni hardcoded
|
||||
|
||||
#TODO get this from file da ni hardcoded?
|
||||
# altho itak je ta script za tist specific tse box in so vsi isti
|
||||
mapping_toggles = {
|
||||
"master": 1,
|
||||
"audio": 2,
|
||||
"projectors": 3,
|
||||
}
|
||||
|
||||
# 4 is not connected to anything
|
||||
platno_mapping = {
|
||||
"glavni": {
|
||||
"dol": 5,
|
||||
|
@ -40,26 +56,34 @@ shades_mapping = {
|
|||
"gor": 10
|
||||
}
|
||||
|
||||
#reverse_lookup = {v: k for k, v in mapping.items()} #fujto
|
||||
reverse_lookup = {
|
||||
1: "master",
|
||||
2: "audio",
|
||||
3: "projectors",
|
||||
|
||||
5: "glavni_dol",
|
||||
6: "glavni_gor",
|
||||
|
||||
7: "glavni_dol",
|
||||
8: "glavni_gor",
|
||||
|
||||
9: "shades_dol",
|
||||
10: "shades_gor"
|
||||
}
|
||||
|
||||
# TODO simple reverse lookup za ko kripa pove kaj
|
||||
# in vse tole
|
||||
|
||||
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)
|
||||
#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
|
||||
# REWORK
|
||||
# probably just do it the most straight forward way
|
||||
# with some more code
|
||||
data = await aser.read_until_async()
|
||||
data = data.decode(errors='ignore').strip()
|
||||
print("TSE box sent: " + data)
|
||||
relState = resp_to_relay_state(data)
|
||||
if relState.relay_id == None:
|
||||
continue # TODO handling
|
||||
command = reverse_lookup[relState.relay_id]
|
||||
|
||||
action = relState.state
|
||||
|
||||
#publishTopic = f"{room}/"
|
||||
#publishPayload = "ON" if relState.state else "OFF"
|
||||
#print("Publishing [" + publishPayload + "] to topic [" + publishTopic + "]")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue