|
10 | 10 | ATTR_EVENT_TYPE, |
11 | 11 | ATTR_EVENT_TYPES, |
12 | 12 | DOMAIN, |
| 13 | + DoorbellEventType, |
13 | 14 | EventDeviceClass, |
14 | 15 | EventEntity, |
15 | 16 | EventEntityDescription, |
|
34 | 35 | mock_platform, |
35 | 36 | mock_restore_cache, |
36 | 37 | mock_restore_cache_with_extra_data, |
| 38 | + setup_test_component_platform, |
37 | 39 | ) |
38 | 40 |
|
39 | 41 |
|
@@ -344,3 +346,68 @@ async def async_setup_entry_platform( |
344 | 346 | "device_class": "doorbell", |
345 | 347 | "friendly_name": "Doorbell", |
346 | 348 | } |
| 349 | + |
| 350 | + |
| 351 | +@pytest.mark.usefixtures("config_flow_fixture") |
| 352 | +async def test_doorbell_missing_ring_event_type( |
| 353 | + hass: HomeAssistant, |
| 354 | + caplog: pytest.LogCaptureFixture, |
| 355 | +) -> None: |
| 356 | + """Test warning when a doorbell entity does not include the standard ring event type.""" |
| 357 | + |
| 358 | + async def async_setup_entry_init( |
| 359 | + hass: HomeAssistant, config_entry: ConfigEntry |
| 360 | + ) -> bool: |
| 361 | + """Set up test config entry.""" |
| 362 | + await hass.config_entries.async_forward_entry_setups( |
| 363 | + config_entry, [Platform.EVENT] |
| 364 | + ) |
| 365 | + return True |
| 366 | + |
| 367 | + mock_platform(hass, f"{TEST_DOMAIN}.config_flow") |
| 368 | + mock_integration( |
| 369 | + hass, |
| 370 | + MockModule( |
| 371 | + TEST_DOMAIN, |
| 372 | + async_setup_entry=async_setup_entry_init, |
| 373 | + ), |
| 374 | + ) |
| 375 | + |
| 376 | + # Doorbell entity WITHOUT the standard "ring" event type |
| 377 | + entity_without_ring = EventEntity() |
| 378 | + entity_without_ring._attr_event_types = ["ding"] |
| 379 | + entity_without_ring._attr_device_class = EventDeviceClass.DOORBELL |
| 380 | + entity_without_ring._attr_has_entity_name = True |
| 381 | + entity_without_ring.entity_id = "event.doorbell_without_ring" |
| 382 | + |
| 383 | + # Doorbell entity WITH the standard "ring" event type |
| 384 | + entity_with_ring = EventEntity() |
| 385 | + entity_with_ring._attr_event_types = [DoorbellEventType.RING, "ding"] |
| 386 | + entity_with_ring._attr_device_class = EventDeviceClass.DOORBELL |
| 387 | + entity_with_ring._attr_has_entity_name = True |
| 388 | + entity_with_ring.entity_id = "event.doorbell_with_ring" |
| 389 | + |
| 390 | + # Non-doorbell entity should not warn |
| 391 | + entity_button = EventEntity() |
| 392 | + entity_button._attr_event_types = ["press"] |
| 393 | + entity_button._attr_device_class = EventDeviceClass.BUTTON |
| 394 | + entity_button._attr_has_entity_name = True |
| 395 | + entity_button.entity_id = "event.button" |
| 396 | + |
| 397 | + setup_test_component_platform( |
| 398 | + hass, |
| 399 | + DOMAIN, |
| 400 | + [entity_without_ring, entity_with_ring, entity_button], |
| 401 | + from_config_entry=True, |
| 402 | + ) |
| 403 | + config_entry = MockConfigEntry(domain=TEST_DOMAIN) |
| 404 | + config_entry.add_to_hass(hass) |
| 405 | + assert await hass.config_entries.async_setup(config_entry.entry_id) |
| 406 | + await hass.async_block_till_done() |
| 407 | + |
| 408 | + assert ( |
| 409 | + "Entity event.doorbell_without_ring is a doorbell event entity " |
| 410 | + "but does not support the 'ring' event type" |
| 411 | + ) in caplog.text |
| 412 | + assert "event.doorbell_with_ring" not in caplog.text |
| 413 | + assert "event.button" not in caplog.text |
0 commit comments