Improve logging when a unique id conflict is detected (#38434)

* fix error when unique id is re-used

* add test for the logging

* Update homeassistant/helpers/entity_platform.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/helpers/entity_platform.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
J. Nick KostonandMartin Hjelmare authored and GitHub committed 2020-08-01 11:20:37 +02:00
1 parent ff1709979f
commit fe69a85386
2 files changed
+22 -3

No files matched your search

+9 -2
View File
@@ -325,11 +325,13 @@ class EntityPlatform:
entity.platform = None
return
requested_entity_id = None
suggested_object_id = None
# Get entity_id from unique ID registration
if entity.unique_id is not None:
if entity.entity_id is not None:
requested_entity_id = entity.entity_id
suggested_object_id = split_entity_id(entity.entity_id)[1]
else:
suggested_object_id = entity.name
@@ -435,9 +437,14 @@ class EntityPlatform:
already_exists = True
if already_exists:
msg = f"Entity id already exists - ignoring: {entity.entity_id}"
if entity.unique_id is not None:
msg += f". Platform {self.platform_name} does not generate unique IDs"
msg = f"Platform {self.platform_name} does not generate unique IDs. "
if requested_entity_id:
msg += f"ID {entity.unique_id} is already used by {entity.entity_id} - ignoring {requested_entity_id}"
else:
msg += f"ID {entity.unique_id} already exists - ignoring {entity.entity_id}"
else:
msg = f"Entity id already exists - ignoring: {entity.entity_id}"
self.logger.error(msg)
entity.hass = None
entity.platform = None