Autodetect USB teleinfo device.

This commit is contained in:
yohan 2024-06-08 22:00:17 +02:00
parent 41bd4e1465
commit bcb565a559

View File

@ -8,13 +8,25 @@ import argparse
import json
from teleinfo import Parser
from teleinfo.hw_vendors import UTInfo2
import subprocess
parser = argparse.ArgumentParser(description='Téléinfo retriever.')
parser.add_argument("-f", "--format", help="Output format.",
type=str, choices=['human-readable', 'raw_json', 'custom_json'], default='human-readable')
args = parser.parse_args()
ti = Parser(UTInfo2(port="/dev/ttyUSB0"))
find_ttyUSB_output = subprocess.check_output(["./find_ttyUSB.sh"])
device = None
for line in find_ttyUSB_output.decode('utf-8').split("\n"):
if "Cartelectronic_Interface_USB_1_TIC_DA6TLO1X" in line:
device = line.split(" ")[0]
break
if device is None:
print ("USB teleinfo device not found.")
sys.exit(1)
ti = Parser(UTInfo2(port=device))
res = ti.get_frame()
if args.format == 'human-readable':