mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Store config entry id in entity registry (#14851)
* Store config entry id in entity registry * Lint
This commit is contained in:
committed by
Pascal Vizeli
parent
bb4d1773d3
commit
67d137cfd5
@@ -43,6 +43,7 @@ class RegistryEntry:
|
||||
unique_id = attr.ib(type=str)
|
||||
platform = attr.ib(type=str)
|
||||
name = attr.ib(type=str, default=None)
|
||||
config_entry_id = attr.ib(type=str, default=None)
|
||||
disabled_by = attr.ib(
|
||||
type=str, default=None,
|
||||
validator=attr.validators.in_((DISABLED_HASS, DISABLED_USER, None)))
|
||||
@@ -106,7 +107,7 @@ class EntityRegistry:
|
||||
|
||||
@callback
|
||||
def async_get_or_create(self, domain, platform, unique_id, *,
|
||||
suggested_object_id=None):
|
||||
suggested_object_id=None, config_entry_id=None):
|
||||
"""Get entity. Create if it doesn't exist."""
|
||||
entity_id = self.async_get_entity_id(domain, platform, unique_id)
|
||||
if entity_id:
|
||||
@@ -114,8 +115,10 @@ class EntityRegistry:
|
||||
|
||||
entity_id = self.async_generate_entity_id(
|
||||
domain, suggested_object_id or '{}_{}'.format(platform, unique_id))
|
||||
|
||||
entity = RegistryEntry(
|
||||
entity_id=entity_id,
|
||||
config_entry_id=config_entry_id,
|
||||
unique_id=unique_id,
|
||||
platform=platform,
|
||||
)
|
||||
@@ -179,6 +182,7 @@ class EntityRegistry:
|
||||
for entity_id, info in data.items():
|
||||
entities[entity_id] = RegistryEntry(
|
||||
entity_id=entity_id,
|
||||
config_entry_id=info.get('config_entry_id'),
|
||||
unique_id=info['unique_id'],
|
||||
platform=info['platform'],
|
||||
name=info.get('name'),
|
||||
@@ -205,6 +209,7 @@ class EntityRegistry:
|
||||
|
||||
for entry in self.entities.values():
|
||||
data[entry.entity_id] = {
|
||||
'config_entry_id': entry.config_entry_id,
|
||||
'unique_id': entry.unique_id,
|
||||
'platform': entry.platform,
|
||||
'name': entry.name,
|
||||
|
||||
Reference in New Issue
Block a user