import { timeCachePromiseFunc } from "../../common/util/time-cache-function-promise"; import type { HomeAssistant } from "../../types"; interface EntitySource { domain: string; } export type EntitySources = Record; const fetchEntitySources = (hass: HomeAssistant): Promise => hass.callWS({ type: "entity/source" }); export const fetchEntitySourcesWithCache = ( hass: HomeAssistant ): Promise => 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 );