From c08245f87ed7993ab73db927b1c947c815da88e0 Mon Sep 17 00:00:00 2001 From: MartyTremblay Date: Tue, 10 Mar 2020 21:54:20 -0400 Subject: [PATCH] pygatt version bump and minor code refactoring --- custom_components/airthings_wave/airthings.py | 6 +++-- .../airthings_wave/manifest.json | 2 +- custom_components/airthings_wave/sensor.py | 22 +++++++------------ 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/custom_components/airthings_wave/airthings.py b/custom_components/airthings_wave/airthings.py index 1a8908c..d099dcc 100644 --- a/custom_components/airthings_wave/airthings.py +++ b/custom_components/airthings_wave/airthings.py @@ -141,10 +141,12 @@ def find_devices(self): self.airthing_devices.append(mac) except (BLEError, NotConnectedError, NotificationTimeout): _LOGGER.debug("connection to {} failed".format(mac)) - dev.disconnect() + finally: + dev.disconnect() except (BLEError, NotConnectedError, NotificationTimeout): _LOGGER.debug("Faild to connect") - self.adapter.stop() + finally: + self.adapter.stop() _LOGGER.debug("Found {} airthings devices".format(len(self.airthing_devices))) return len(self.airthing_devices) diff --git a/custom_components/airthings_wave/manifest.json b/custom_components/airthings_wave/manifest.json index ebed613..a8cdb29 100644 --- a/custom_components/airthings_wave/manifest.json +++ b/custom_components/airthings_wave/manifest.json @@ -5,6 +5,6 @@ "dependencies": [], "codeowners": ["@MartyTremblay"], "requirements": [ - "pygatt[GATTTOOL]==4.0.3" + "pygatt[GATTTOOL]==4.0.5" ] } diff --git a/custom_components/airthings_wave/sensor.py b/custom_components/airthings_wave/sensor.py index bd73b56..b12b078 100644 --- a/custom_components/airthings_wave/sensor.py +++ b/custom_components/airthings_wave/sensor.py @@ -13,7 +13,6 @@ https://home-assistant.io/components/sensor.airthings_wave/ """ import logging -import threading from datetime import timedelta from .airthings import AirthingsWaveDetect @@ -33,13 +32,8 @@ EVENT_HOMEASSISTANT_STOP, ILLUMINANCE, STATE_UNKNOWN) from homeassistant.helpers.entity import Entity -VERSION = '0.5.0' - -REQUIREMENTS = ['pygatt[GATTTOOL]==4.0.3'] _LOGGER = logging.getLogger(__name__) -DEFAULT_NAME = 'Airthings Wave' -CONNECT_LOCK = threading.Lock() CONNECT_TIMEOUT = 30 SCAN_INTERVAL = timedelta(seconds=300) @@ -118,14 +112,14 @@ def get_extra_attributes(self, data): return {ATTR_RADON_LEVEL: radon_level} -DEVICE_SENSOR_SPECIFICS = {"date_time":Sensor('time', None, None, None), - "temperature":Sensor(TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE, None), - "humidity": Sensor(PERCENT, None, DEVICE_CLASS_HUMIDITY, None), - "rel_atm_pressure": Sensor(ATM_METRIC_UNITS, None, DEVICE_CLASS_PRESSURE, None), - "co2": Sensor(CO2_METRIC_UNITS, None, DEVICE_CLASS_CO2, 'mdi:periodic-table-co2'), - "voc": Sensor(VOC_METRIC_UNITS, None, DEVICE_CLASS_VOC, 'mdi:cloud'), - "illuminance": Sensor(ILLUMINANCE_LUX, None, DEVICE_CLASS_ILLUMINANCE, None), - "accelerometer": Sensor(SPEED_METRIC_UNITS, None, DEVICE_CLASS_ACCELEROMETER, 'mdi:vibrate'), +DEVICE_SENSOR_SPECIFICS = { "date_time":Sensor('time', None, None, None), + "temperature":Sensor(TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE, None), + "humidity": Sensor(PERCENT, None, DEVICE_CLASS_HUMIDITY, None), + "rel_atm_pressure": Sensor(ATM_METRIC_UNITS, None, DEVICE_CLASS_PRESSURE, None), + "co2": Sensor(CO2_METRIC_UNITS, None, DEVICE_CLASS_CO2, 'mdi:periodic-table-co2'), + "voc": Sensor(VOC_METRIC_UNITS, None, DEVICE_CLASS_VOC, 'mdi:cloud'), + "illuminance": Sensor(ILLUMINANCE_LUX, None, DEVICE_CLASS_ILLUMINANCE, None), + "accelerometer": Sensor(SPEED_METRIC_UNITS, None, DEVICE_CLASS_ACCELEROMETER, 'mdi:vibrate'), "radon_1day_avg": RadonSensor(VOLUME_BECQUEREL, None, DEVICE_CLASS_RADON, 'mdi:radioactive'), "radon_longterm_avg": RadonSensor(VOLUME_BECQUEREL, None, DEVICE_CLASS_RADON, 'mdi:radioactive') }