diff --git a/custom_components/ble_monitor/ble_parser/bthome_const.py b/custom_components/ble_monitor/ble_parser/bthome_const.py index bee3f83f5..38cc90b27 100644 --- a/custom_components/ble_monitor/ble_parser/bthome_const.py +++ b/custom_components/ble_monitor/ble_parser/bthome_const.py @@ -144,7 +144,7 @@ class MeasTypes: meas_format="garage_door", ), 0x1C: MeasTypes( - meas_format="gas", + meas_format="gas_detected", ), 0x1D: MeasTypes( meas_format="heat", @@ -156,7 +156,7 @@ class MeasTypes: meas_format="lock", ), 0x20: MeasTypes( - meas_format="moisture", + meas_format="moisture_detected", ), 0x21: MeasTypes( meas_format="motion", diff --git a/custom_components/ble_monitor/const.py b/custom_components/ble_monitor/const.py index defe50f54..da4440b98 100755 --- a/custom_components/ble_monitor/const.py +++ b/custom_components/ble_monitor/const.py @@ -161,6 +161,42 @@ class BLEMonitorBinarySensorEntityDescription( device_class=BinarySensorDeviceClass.CONNECTIVITY, force_update=True, ), + BLEMonitorBinarySensorEntityDescription( + key="garage_door", + sensor_class="BaseBinarySensor", + update_behavior="Instantly", + name="garage door", + unique_id="bgdr_", + device_class=BinarySensorDeviceClass.GARAGE_DOOR, + force_update=True, + ), + BLEMonitorBinarySensorEntityDescription( + key="gas_detected", + sensor_class="BaseBinarySensor", + update_behavior="Instantly", + name="gas", + unique_id="bgas_", + device_class=BinarySensorDeviceClass.GAS, + force_update=True, + ), + BLEMonitorBinarySensorEntityDescription( + key="heat", + sensor_class="BaseBinarySensor", + update_behavior="Instantly", + name="heat", + unique_id="bheat_", + device_class=BinarySensorDeviceClass.HEAT, + force_update=True, + ), + BLEMonitorBinarySensorEntityDescription( + key="moisture_detected", + sensor_class="BaseBinarySensor", + update_behavior="Instantly", + name="moisture", + unique_id="bmoist_", + device_class=BinarySensorDeviceClass.MOISTURE, + force_update=True, + ), BLEMonitorBinarySensorEntityDescription( key="binary", sensor_class="BaseBinarySensor", @@ -1543,10 +1579,14 @@ class BLEMonitorBinarySensorEntityDescription( "binary", "door", "dropping", + "garage_door", + "gas_detected", + "heat", "impact", "light", "lock", "motion", + "moisture_detected" "opening", "smoke", "switch", diff --git a/custom_components/ble_monitor/test/test_bthome_v2.py b/custom_components/ble_monitor/test/test_bthome_v2.py index ada6d7816..37fe219ff 100644 --- a/custom_components/ble_monitor/test/test_bthome_v2.py +++ b/custom_components/ble_monitor/test/test_bthome_v2.py @@ -373,6 +373,125 @@ def test_bthome_v2_connectivity(self): assert sensor_msg["connectivity"] == 1 assert sensor_msg["rssi"] == -52 + def test_bthome_v2_door(self): + """Test BTHome parser for door measurement""" + data_string = "043E1602010000A5808FE648540A0201060616D2FC401A01CC" + data = bytes(bytearray.fromhex(data_string)) + + # pylint: disable=unused-variable + ble_parser = BleParser() + sensor_msg, tracker_msg = ble_parser.parse_raw_data(data) + + assert sensor_msg["firmware"] == "BTHome V2" + assert sensor_msg["type"] == "BTHome" + assert sensor_msg["mac"] == "5448E68F80A5" + assert sensor_msg["packet"] == "no packet id" + assert sensor_msg["data"] + assert sensor_msg["door"] == 1 + assert sensor_msg["rssi"] == -52 + + def test_bthome_v2_garage_door(self): + """Test BTHome parser for garage door measurement""" + data_string = "043E1602010000A5808FE648540A0201060616D2FC401B01CC" + data = bytes(bytearray.fromhex(data_string)) + + # pylint: disable=unused-variable + ble_parser = BleParser() + sensor_msg, tracker_msg = ble_parser.parse_raw_data(data) + + assert sensor_msg["firmware"] == "BTHome V2" + assert sensor_msg["type"] == "BTHome" + assert sensor_msg["mac"] == "5448E68F80A5" + assert sensor_msg["packet"] == "no packet id" + assert sensor_msg["data"] + assert sensor_msg["garage_door"] == 1 + assert sensor_msg["rssi"] == -52 + + def test_bthome_v2_gas_detected(self): + """Test BTHome parser for gas detected measurement""" + data_string = "043E1602010000A5808FE648540A0201060616D2FC401C00CC" + data = bytes(bytearray.fromhex(data_string)) + + # pylint: disable=unused-variable + ble_parser = BleParser() + sensor_msg, tracker_msg = ble_parser.parse_raw_data(data) + + assert sensor_msg["firmware"] == "BTHome V2" + assert sensor_msg["type"] == "BTHome" + assert sensor_msg["mac"] == "5448E68F80A5" + assert sensor_msg["packet"] == "no packet id" + assert sensor_msg["data"] + assert sensor_msg["gas_detected"] == 0 + assert sensor_msg["rssi"] == -52 + + def test_bthome_v2_heat(self): + """Test BTHome parser for heat measurement""" + data_string = "043E1602010000A5808FE648540A0201060616D2FC401D01CC" + data = bytes(bytearray.fromhex(data_string)) + + # pylint: disable=unused-variable + ble_parser = BleParser() + sensor_msg, tracker_msg = ble_parser.parse_raw_data(data) + + assert sensor_msg["firmware"] == "BTHome V2" + assert sensor_msg["type"] == "BTHome" + assert sensor_msg["mac"] == "5448E68F80A5" + assert sensor_msg["packet"] == "no packet id" + assert sensor_msg["data"] + assert sensor_msg["heat"] == 1 + assert sensor_msg["rssi"] == -52 + + def test_bthome_v2_light(self): + """Test BTHome parser for light measurement""" + data_string = "043E1602010000A5808FE648540A0201060616D2FC401E01CC" + data = bytes(bytearray.fromhex(data_string)) + + # pylint: disable=unused-variable + ble_parser = BleParser() + sensor_msg, tracker_msg = ble_parser.parse_raw_data(data) + + assert sensor_msg["firmware"] == "BTHome V2" + assert sensor_msg["type"] == "BTHome" + assert sensor_msg["mac"] == "5448E68F80A5" + assert sensor_msg["packet"] == "no packet id" + assert sensor_msg["data"] + assert sensor_msg["light"] == 1 + assert sensor_msg["rssi"] == -52 + + def test_bthome_v2_lock(self): + """Test BTHome parser for lock measurement""" + data_string = "043E1602010000A5808FE648540A0201060616D2FC401F01CC" + data = bytes(bytearray.fromhex(data_string)) + + # pylint: disable=unused-variable + ble_parser = BleParser() + sensor_msg, tracker_msg = ble_parser.parse_raw_data(data) + + assert sensor_msg["firmware"] == "BTHome V2" + assert sensor_msg["type"] == "BTHome" + assert sensor_msg["mac"] == "5448E68F80A5" + assert sensor_msg["packet"] == "no packet id" + assert sensor_msg["data"] + assert sensor_msg["lock"] == 1 + assert sensor_msg["rssi"] == -52 + + def test_bthome_v2_moisture_detected(self): + """Test BTHome parser for moisture detected measurement""" + data_string = "043E1602010000A5808FE648540A0201060616D2FC401F01CC" + data = bytes(bytearray.fromhex(data_string)) + + # pylint: disable=unused-variable + ble_parser = BleParser() + sensor_msg, tracker_msg = ble_parser.parse_raw_data(data) + + assert sensor_msg["firmware"] == "BTHome V2" + assert sensor_msg["type"] == "BTHome" + assert sensor_msg["mac"] == "5448E68F80A5" + assert sensor_msg["packet"] == "no packet id" + assert sensor_msg["data"] + assert sensor_msg["moisture_detected"] == 1 + assert sensor_msg["rssi"] == -52 + def test_bthome_v2_button(self): """Test BTHome parser for button sensor measurement""" data_string = "043E1602010000A5808FE648540A0201060616D2FC403A02CC"