feat: Proper configuration.

This commit is contained in:
Laur Ivan 2022-12-20 15:39:41 +01:00
parent 135802109e
commit d52d6ec6d9
9 changed files with 20 additions and 15 deletions

0
.dockerignore Normal file
View File

2
.env
View File

@ -4,4 +4,4 @@ KNX_TOPOLOGY=export-addresses.csv
INFLUX_BUCKET=my_bucket INFLUX_BUCKET=my_bucket
INFLUX_ORG=example.com INFLUX_ORG=example.com
INFLUX_TOKEN=change_me INFLUX_TOKEN=change_me
INFLUX_URL=http://localhost:8086 INFLUX_URL=http://10.0.0.27:40086

4
.gitignore vendored
View File

@ -1,3 +1,5 @@
venv/ venv/
requirements/ requirements/
__py*/ __py*/
.env
./*.csv

View File

@ -15,12 +15,8 @@ ENV INFLUX_TOKEN=change_me
ENV INFLUX_URL=http://localhost:8086 ENV INFLUX_URL=http://localhost:8086
COPY ./*.py /code/knx COPY ./*.py /code/knx
COPY ./.env /code/knx COPY ./defaults/.env /code/knx
COPY ./defaults/export-addresses.csv /code/knx
CMD ["python", "knx_monitor.py"]
ENV CONFIG_STRUCTURE=/code/data/export-addresses.csv # CMD ["ls", "-lsrtaR"]
VOLUME ["/code/data/export-addresses.csv", "/code/knx/.env"]
CMD ["python", "knx_monitor.py"]

9
db.py
View File

@ -3,6 +3,7 @@ from influxdb_client.client.write_api import SYNCHRONOUS
from dotenv import load_dotenv from dotenv import load_dotenv
import os import os
from os.path import dirname, join
dotenv_path = join(dirname(__file__), '.env') dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path) load_dotenv(dotenv_path)
@ -16,5 +17,9 @@ write_api = client.write_api(write_options=SYNCHRONOUS)
def publish_measurement(value): def publish_measurement(value):
p = influxdb_client.Point(f'KNX-{value["type"]}').tag("name", f'{value["name"]}').tag("destination", f'{value["destination"]}').tag("description", f'{value["description"]}').field("value", value["value"]) try:
write_api.write(bucket=bucket, org=org, record=p) p = influxdb_client.Point(f'KNX-{value["type"]}').tag("name", f'{value["name"]}').tag("destination", f'{value["destination"]}').tag("description", f'{value["description"]}').field("value", value["value"])
write_api.write(bucket=bucket, org=org, record=p)
except Exception as e:
print(f"Could not send value {value} to {url}")
print(e)

View File

@ -0,0 +1 @@
"Group name";"Address";"Central";"Unfiltered";"Description";"DatapointType";"Security"
1 Group name Address Central Unfiltered Description DatapointType Security

View File

@ -3,6 +3,8 @@ import asyncio
import getopt import getopt
import sys import sys
import os
from os.path import dirname, join
from xknx import XKNX from xknx import XKNX
from xknx.io import ConnectionConfig, ConnectionType from xknx.io import ConnectionConfig, ConnectionType
from xknx.telegram import AddressFilter from xknx.telegram import AddressFilter
@ -18,9 +20,6 @@ from db import publish_measurement
config = {} config = {}
mapping = {} mapping = {}
async def telegram_received_cb(telegram): async def telegram_received_cb(telegram):
"""Do something with the received telegram.""" """Do something with the received telegram."""
val = parse_message(config, mapping, telegram) val = parse_message(config, mapping, telegram)

View File

@ -56,6 +56,7 @@ def init_value_mapping():
def load_structure(filename): def load_structure(filename):
print(f"Configuration file: {filename}")
config = {} config = {}
with open(filename, newline='') as csvFile: with open(filename, newline='') as csvFile:
line = 0 line = 0
@ -98,6 +99,7 @@ def parse_message(structure, mapping, telegram):
if __name__ == '__main__': if __name__ == '__main__':
from os.path import dirname, join
from dotenv import load_dotenv from dotenv import load_dotenv
dotenv_path = join(dirname(__file__), '.env') dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path) load_dotenv(dotenv_path)