Skip to content

Commit c08245f

Browse files
committed
pygatt version bump and minor code refactoring
1 parent 0cdaba8 commit c08245f

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

custom_components/airthings_wave/airthings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,12 @@ def find_devices(self):
141141
self.airthing_devices.append(mac)
142142
except (BLEError, NotConnectedError, NotificationTimeout):
143143
_LOGGER.debug("connection to {} failed".format(mac))
144-
dev.disconnect()
144+
finally:
145+
dev.disconnect()
145146
except (BLEError, NotConnectedError, NotificationTimeout):
146147
_LOGGER.debug("Faild to connect")
147-
self.adapter.stop()
148+
finally:
149+
self.adapter.stop()
148150

149151
_LOGGER.debug("Found {} airthings devices".format(len(self.airthing_devices)))
150152
return len(self.airthing_devices)

custom_components/airthings_wave/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"dependencies": [],
66
"codeowners": ["@MartyTremblay"],
77
"requirements": [
8-
"pygatt[GATTTOOL]==4.0.3"
8+
"pygatt[GATTTOOL]==4.0.5"
99
]
1010
}

custom_components/airthings_wave/sensor.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
https://home-assistant.io/components/sensor.airthings_wave/
1414
"""
1515
import logging
16-
import threading
1716
from datetime import timedelta
1817

1918
from .airthings import AirthingsWaveDetect
@@ -33,13 +32,8 @@
3332
EVENT_HOMEASSISTANT_STOP, ILLUMINANCE,
3433
STATE_UNKNOWN)
3534
from homeassistant.helpers.entity import Entity
36-
VERSION = '0.5.0'
37-
38-
REQUIREMENTS = ['pygatt[GATTTOOL]==4.0.3']
3935

4036
_LOGGER = logging.getLogger(__name__)
41-
DEFAULT_NAME = 'Airthings Wave'
42-
CONNECT_LOCK = threading.Lock()
4337
CONNECT_TIMEOUT = 30
4438
SCAN_INTERVAL = timedelta(seconds=300)
4539

@@ -118,14 +112,14 @@ def get_extra_attributes(self, data):
118112
return {ATTR_RADON_LEVEL: radon_level}
119113

120114

121-
DEVICE_SENSOR_SPECIFICS = {"date_time":Sensor('time', None, None, None),
122-
"temperature":Sensor(TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE, None),
123-
"humidity": Sensor(PERCENT, None, DEVICE_CLASS_HUMIDITY, None),
124-
"rel_atm_pressure": Sensor(ATM_METRIC_UNITS, None, DEVICE_CLASS_PRESSURE, None),
125-
"co2": Sensor(CO2_METRIC_UNITS, None, DEVICE_CLASS_CO2, 'mdi:periodic-table-co2'),
126-
"voc": Sensor(VOC_METRIC_UNITS, None, DEVICE_CLASS_VOC, 'mdi:cloud'),
127-
"illuminance": Sensor(ILLUMINANCE_LUX, None, DEVICE_CLASS_ILLUMINANCE, None),
128-
"accelerometer": Sensor(SPEED_METRIC_UNITS, None, DEVICE_CLASS_ACCELEROMETER, 'mdi:vibrate'),
115+
DEVICE_SENSOR_SPECIFICS = { "date_time":Sensor('time', None, None, None),
116+
"temperature":Sensor(TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE, None),
117+
"humidity": Sensor(PERCENT, None, DEVICE_CLASS_HUMIDITY, None),
118+
"rel_atm_pressure": Sensor(ATM_METRIC_UNITS, None, DEVICE_CLASS_PRESSURE, None),
119+
"co2": Sensor(CO2_METRIC_UNITS, None, DEVICE_CLASS_CO2, 'mdi:periodic-table-co2'),
120+
"voc": Sensor(VOC_METRIC_UNITS, None, DEVICE_CLASS_VOC, 'mdi:cloud'),
121+
"illuminance": Sensor(ILLUMINANCE_LUX, None, DEVICE_CLASS_ILLUMINANCE, None),
122+
"accelerometer": Sensor(SPEED_METRIC_UNITS, None, DEVICE_CLASS_ACCELEROMETER, 'mdi:vibrate'),
129123
"radon_1day_avg": RadonSensor(VOLUME_BECQUEREL, None, DEVICE_CLASS_RADON, 'mdi:radioactive'),
130124
"radon_longterm_avg": RadonSensor(VOLUME_BECQUEREL, None, DEVICE_CLASS_RADON, 'mdi:radioactive')
131125
}

0 commit comments

Comments
 (0)