From d5f5273c3162a22e0568b359acde16a88322e54d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 8 Oct 2018 12:53:51 +0200 Subject: [PATCH] Guard for bad device info (#17238) --- homeassistant/helpers/entity_platform.py | 6 +++--- tests/helpers/test_entity_platform.py | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index 99aa10013ab..3ab45577236 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -273,6 +273,7 @@ class EntityPlatform: config_entry_id = None device_info = entity.device_info + device_id = None if config_entry_id is not None and device_info is not None: processed_dev_info = { @@ -292,9 +293,8 @@ class EntityPlatform: device = device_registry.async_get_or_create( **processed_dev_info) - device_id = device.id - else: - device_id = None + if device: + device_id = device.id entry = entity_registry.async_get_or_create( self.domain, self.platform_name, entity.unique_id, diff --git a/tests/helpers/test_entity_platform.py b/tests/helpers/test_entity_platform.py index 97d6a0f5b98..e985771e486 100644 --- a/tests/helpers/test_entity_platform.py +++ b/tests/helpers/test_entity_platform.py @@ -719,6 +719,8 @@ async def test_device_info_called(hass): assert await entity_platform.async_setup_entry(config_entry) await hass.async_block_till_done() + assert len(hass.states.async_entity_ids()) == 2 + device = registry.async_get_device({('hue', '1234')}, set()) assert device is not None assert device.identifiers == {('hue', '1234')}