From d1969fd0c222550537ec8def29c68d1e010ca87f Mon Sep 17 00:00:00 2001 From: Ernst Klamer Date: Tue, 14 Mar 2023 19:26:05 +0100 Subject: [PATCH] Add water sensor to bthome (#89595) * Add water sensor to bthome * Use TOTAL state class for gas water and energy --- homeassistant/components/bthome/manifest.json | 2 +- homeassistant/components/bthome/sensor.py | 14 +++++++++-- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/bthome/test_sensor.py | 23 ++++++++++++++++--- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/bthome/manifest.json b/homeassistant/components/bthome/manifest.json index da8f719bf70..87a84e5fab0 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.8.0"] + "requirements": ["bthome-ble==2.9.0"] } diff --git a/homeassistant/components/bthome/sensor.py b/homeassistant/components/bthome/sensor.py index 98163957307..9b5def30054 100644 --- a/homeassistant/components/bthome/sensor.py +++ b/homeassistant/components/bthome/sensor.py @@ -117,7 +117,7 @@ SENSOR_DESCRIPTIONS = { key=f"{BTHomeSensorDeviceClass.ENERGY}_{Units.ENERGY_KILO_WATT_HOUR}", device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, - state_class=SensorStateClass.TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL, ), # Gas (m3) ( @@ -127,7 +127,7 @@ SENSOR_DESCRIPTIONS = { key=f"{BTHomeSensorDeviceClass.GAS}_{Units.VOLUME_CUBIC_METERS}", device_class=SensorDeviceClass.GAS, native_unit_of_measurement=UnitOfVolume.CUBIC_METERS, - state_class=SensorStateClass.TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL, ), # Humidity in (percent) (BTHomeSensorDeviceClass.HUMIDITY, Units.PERCENTAGE): SensorEntityDescription( @@ -297,6 +297,16 @@ SENSOR_DESCRIPTIONS = { native_unit_of_measurement=UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR, state_class=SensorStateClass.MEASUREMENT, ), + # Water (L) + ( + BTHomeSensorDeviceClass.WATER, + Units.VOLUME_LITERS, + ): SensorEntityDescription( + key=f"{BTHomeSensorDeviceClass.WATER}_{Units.VOLUME_LITERS}", + device_class=SensorDeviceClass.WATER, + native_unit_of_measurement=UnitOfVolume.LITERS, + state_class=SensorStateClass.TOTAL, + ), } diff --git a/requirements_all.txt b/requirements_all.txt index 9aa47dde7f0..fb6a0c4e600 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.8.0 +bthome-ble==2.9.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 2844a2abe75..df875eccea6 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -402,7 +402,7 @@ brother==2.3.0 brunt==1.2.0 # homeassistant.components.bthome -bthome-ble==2.8.0 +bthome-ble==2.9.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 af01db0a6ef..7893ad3cb44 100644 --- a/tests/components/bthome/test_sensor.py +++ b/tests/components/bthome/test_sensor.py @@ -188,7 +188,7 @@ _LOGGER = logging.getLogger(__name__) "sensor_entity": "sensor.test_device_18b2_energy", "friendly_name": "Test Device 18B2 Energy", "unit_of_measurement": "kWh", - "state_class": "total_increasing", + "state_class": "total", "expected_state": "1346.067", }, ], @@ -542,7 +542,7 @@ async def test_v1_sensors( "sensor_entity": "sensor.test_device_18b2_energy", "friendly_name": "Test Device 18B2 Energy", "unit_of_measurement": "kWh", - "state_class": "total_increasing", + "state_class": "total", "expected_state": "1346.067", }, ], @@ -856,11 +856,28 @@ async def test_v1_sensors( "sensor_entity": "sensor.test_device_18b2_gas", "friendly_name": "Test Device 18B2 Gas", "unit_of_measurement": "m³", - "state_class": "total_increasing", + "state_class": "total", "expected_state": "1346.067", }, ], ), + ( + "A4:C1:38:8D:18:B2", + make_bthome_v2_adv( + "A4:C1:38:8D:18:B2", + b"\x40\x4f\x87\x56\x2a\x01", + ), + None, + [ + { + "sensor_entity": "sensor.test_device_18b2_water", + "friendly_name": "Test Device 18B2 Water", + "unit_of_measurement": "L", + "state_class": "total", + "expected_state": "19551.879", + }, + ], + ), ( "A4:C1:38:8D:18:B2", make_bthome_v2_adv(