UNPKG

@hakit/core

Version:

A collection of React hooks and helpers for Home Assistant to easily communicate with the Home Assistant WebSocket API.

50 lines (49 loc) 1.51 kB
import { createCollection as d } from "home-assistant-js-websocket"; import { debounce as g } from "lodash"; import { stringCompare as u } from "../string.js"; const n = (r) => r.sendMessagePromise({ type: "config/area_registry/list" }), y = (r, e) => r.subscribeEvents( g(() => n(r).then((t) => e.setState(t, !0)), 500, { leading: !0, trailing: !0 }), "area_registry_updated" ), m = (r, e) => d("_areaRegistry", n, y, r, e), A = (r, e) => r.sendMessagePromise({ type: "config/area_registry/create", ...e }), l = (r, e, t) => r.sendMessagePromise({ type: "config/area_registry/update", area_id: e, ...t }), R = (r, e) => r.sendMessagePromise({ type: "config/area_registry/delete", area_id: e }), E = (r) => { const e = {}; for (const t of r) t.area_id && (t.area_id in e || (e[t.area_id] = []), e[t.area_id].push(t)); return e; }, b = (r) => { const e = {}; for (const t of r) t.area_id && (t.area_id in e || (e[t.area_id] = []), e[t.area_id].push(t)); return e; }, x = (r, e) => (t, a) => { const i = e ? e.indexOf(t) : -1, s = e ? e.indexOf(a) : -1; if (i === -1 && s === -1) { const o = r?.[t]?.name ?? t, c = r?.[a]?.name ?? a; return u(o, c); } return i === -1 ? 1 : s === -1 ? -1 : i - s; }; export { x as areaCompare, A as createAreaRegistryEntry, R as deleteAreaRegistryEntry, b as getAreaDeviceLookup, E as getAreaEntityLookup, m as subscribeAreaRegistry, l as updateAreaRegistryEntry }; //# sourceMappingURL=areas.js.map