diff --git a/custom_components/ble_monitor/const.py b/custom_components/ble_monitor/const.py index 39ab6cb5f..defe50f54 100755 --- a/custom_components/ble_monitor/const.py +++ b/custom_components/ble_monitor/const.py @@ -125,6 +125,42 @@ class BLEMonitorBinarySensorEntityDescription( BINARY_SENSOR_TYPES: tuple[BLEMonitorBinarySensorEntityDescription, ...] = ( + BLEMonitorBinarySensorEntityDescription( + key="battery_charging", + sensor_class="BaseBinarySensor", + update_behavior="Instantly", + name="battery_charging", + unique_id="bc_", + device_class=BinarySensorDeviceClass.BATTERY_CHARGING, + force_update=True, + ), + BLEMonitorBinarySensorEntityDescription( + key="carbon_monoxide", + sensor_class="BaseBinarySensor", + update_behavior="Instantly", + name="carbon monoxide", + unique_id="bco_", + device_class=BinarySensorDeviceClass.CO, + force_update=True, + ), + BLEMonitorBinarySensorEntityDescription( + key="cold", + sensor_class="BaseBinarySensor", + update_behavior="Instantly", + name="cold", + unique_id="bcold_", + device_class=BinarySensorDeviceClass.COLD, + force_update=True, + ), + BLEMonitorBinarySensorEntityDescription( + key="connectivity", + sensor_class="BaseBinarySensor", + update_behavior="Instantly", + name="connectivity", + unique_id="bconn_", + device_class=BinarySensorDeviceClass.CONNECTIVITY, + force_update=True, + ), BLEMonitorBinarySensorEntityDescription( key="binary", sensor_class="BaseBinarySensor", @@ -1500,6 +1536,10 @@ class BLEMonitorBinarySensorEntityDescription( # Binary Sensors that are automatically added if device is in AUTO_MANUFACTURER_DICT AUTO_BINARY_SENSOR_LIST = [ + "battery_charging", + "carbon_monoxide", + "cold", + "connectivity", "binary", "door", "dropping", @@ -1524,6 +1564,7 @@ class BLEMonitorBinarySensorEntityDescription( "conductivity", "count", "dewpoint", + "dimmer", "energy", "gravity", "humidity", diff --git a/custom_components/ble_monitor/test/test_bthome_v2.py b/custom_components/ble_monitor/test/test_bthome_v2.py index d82dbdad9..ada6d7816 100644 --- a/custom_components/ble_monitor/test/test_bthome_v2.py +++ b/custom_components/ble_monitor/test/test_bthome_v2.py @@ -305,6 +305,74 @@ def test_bthome_v2_moisture(self): assert sensor_msg["moisture"] == 3.07 assert sensor_msg["rssi"] == -52 + def test_bthome_v2_battery_charging(self): + """Test BTHome parser for battery charging measurement""" + data_string = "043E1602010000A5808FE648540A0201060616D2FC401601CC" + 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["battery_charging"] == 1 + assert sensor_msg["rssi"] == -52 + + def test_bthome_v2_carbon_monoxide(self): + """Test BTHome parser for carbon monoxide measurement""" + data_string = "043E1602010000A5808FE648540A0201060616D2FC401701CC" + 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["carbon_monoxide"] == 1 + assert sensor_msg["rssi"] == -52 + + def test_bthome_v2_cold(self): + """Test BTHome parser for cold measurement""" + data_string = "043E1602010000A5808FE648540A0201060616D2FC401801CC" + 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["cold"] == 1 + assert sensor_msg["rssi"] == -52 + + def test_bthome_v2_connectivity(self): + """Test BTHome parser for connectivity measurement""" + data_string = "043E1602010000A5808FE648540A0201060616D2FC401901CC" + 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["connectivity"] == 1 + assert sensor_msg["rssi"] == -52 + def test_bthome_v2_button(self): """Test BTHome parser for button sensor measurement""" data_string = "043E1602010000A5808FE648540A0201060616D2FC403A02CC"