Use entity_sources to determine integration in recorder platforms (#88382)

This commit is contained in:
Erik Montnemery 2023-02-18 14:21:41 +01:00 committed by GitHub
parent 728f0d5b3b
commit 83e5bf7ae8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 19 deletions

View file

@ -57,11 +57,18 @@ SOURCE_PLATFORM_CONFIG = "platform_config"
FLOAT_PRECISION = abs(int(math.floor(math.log10(abs(sys.float_info.epsilon))))) - 1
@callback
def async_setup(hass: HomeAssistant) -> None:
"""Set up entity sources."""
hass.data[DATA_ENTITY_SOURCE] = {}
@callback
@bind_hass
def entity_sources(hass: HomeAssistant) -> dict[str, dict[str, str]]:
"""Get the entity sources."""
return hass.data.get(DATA_ENTITY_SOURCE, {})
_entity_sources: dict[str, dict[str, str]] = hass.data[DATA_ENTITY_SOURCE]
return _entity_sources
def generate_entity_id(
@ -868,7 +875,7 @@ class Entity(ABC):
else:
info["source"] = SOURCE_PLATFORM_CONFIG
self.hass.data.setdefault(DATA_ENTITY_SOURCE, {})[self.entity_id] = info
self.hass.data[DATA_ENTITY_SOURCE][self.entity_id] = info
if self.registry_entry is not None:
# This is an assert as it should never happen, but helps in tests