From 00954dfc1f0e0eb3ebd6d58807e2a660705a839a Mon Sep 17 00:00:00 2001 From: Ernst Klamer Date: Mon, 27 Feb 2023 16:40:08 +0100 Subject: [PATCH] Add gas sensor to BTHome (#88770) * Bump bthome * Add gas sensor --- homeassistant/components/bthome/manifest.json | 2 +- homeassistant/components/bthome/sensor.py | 10 ++++++++++ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/bthome/test_sensor.py | 17 +++++++++++++++++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/bthome/manifest.json b/homeassistant/components/bthome/manifest.json index 47f980c78fe..f875074a9ff 100644 --- a/homeassistant/components/bthome/manifest.json +++ b/homeassistant/components/bthome/manifest.json @@ -20,5 +20,5 @@ "dependencies": ["bluetooth_adapters"], "documentation": "https://www.home-assistant.io/integrations/bthome", "iot_class": "local_push", - "requirements": ["bthome-ble==2.5.2"] + "requirements": ["bthome-ble==2.7.0"] } diff --git a/homeassistant/components/bthome/sensor.py b/homeassistant/components/bthome/sensor.py index 4b378183489..98163957307 100644 --- a/homeassistant/components/bthome/sensor.py +++ b/homeassistant/components/bthome/sensor.py @@ -119,6 +119,16 @@ SENSOR_DESCRIPTIONS = { native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, ), + # Gas (m3) + ( + BTHomeSensorDeviceClass.GAS, + Units.VOLUME_CUBIC_METERS, + ): SensorEntityDescription( + key=f"{BTHomeSensorDeviceClass.GAS}_{Units.VOLUME_CUBIC_METERS}", + device_class=SensorDeviceClass.GAS, + native_unit_of_measurement=UnitOfVolume.CUBIC_METERS, + state_class=SensorStateClass.TOTAL_INCREASING, + ), # Humidity in (percent) (BTHomeSensorDeviceClass.HUMIDITY, Units.PERCENTAGE): SensorEntityDescription( key=f"{BTHomeSensorDeviceClass.HUMIDITY}_{Units.PERCENTAGE}", diff --git a/requirements_all.txt b/requirements_all.txt index 9bea267c26f..680c4ed043e 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -492,7 +492,7 @@ brunt==1.2.0 bt_proximity==0.2.1 # homeassistant.components.bthome -bthome-ble==2.5.2 +bthome-ble==2.7.0 # homeassistant.components.bt_home_hub_5 bthomehub5-devicelist==0.1.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 3e081f63a7c..7f428578537 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -399,7 +399,7 @@ brother==2.2.0 brunt==1.2.0 # homeassistant.components.bthome -bthome-ble==2.5.2 +bthome-ble==2.7.0 # homeassistant.components.buienradar buienradar==1.0.5 diff --git a/tests/components/bthome/test_sensor.py b/tests/components/bthome/test_sensor.py index 3b5c434c793..af01db0a6ef 100644 --- a/tests/components/bthome/test_sensor.py +++ b/tests/components/bthome/test_sensor.py @@ -844,6 +844,23 @@ async def test_v1_sensors( }, ], ), + ( + "A4:C1:38:8D:18:B2", + make_bthome_v2_adv( + "A4:C1:38:8D:18:B2", + b"\x40\x4b\x13\x8a\x14", + ), + None, + [ + { + "sensor_entity": "sensor.test_device_18b2_gas", + "friendly_name": "Test Device 18B2 Gas", + "unit_of_measurement": "m³", + "state_class": "total_increasing", + "expected_state": "1346.067", + }, + ], + ), ( "A4:C1:38:8D:18:B2", make_bthome_v2_adv(