Skip to content

Commit

Permalink
add more sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernst79 committed Sep 23, 2023
1 parent ba70e8f commit 4c8aa70
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 4 deletions.
4 changes: 2 additions & 2 deletions custom_components/ble_monitor/ble_parser/bthome_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down Expand Up @@ -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,
),
Expand Down
131 changes: 131 additions & 0 deletions custom_components/ble_monitor/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1704,8 +1825,12 @@ class BLEMonitorBinarySensorEntityDescription(
"co2",
"conductivity",
"count",
"current",
"dewpoint",
"dimmer",
"distance",
"distance mm",
"duration",
"energy",
"gravity",
"humidity",
Expand All @@ -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",
]

Expand Down
4 changes: 2 additions & 2 deletions custom_components/ble_monitor/test/test_bthome_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 4c8aa70

Please sign in to comment.