ThomDietrich/miflora-mqtt-daemon

config load error

Opened this issue · 3 comments

when I run the python script, I get this error:
Traceback (most recent call last):
File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 126, in
reporting_mode = config['General'].get('reporting_method', 'mqtt-json')
File "/usr/lib/python3.5/configparser.py", line 956, in getitem
raise KeyError(key)
KeyError: 'General'

What am I doing wrong?

my config is this:

# Configuration file for Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
# Source: https://github.com/ThomDietrich/miflora-mqtt-daemon
#
# Uncomment and adapt all settings as needed.
[General]
reporting_method = mqtt-json
adapter = hci0
[Daemon]
enabled = true
period = 300
[MQTT]
hostname = localhost
port = 1883
keepalive = 60
base_topic = miflora                   # Default for: mqtt-json, mqtt-smarthome
homie_device_id = miflora-mqtt-daemon
# The MQTT broker authentification credentials (Default: no authentication)
#username = user
#password = pwd123
# Enable TLS/SSL on the connection
tls = false
# Path to CA Certificate file to verify host
#tls_ca_cert =
# Path to TLS client auth key file
#tls_keyfile =
# Path to TLS client auth certificate file
#tls_certfile =
[Sensors]
BonsaiKitchen = C4:XXXXXXX # real mac address to be inserted

ERROR 40 <-- my fault. it couldn't find the config file

Happy for you you fixed the issue. I think it's worth catching the error. Would you like to propose a PR?

Also see: https://stackoverflow.com/a/18091313/6654920

And my suggestion on how to react:

print_line('No sensors found in configuration file "config.ini"', error=True, sd_notify=True)
sys.exit(1)

Happy for you you fixed the issue. I think it's worth catching the error. Would you like to propose a PR?

Also see: https://stackoverflow.com/a/18091313/6654920

And my suggestion on how to react:

print_line('No sensors found in configuration file "config.ini"', error=True, sd_notify=True)
sys.exit(1)

As I ran in the same situation (but was aware of the missing config g), a suitable error message would be better. I'll create one