From f53a29b5313036dbb374bfb4972db5070440d171 Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Sat, 19 Sep 2020 22:45:01 +0300 Subject: [PATCH] Add support smoke and gas sensors --- custom_components/xiaomi_gateway3/binary_sensor.py | 3 ++- custom_components/xiaomi_gateway3/sensor.py | 14 +++++++++++++- custom_components/xiaomi_gateway3/utils.py | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/custom_components/xiaomi_gateway3/binary_sensor.py b/custom_components/xiaomi_gateway3/binary_sensor.py index 0f9ee27f..731c4e96 100644 --- a/custom_components/xiaomi_gateway3/binary_sensor.py +++ b/custom_components/xiaomi_gateway3/binary_sensor.py @@ -62,7 +62,8 @@ def _set_no_motion(self, *args): def update(self, data: dict = None): if self._attr not in data: return - self._state = data[self._attr] == 1 + # gas and smoke => 1 and 2 + self._state = data[self._attr] >= 1 self.schedule_update_ha_state() if self._state: diff --git a/custom_components/xiaomi_gateway3/sensor.py b/custom_components/xiaomi_gateway3/sensor.py index ff5ff701..10b3c514 100644 --- a/custom_components/xiaomi_gateway3/sensor.py +++ b/custom_components/xiaomi_gateway3/sensor.py @@ -14,7 +14,15 @@ DEVICE_CLASS_PRESSURE: 'hPa', DEVICE_CLASS_ILLUMINANCE: 'lm', DEVICE_CLASS_POWER: POWER_WATT, - 'consumption': ENERGY_WATT_HOUR + 'consumption': ENERGY_WATT_HOUR, + 'gas density': '% LEL', + 'smoke density': '% obs/ft', +} + +ICONS = { + 'consumption': 'mdi:flash', + 'gas density': 'mdi:google-circles-communities', + 'smoke density': 'mdi:google-circles-communities', } @@ -43,6 +51,10 @@ def device_class(self): def unit_of_measurement(self): return UNITS.get(self._attr) + @property + def icon(self): + return ICONS.get(self._attr) + def update(self, data: dict = None): if self._attr not in data: return diff --git a/custom_components/xiaomi_gateway3/utils.py b/custom_components/xiaomi_gateway3/utils.py index 002b2df5..2fffba2f 100644 --- a/custom_components/xiaomi_gateway3/utils.py +++ b/custom_components/xiaomi_gateway3/utils.py @@ -244,6 +244,20 @@ ['2.1', '2.1', 'illuminance', 'sensor'], ['3.1', '3.1', 'battery', 'sensor'], ] +}, { + 'lumi.sensor_smoke': ["Honeywell", "Smoke Sensor", "JTYJ-GD-01LM/BW"], + 'params': [ + ['0.1.85', 'density', 'smoke density', 'sensor'], + ['13.1.85', 'alarm', 'smoke', 'binary_sensor'], + ['8.0.2001', 'battery', 'battery', 'sensor'], + ] +}, { + 'lumi.sensor_natgas': ["Honeywell", "Gas Sensor", "JTQJ-BF-01LM/BW"], + 'params': [ + ['0.1.85', 'density', 'gas density', 'sensor'], + ['13.1.85', 'alarm', 'gas', 'binary_sensor'], + ['8.0.2001', 'battery', 'battery', 'sensor'], + ] }, { # OTHER MANUFACTURERS 'TRADFRI bulb E27 W opal 1000lm': ["IKEA", "Bulb E27"], 'LWB010': ["Philips", "Hue Bulb E27"],