Skip to content

Commit

Permalink
pygatt version bump and minor code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MartyTremblay committed Mar 11, 2020
1 parent 0cdaba8 commit c08245f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
6 changes: 4 additions & 2 deletions custom_components/airthings_wave/airthings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/airthings_wave/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"dependencies": [],
"codeowners": ["@MartyTremblay"],
"requirements": [
"pygatt[GATTTOOL]==4.0.3"
"pygatt[GATTTOOL]==4.0.5"
]
}
22 changes: 8 additions & 14 deletions custom_components/airthings_wave/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
https://home-assistant.io/components/sensor.airthings_wave/
"""
import logging
import threading
from datetime import timedelta

from .airthings import AirthingsWaveDetect
Expand All @@ -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)

Expand Down Expand Up @@ -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')
}
Expand Down

0 comments on commit c08245f

Please sign in to comment.