From 4c8aa70cc716c3184b52e07b1015087ebdb9c650 Mon Sep 17 00:00:00 2001 From: Ernst Klamer Date: Sat, 23 Sep 2023 19:34:31 +0200 Subject: [PATCH] add more sensors --- .../ble_monitor/ble_parser/bthome_const.py | 4 +- custom_components/ble_monitor/const.py | 131 ++++++++++++++++++ .../ble_monitor/test/test_bthome_v2.py | 4 +- 3 files changed, 135 insertions(+), 4 deletions(-) diff --git a/custom_components/ble_monitor/ble_parser/bthome_const.py b/custom_components/ble_monitor/ble_parser/bthome_const.py index e898b6ac0..a2fac78ad 100644 --- a/custom_components/ble_monitor/ble_parser/bthome_const.py +++ b/custom_components/ble_monitor/ble_parser/bthome_const.py @@ -228,7 +228,7 @@ class MeasTypes: factor=0.1, ), 0x40: MeasTypes( - meas_format="distance", + meas_format="distance mm", unit_of_measurement="mm", data_length=2, ), @@ -275,7 +275,7 @@ class MeasTypes: factor=0.1, ), 0x48: MeasTypes( - meas_format="volume", + meas_format="volume mL", unit_of_measurement="mL", data_length=2, ), diff --git a/custom_components/ble_monitor/const.py b/custom_components/ble_monitor/const.py index 7a879ad41..a178ffdcb 100755 --- a/custom_components/ble_monitor/const.py +++ b/custom_components/ble_monitor/const.py @@ -898,6 +898,55 @@ class BLEMonitorBinarySensorEntityDescription( native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS, suggested_display_precision=0, + state_class=SensorStateClass.MEASUREMENT, + ), + BLEMonitorSensorEntityDescription( + key="uv index", + sensor_class="MeasuringSensor", + update_behavior="Averaging", + name="UV index", + unique_id="uv_index_", + icon="mdi:weather-sunny", + native_unit_of_measurement=None, + device_class=None, + suggested_display_precision=1, + state_class=SensorStateClass.MEASUREMENT, + ), + BLEMonitorSensorEntityDescription( + key="volume", + sensor_class="MeasuringSensor", + update_behavior="Averaging", + name="volume", + unique_id="volume_", + icon="mdi:wave", + native_unit_of_measurement=UnitOfVolume.LITERS, + device_class=None, + suggested_display_precision=1, + state_class=SensorStateClass.MEASUREMENT, + ), + BLEMonitorSensorEntityDescription( + key="volume mL", + sensor_class="MeasuringSensor", + update_behavior="Averaging", + name="volume_mL", + unique_id="volume_mL_", + icon="mdi:wave", + native_unit_of_measurement=UnitOfVolume.MILLILITERS, + device_class=None, + suggested_display_precision=0, + state_class=SensorStateClass.MEASUREMENT, + ), + BLEMonitorSensorEntityDescription( + key="volume flow rate", + sensor_class="MeasuringSensor", + update_behavior="Averaging", + name="volume flow rate", + unique_id="volume_flow_rate_", + icon="mdi:wave", + native_unit_of_measurement="m3/hr", + device_class=None, + suggested_display_precision=3, + state_class=SensorStateClass.MEASUREMENT, ), BLEMonitorSensorEntityDescription( key="aqi", @@ -1042,6 +1091,78 @@ class BLEMonitorBinarySensorEntityDescription( suggested_display_precision=0, state_class=SensorStateClass.TOTAL, ), + BLEMonitorSensorEntityDescription( + key="rotation", + sensor_class="InstantUpdateSensor", + update_behavior="Instantly", + name="ble rotation", + unique_id="rotation_", + icon="mdi:rotate-left", + native_unit_of_measurement="°", + device_class=None, + suggested_display_precision=1, + state_class=SensorStateClass.MEASUREMENT, + ), + BLEMonitorSensorEntityDescription( + key="distance", + sensor_class="InstantUpdateSensor", + update_behavior="Instantly", + name="ble distance", + unique_id="distance_", + icon="mdi:map-marker-distance", + native_unit_of_measurement="m", + device_class=None, + suggested_display_precision=1, + state_class=SensorStateClass.MEASUREMENT, + ), + BLEMonitorSensorEntityDescription( + key="distance mm", + sensor_class="InstantUpdateSensor", + update_behavior="Instantly", + name="ble distance_mm", + unique_id="distance_mm_", + icon="mdi:map-marker-distance", + native_unit_of_measurement="mm", + device_class=None, + suggested_display_precision=0, + state_class=SensorStateClass.MEASUREMENT, + ), + BLEMonitorSensorEntityDescription( + key="duration", + sensor_class="InstantUpdateSensor", + update_behavior="Instantly", + name="duration", + unique_id="duration_", + icon="mdi:clock-time-eight", + native_unit_of_measurement="s", + device_class=None, + suggested_display_precision=3, + state_class=SensorStateClass.MEASUREMENT, + ), + BLEMonitorSensorEntityDescription( + key="current", + sensor_class="InstantUpdateSensor", + update_behavior="Instantly", + name="current", + unique_id="current_", + icon="mdi:sine-wave", + native_unit_of_measurement="A", + device_class=None, + suggested_display_precision=3, + state_class=SensorStateClass.MEASUREMENT, + ), + BLEMonitorSensorEntityDescription( + key="speed", + sensor_class="InstantUpdateSensor", + update_behavior="Instantly", + name="speed", + unique_id="speed_", + icon="mdi:speedometer", + native_unit_of_measurement="m/s", + device_class=None, + suggested_display_precision=2, + state_class=SensorStateClass.MEASUREMENT, + ), BLEMonitorSensorEntityDescription( key="pulse", sensor_class="InstantUpdateSensor", @@ -1704,8 +1825,12 @@ class BLEMonitorBinarySensorEntityDescription( "co2", "conductivity", "count", + "current", "dewpoint", "dimmer", + "distance", + "distance mm", + "duration", "energy", "gravity", "humidity", @@ -1719,12 +1844,18 @@ class BLEMonitorBinarySensorEntityDescription( "power", "pressure", "pulse", + "rotation", + "speed", "steps", "rssi", "temperature", "temperature probe 1", "tvoc", + "uv index", "voltage", + "volume", + "volume mL", + "volume flow rate", "weight", ] diff --git a/custom_components/ble_monitor/test/test_bthome_v2.py b/custom_components/ble_monitor/test/test_bthome_v2.py index dfd322b8a..cb08c9bbf 100644 --- a/custom_components/ble_monitor/test/test_bthome_v2.py +++ b/custom_components/ble_monitor/test/test_bthome_v2.py @@ -847,7 +847,7 @@ def test_bthome_v2_distance_mm(self): assert sensor_msg["mac"] == "5448E68F80A5" assert sensor_msg["packet"] == "no packet id" assert sensor_msg["data"] - assert sensor_msg["distance"] == 12 + assert sensor_msg["distance mm"] == 12 assert sensor_msg["rssi"] == -52 def test_bthome_v2_distance_m(self): @@ -983,7 +983,7 @@ def test_bthome_v2_volume_milliliter(self): assert sensor_msg["mac"] == "5448E68F80A5" assert sensor_msg["packet"] == "no packet id" assert sensor_msg["data"] - assert sensor_msg["volume"] == 34780 + assert sensor_msg["volume mL"] == 34780 assert sensor_msg["rssi"] == -52 def test_bthome_v2_volume_flow_rate(self):