From 085b26d5ea1e74fac81f9557a7dde09dde35045e Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 5 Sep 2023 14:45:22 +0200 Subject: [PATCH] Simplify entity sources (#17770) --- src/data/entity_sources.ts | 51 +++++++++++--------------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/src/data/entity_sources.ts b/src/data/entity_sources.ts index 67455c1d22..851a70bfa6 100644 --- a/src/data/entity_sources.ts +++ b/src/data/entity_sources.ts @@ -1,46 +1,25 @@ import { timeCachePromiseFunc } from "../common/util/time-cache-function-promise"; import { HomeAssistant } from "../types"; -interface EntitySourceConfigEntry { - source: "config_entry"; +interface EntitySource { domain: string; - custom_component: boolean; - config_entry: string; } -interface EntitySourcePlatformConfig { - source: "platform_config"; - domain: string; - custom_component: boolean; -} +export type EntitySources = Record; -export type EntitySources = Record< - string, - EntitySourceConfigEntry | EntitySourcePlatformConfig ->; - -const fetchEntitySources = ( - hass: HomeAssistant, - entity_id?: string -): Promise => - hass.callWS({ - type: "entity/source", - entity_id, - }); +const fetchEntitySources = (hass: HomeAssistant): Promise => + hass.callWS({ type: "entity/source" }); export const fetchEntitySourcesWithCache = ( - hass: HomeAssistant, - entity_id?: string + hass: HomeAssistant ): Promise => - entity_id - ? fetchEntitySources(hass, entity_id) - : timeCachePromiseFunc( - "_entitySources", - // cache for 30 seconds - 30000, - fetchEntitySources, - // We base the cache on number of states. If number of states - // changes we force a refresh - (hass2) => Object.keys(hass2.states).length, - hass - ); + timeCachePromiseFunc( + "_entitySources", + // cache for 30 seconds + 30000, + fetchEntitySources, + // We base the cache on number of states. If number of states + // changes we force a refresh + (hass2) => Object.keys(hass2.states).length, + hass + );