|
31 | 31 | HUBMINI_MATTER_SERVICE_INFO, |
32 | 32 | LEAK_SERVICE_INFO, |
33 | 33 | PLUG_MINI_EU_SERVICE_INFO, |
| 34 | + PRESENCE_SENSOR_SERVICE_INFO, |
34 | 35 | RELAY_SWITCH_2PM_SERVICE_INFO, |
35 | 36 | REMOTE_SERVICE_INFO, |
36 | 37 | WOHAND_SERVICE_INFO, |
@@ -793,3 +794,57 @@ async def test_climate_panel_sensor(hass: HomeAssistant) -> None: |
793 | 794 |
|
794 | 795 | assert await hass.config_entries.async_unload(entry.entry_id) |
795 | 796 | await hass.async_block_till_done() |
| 797 | + |
| 798 | + |
| 799 | +@pytest.mark.usefixtures("entity_registry_enabled_by_default") |
| 800 | +async def test_presence_sensor(hass: HomeAssistant) -> None: |
| 801 | + """Test setting up creates the sensors for Presence Sensor.""" |
| 802 | + await async_setup_component(hass, DOMAIN, {}) |
| 803 | + inject_bluetooth_service_info(hass, PRESENCE_SENSOR_SERVICE_INFO) |
| 804 | + |
| 805 | + entry = MockConfigEntry( |
| 806 | + domain=DOMAIN, |
| 807 | + data={ |
| 808 | + CONF_ADDRESS: "AA:BB:CC:DD:EE:FF", |
| 809 | + CONF_NAME: "test-name", |
| 810 | + CONF_SENSOR_TYPE: "presence_sensor", |
| 811 | + }, |
| 812 | + unique_id="aabbccddeeff", |
| 813 | + ) |
| 814 | + entry.add_to_hass(hass) |
| 815 | + |
| 816 | + assert await hass.config_entries.async_setup(entry.entry_id) |
| 817 | + await hass.async_block_till_done() |
| 818 | + |
| 819 | + assert len(hass.states.async_all("sensor")) == 3 |
| 820 | + assert len(hass.states.async_all("binary_sensor")) == 2 |
| 821 | + |
| 822 | + battery_sensor = hass.states.get("sensor.test_name_battery") |
| 823 | + battery_sensor_attrs = battery_sensor.attributes |
| 824 | + assert battery_sensor |
| 825 | + assert battery_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Battery" |
| 826 | + assert battery_sensor_attrs[ATTR_STATE_CLASS] == "measurement" |
| 827 | + |
| 828 | + light_level_sensor = hass.states.get("sensor.test_name_light_level") |
| 829 | + light_level_sensor_attrs = light_level_sensor.attributes |
| 830 | + assert light_level_sensor |
| 831 | + assert light_level_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Light level" |
| 832 | + |
| 833 | + rssi_sensor = hass.states.get("sensor.test_name_bluetooth_signal") |
| 834 | + rssi_sensor_attrs = rssi_sensor.attributes |
| 835 | + assert rssi_sensor |
| 836 | + assert rssi_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Bluetooth signal" |
| 837 | + assert rssi_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "dBm" |
| 838 | + |
| 839 | + light_sensor = hass.states.get("binary_sensor.test_name_light") |
| 840 | + light_sensor_attrs = light_sensor.attributes |
| 841 | + assert light_sensor |
| 842 | + assert light_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Light" |
| 843 | + |
| 844 | + motion_sensor = hass.states.get("binary_sensor.test_name_motion") |
| 845 | + motion_sensor_attrs = motion_sensor.attributes |
| 846 | + assert motion_sensor |
| 847 | + assert motion_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Motion" |
| 848 | + |
| 849 | + assert await hass.config_entries.async_unload(entry.entry_id) |
| 850 | + await hass.async_block_till_done() |
0 commit comments