mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-19 18:28:42 +00:00
26 lines
729 B
TypeScript
26 lines
729 B
TypeScript
import { timeCachePromiseFunc } from "../../common/util/time-cache-function-promise";
|
|
import type { HomeAssistant } from "../../types";
|
|
|
|
interface EntitySource {
|
|
domain: string;
|
|
}
|
|
|
|
export type EntitySources = Record<string, EntitySource>;
|
|
|
|
const fetchEntitySources = (hass: HomeAssistant): Promise<EntitySources> =>
|
|
hass.callWS({ type: "entity/source" });
|
|
|
|
export const fetchEntitySourcesWithCache = (
|
|
hass: HomeAssistant
|
|
): Promise<EntitySources> =>
|
|
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
|
|
);
|