Skip to content

Commit

Permalink
Use dict for device info types
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Jul 2, 2023
1 parent 3b3748b commit 03727f9
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions homeassistant/helpers/entity_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@
DATA_ENTITY_PLATFORM = "entity_platform"
PLATFORM_NOT_READY_BASE_WAIT_TIME = 30 # seconds

DEVICE_INFO_TYPES = (
# link info
{
"connections",
"identifiers",
},
# primary info
{
DEVICE_INFO_TYPES = {
"primary": {
"configuration_url",
"connections",
"entry_type",
Expand All @@ -81,16 +75,19 @@
"sw_version",
"via_device",
},
# secondary info
{
"secondary": {
"connections",
"default_manufacturer",
"default_model",
"default_name",
# Used by Fritz
"via_device",
},
)
"link": {
"connections",
"identifiers",
},
}

_LOGGER = getLogger(__name__)

Expand Down Expand Up @@ -666,7 +663,14 @@ async def _async_add_entity( # noqa: C901
]

keys = set(processed_dev_info)
if not any(keys <= allowed for allowed in DEVICE_INFO_TYPES):
entity_type: str | None = None

for possible_type, allowed_keys in DEVICE_INFO_TYPES.items():
if keys <= allowed_keys:
entity_type = possible_type
break

if entity_type is None:
raise HomeAssistantError(

Check warning on line 674 in homeassistant/helpers/entity_platform.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/helpers/entity_platform.py#L674

Added line #L674 was not covered by tests
"Device info needs to either describe a device, "
"link to existing device or provide extra information."
Expand Down

0 comments on commit 03727f9

Please sign in to comment.