Add water sensor to bthome (#89595)

* Add water sensor to bthome

* Use TOTAL state class for gas water and energy
This commit is contained in:
Ernst Klamer 2023-03-14 19:26:05 +01:00 committed by GitHub
parent 71dc98a39c
commit d1969fd0c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 8 deletions

View File

@ -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"]
}

View File

@ -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,
),
}

View File

@ -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

View File

@ -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

View File

@ -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": "",
"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(