Autodetect USB teleinfo device.
This commit is contained in:
parent
41bd4e1465
commit
bcb565a559
@ -8,13 +8,25 @@ import argparse
|
|||||||
import json
|
import json
|
||||||
from teleinfo import Parser
|
from teleinfo import Parser
|
||||||
from teleinfo.hw_vendors import UTInfo2
|
from teleinfo.hw_vendors import UTInfo2
|
||||||
|
import subprocess
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Téléinfo retriever.')
|
parser = argparse.ArgumentParser(description='Téléinfo retriever.')
|
||||||
parser.add_argument("-f", "--format", help="Output format.",
|
parser.add_argument("-f", "--format", help="Output format.",
|
||||||
type=str, choices=['human-readable', 'raw_json', 'custom_json'], default='human-readable')
|
type=str, choices=['human-readable', 'raw_json', 'custom_json'], default='human-readable')
|
||||||
args = parser.parse_args()
|
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()
|
res = ti.get_frame()
|
||||||
|
|
||||||
if args.format == 'human-readable':
|
if args.format == 'human-readable':
|
||||||
|
Loading…
Reference in New Issue
Block a user