diff --git a/read_teleinfo.py b/read_teleinfo.py index f10e3d8..9b6b288 100755 --- a/read_teleinfo.py +++ b/read_teleinfo.py @@ -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':