pep8 et constante en majuscule

This commit is contained in:
Sébastien Reuiller 2021-12-14 23:55:27 +01:00
parent 0702cc0801
commit 2dc277e8a4
2 changed files with 53 additions and 26 deletions

24
setup.cfg Normal file
View file

@ -0,0 +1,24 @@
# - https://timothycrosley.github.io/isort/
# - https://github.com/timothycrosley/isort#configuring-isort
# - https://github.com/timothycrosley/isort/wiki/isort-Settings
[isort]
combine_as_imports = True
ensure_newline_before_comments = True
force_grid_wrap = 0
include_trailing_comma = True
known_first_party = itou
lines_after_imports = 2
line_length = 119
multi_line_output = 3
use_parentheses = True
# - https://www.flake8rules.com
# - http://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html#changing-the-ignore-list
[flake8]
# E203: Whitespace before ':', used to please Black in `yield items[i : i + n]`
# E266: Too many leading '#' for block comment
# W503: Line break occurred before a binary operator
ignore = E203, E266, W503
max-line-length = 119

View file

@ -22,16 +22,17 @@
# }
import serial
import logging
import time
import requests
from datetime import datetime
import requests
import serial
from influxdb import InfluxDBClient
# clés téléinfo
int_measure_keys = ['BASE', 'IMAX', 'HCHC', 'IINST', 'PAPP', 'ISOUSC', 'ADCO', 'HCHP']
no_checksum = ['MOTDETAT']
INT_MESURE_KEYS = ['BASE', 'IMAX', 'HCHC', 'IINST', 'PAPP', 'ISOUSC', 'ADCO', 'HCHP']
# création du logguer
logging.basicConfig(filename='/var/log/teleinfo/releve.log', level=logging.INFO, format='%(asctime)s %(message)s')
@ -39,17 +40,17 @@ logging.info("Teleinfo starting..")
# connexion a la base de données InfluxDB
client = InfluxDBClient('localhost', 8086)
db = "teleinfo"
DB_NAME = "teleinfo"
connected = False
while not connected:
try:
logging.info("Database %s exists?" % db)
if not {'name': db} in client.get_list_database():
logging.info("Database %s creation.." % db)
client.create_database(db)
logging.info("Database %s created!" % db)
client.switch_database(db)
logging.info("Connected to %s!" % db)
logging.info("Database %s exists?" % DB_NAME)
if not {'name': DB_NAME} in client.get_list_database():
logging.info("Database %s creation.." % DB_NAME)
client.create_database(DB_NAME)
logging.info("Database %s created!" % DB_NAME)
client.switch_database(DB_NAME)
logging.info("Connected to %s!" % DB_NAME)
except requests.exceptions.ConnectionError:
logging.info('InfluxDB is not reachable. Waiting 5 seconds to retry.')
time.sleep(5)
@ -106,14 +107,16 @@ def main():
logging.debug(line)
try:
[key, val, *_] = line_str.split(" ") # separation sur espace /!\ attention le caractere de controle 0x32 est un espace aussi
# separation sur espace /!\ attention le caractere de controle 0x32 est un espace aussi
[key, val, *_] = line_str.split(" ")
# supprimer les retours charriot et saut de ligne puis selectionne le caractere de controle en partant de la fin
# supprimer les retours charriot et saut de ligne puis selectionne le caractere
# de controle en partant de la fin
checksum = (line_str.replace('\x03\x02', ''))[-3:-2]
if verif_checksum(f"{key} {val}", checksum):
# creation du champ pour la trame en cours avec cast des valeurs de mesure en "integer"
trame[key] = int(val) if key in int_measure_keys else val
trame[key] = int(val) if key in INT_MESURE_KEYS else val
if b'\x03' in line: # si caractère de fin dans la ligne, on insère la trame dans influx
del trame['ADCO'] # adresse du compteur : confidentiel!