mirror of
https://github.com/home-assistant/core.git
synced 2026-05-02 22:52:06 +01:00
Make bad entity ID detection more lenient (#162425)
This commit is contained in:
@@ -1967,11 +1967,39 @@ async def test_invalid_entity_id(
|
||||
assert entity.hass is None
|
||||
assert entity.platform is None
|
||||
assert "Invalid entity ID: invalid_entity_id" in caplog.text
|
||||
|
||||
# Ensure the valid entity was still added
|
||||
assert entity2.hass is not None
|
||||
assert entity2.platform is not None
|
||||
|
||||
|
||||
async def test_invalid_entity_id_report_usage(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test that setting an invalid entity_id reports usage."""
|
||||
platform = MockEntityPlatform(hass)
|
||||
entity = MockEntity(entity_id="test_domain.INVALID-ENTITY-ID", unique_id="unique")
|
||||
|
||||
mock_integration = Mock(is_built_in=True, domain="test_platform")
|
||||
with (
|
||||
caplog.at_level(logging.WARNING),
|
||||
patch(
|
||||
"homeassistant.helpers.frame.async_get_issue_integration",
|
||||
return_value=mock_integration,
|
||||
),
|
||||
):
|
||||
await platform.async_add_entities([entity])
|
||||
|
||||
assert (
|
||||
"Detected that integration 'test_platform' "
|
||||
"sets an invalid entity ID: 'test_domain.INVALID-ENTITY-ID'"
|
||||
) in caplog.text
|
||||
|
||||
# Ensure the entity was still added
|
||||
assert entity.hass is not None
|
||||
assert entity.platform is not None
|
||||
|
||||
|
||||
class MockBlockingEntity(MockEntity):
|
||||
"""Class to mock an entity that will block adding entities."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user