From 69bda8e5f687854ac97c115f2e6ae6847f99b08b Mon Sep 17 00:00:00 2001 From: Schemen Date: Thu, 18 Feb 2021 10:33:56 +0100 Subject: [PATCH] Small updates --- README.md | 5 ++-- airthings-influxdb.py | 59 +++++++++++++++++++++++-------------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index d8c7812..5598cc1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # airthings-influxdb +This tool is using the library provided by kotlarz at https://github.com/kotlarz/airthings. Thanks for the project! ## Install ```x-sh @@ -26,6 +27,6 @@ Options: Commands: identify Lists available sensors nearby - start - verify verify your configuration + start Start collecting data from your airthings sensors + verify Verify your Influxdb configuration ``` diff --git a/airthings-influxdb.py b/airthings-influxdb.py index f4f4261..a3cfb58 100755 --- a/airthings-influxdb.py +++ b/airthings-influxdb.py @@ -31,7 +31,7 @@ def cli(ctx, debug, config): @cli.command() @click.pass_context def verify(ctx): - """verify your configuration - does not do much yet!""" + """Verify your Influxdb configuration""" config = read_config(ctx.obj['CONFIG']) influx_host = env.get("InfluxdbHost", config['DEFAULT']['InfluxdbHost']) @@ -41,32 +41,37 @@ def verify(ctx): influx_db = env.get("InfluxdbDatabase", config['DEFAULT']['InfluxdbDatabase']) client = InfluxDBClient(influx_host, influx_port, influx_user, influx_pass, influx_db) - + click.echo("Trying to connect to influxdb...") + try: + ping = client.ping() + click.echo("Success! Version: %s"% ping) + except InfluxDBClientError as e: + click.echo("An error occured: %s" % e) @cli.command() def identify(): """Lists available sensors nearby""" airthings_devices = fetch_measurements() - print("Found %s Airthings device(s):" % len(airthings_devices)) + click.echo("Found %s Airthings device(s):" % len(airthings_devices)) for device in airthings_devices: - print("=" * 36) - print("\tMAC address:", device.mac_address) - print("\tIdentifier:", device.identifier) - print("\tModel:", device.label) - print("\tModel number:", device.model_number) - print("\tHas measurements:", device.has_measurements) - print("\tSensor capabilities:") + click.echo("=" * 36) + click.echo("\tMAC address: %s" % device.mac_address) + click.echo("\tIdentifier: %s" % device.identifier) + click.echo("\tModel: %s" % device.label) + click.echo("\tModel number: %s" % device.model_number) + click.echo("\tHas measurements:" + str(device.has_measurements)) + click.echo("\tSensor capabilities:") for sensor, supported in device.sensor_capabilities.items(): - print("\t", sensor, "=", "YES" if supported else "NO") - print("+" * 11, "Measurements", "+" * 11) - print("\t", device.humidity) - print("\t", device.radon_short_term_avg) - print("\t", device.radon_long_term_avg) - print("\t", device.temperature) - print("\t", device.atmospheric_pressure) - print("\t", device.co2) - print("\t", device.voc) + click.echo("\t" + sensor + "=" + "YES" if supported else "\t" + "NO") + click.echo("+" * 11 + "Measurements" + "+" * 11) + click.echo("\t %s" % device.humidity) + click.echo("\t %s" % device.radon_short_term_avg) + click.echo("\t %s" % device.radon_long_term_avg) + click.echo("\t %s" % device.temperature) + click.echo("\t %s" % device.atmospheric_pressure) + click.echo("\t %s" % device.co2) + click.echo("\t %s" % device.voc) @@ -75,7 +80,7 @@ def identify(): @click.pass_context def start(ctx): """ - + Start collecting data from your airthings sensors """ click.echo("Starting the Airthings to Influxdb Bridge") click.echo("Reading the config...") @@ -98,14 +103,14 @@ def start(ctx): while True: click.echo("Searching devices...") airthings_devices = fetch_measurements() - print("Found %s Airthings devices:" % len(airthings_devices)) + click.echo("Found %s Airthings devices:" % len(airthings_devices)) for device in airthings_devices: - print("=" * 36) - print("\tMAC address:", device.mac_address) - print("\tIdentifier:", device.identifier) - print("\tModel:", device.label) - print("\tModel number:", device.model_number) - print("\tHas measurements:", device.has_measurements) + click.echo("=" * 36) + click.echo("\tMAC address: %s" % device.mac_address) + click.echo("\tIdentifier: %s" % device.identifier) + click.echo("\tModel: %s" % device.label) + click.echo("\tModel number: %s" % device.model_number) + click.echo("\tHas measurements: %s" % device.has_measurements) click.echo("Collecting sensor data...") now = datetime.datetime.now()