UNPKG

@hakit/core

Version:

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

55 lines (54 loc) 1.56 kB
import { useMemo as l, useCallback as m } from "react"; import { uniq as v } from "lodash"; import { X as S, Y as $ } from "../../../index-BDZyTvOW.js"; import "home-assistant-js-websocket"; import "../../utils/date.js"; import "@iconify/react"; import "use-debounce"; import "../useLocale/locales/index.js"; function a(e, r, t) { return new Proxy( // @ts-expect-error - purposely not defining the target object here {}, { get: (s, n) => { const i = n; if (i !== "toJSON") return function(p) { const { target: f, serviceData: o, returnResponse: u } = p || {}; let c = t ?? f; return Array.isArray(c) && (c = [...v(c)]), console.info( `${$("perform_action", { search: "{name}", replace: `${e}.${i}` })} ${e}.${i}:`, { target: c, serviceData: o, returnResponse: u } ), r({ domain: e, service: i, serviceData: o, target: c, // necessary cast here as the overloads expect true | false | undefined not a boolean returnResponse: u }); }; } } ); } function k(e, r) { const { callService: t } = S.getState().helpers, s = l(() => e ? a(e, t, r) : void 0, [e, t, r]), n = m( (i) => a(i, t, r), [t, r] ); return e ? s : n; } export { a as createService, k as useService }; //# sourceMappingURL=index.js.map