Do not add entities with invalid device info (#98150)
This commit is contained in:
parent
a2cf08a1ea
commit
97f3199d6d
2 changed files with 22 additions and 13 deletions
|
@ -618,8 +618,13 @@ class EntityPlatform:
|
|||
**device_info,
|
||||
)
|
||||
except dev_reg.DeviceInfoError as exc:
|
||||
self.logger.error("Ignoring invalid device info: %s", str(exc))
|
||||
device = None
|
||||
self.logger.error(
|
||||
"%s: Not adding entity with invalid device info: %s",
|
||||
self.platform_name,
|
||||
str(exc),
|
||||
)
|
||||
entity.add_to_platform_abort()
|
||||
return
|
||||
else:
|
||||
device = None
|
||||
|
||||
|
|
|
@ -1853,23 +1853,27 @@ async def test_device_name_defaulting_config_entry(
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("device_info"),
|
||||
("device_info", "number_of_entities"),
|
||||
[
|
||||
# No identifiers
|
||||
{},
|
||||
{"name": "bla"},
|
||||
{"default_name": "bla"},
|
||||
({}, 1), # Empty device info does not prevent the entity from being created
|
||||
({"name": "bla"}, 0),
|
||||
({"default_name": "bla"}, 0),
|
||||
# Match multiple types
|
||||
{
|
||||
"identifiers": {("hue", "1234")},
|
||||
"name": "bla",
|
||||
"default_name": "yo",
|
||||
},
|
||||
(
|
||||
{
|
||||
"identifiers": {("hue", "1234")},
|
||||
"name": "bla",
|
||||
"default_name": "yo",
|
||||
},
|
||||
0,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_device_type_error_checking(
|
||||
hass: HomeAssistant,
|
||||
device_info: dict,
|
||||
number_of_entities: int,
|
||||
) -> None:
|
||||
"""Test catching invalid device info."""
|
||||
|
||||
|
@ -1895,6 +1899,6 @@ async def test_device_type_error_checking(
|
|||
|
||||
dev_reg = dr.async_get(hass)
|
||||
assert len(dev_reg.devices) == 0
|
||||
# Entity should still be registered
|
||||
ent_reg = er.async_get(hass)
|
||||
assert ent_reg.async_get("test_domain.test_qwer") is not None
|
||||
assert len(ent_reg.entities) == number_of_entities
|
||||
assert len(hass.states.async_all()) == number_of_entities
|
||||
|
|
Loading…
Add table
Reference in a new issue