Skip to content

Commit

Permalink
Stop the daemon from crashing if connection to a MiFlora device fails
Browse files Browse the repository at this point in the history
Fixes #39
  • Loading branch information
insertjokehere authored and ThomDietrich committed Jun 17, 2018
1 parent 04aeeba commit 4888937
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions miflora-mqtt-daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from configparser import ConfigParser
from unidecode import unidecode
from miflora.miflora_poller import MiFloraPoller, MI_BATTERY, MI_CONDUCTIVITY, MI_LIGHT, MI_MOISTURE, MI_TEMPERATURE
from btlewrap import available_backends, BluepyBackend, GatttoolBackend, PygattBackend
from btlewrap import available_backends, BluepyBackend, GatttoolBackend, PygattBackend, BluetoothBackendException
import paho.mqtt.client as mqtt
import sdnotify

Expand Down Expand Up @@ -218,7 +218,7 @@ def flores_to_openhab_items(flores, reporting_mode):
flora_poller.fill_cache()
flora_poller.parameter_value(MI_LIGHT)
flora['firmware'] = flora_poller.firmware_version()
except IOError:
except (IOError, BluetoothBackendException):
print_line('Initial connection to Mi Flora sensor "{}" ({}) failed.'.format(name_pretty, mac), error=True, sd_notify=True)
else:
print('Internal name: "{}"'.format(name_clean))
Expand Down Expand Up @@ -314,7 +314,7 @@ def flores_to_openhab_items(flores, reporting_mode):
try:
flora['poller'].fill_cache()
flora['poller'].parameter_value(MI_LIGHT)
except IOError:
except (IOError, BluetoothBackendException):
attempts = attempts - 1
if attempts > 0:
print_line('Retrying ...', warning = True)
Expand Down

0 comments on commit 4888937

Please sign in to comment.