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.39 kB
import { useMemo as p, useCallback as m } from "react"; import { l as v, u as $ } from "../../../index-BfdcdUoC.js"; import { uniq as S } from "lodash"; function a(e, r, t) { return new Proxy( // @ts-expect-error - purposely not defining the target object here {}, { get: (i, s) => { const n = s; if (n !== "toJSON") return function(f) { const { target: l, serviceData: u, returnResponse: o } = f || {}; let c = t ?? l; return Array.isArray(c) && (c = [...S(c)]), console.info( `${v("perform_action_name", { search: "{name}", replace: `${e}.${n}` })} ${e}.${n}:`, { target: c, serviceData: u, returnResponse: o } ), r({ domain: e, service: n, serviceData: u, target: c, // necessary cast here as the overloads expect true | false | undefined not a boolean returnResponse: o }); }; } } ); } function x(e, r) { const { callService: t } = $(), i = p(() => e ? a(e, t, r) : void 0, [e, t, r]), s = m( (n) => a(n, t, r), [t, r] ); return e ? i : s; } export { a as createService, x as useService }; //# sourceMappingURL=index.js.map