UNPKG

@hakit/core

Version:

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

36 lines (35 loc) 1.03 kB
import { useStore as d } from "../useStore/index.js"; import { useRef as g, useState as m, useCallback as h, useEffect as S } from "react"; function y(u) { const c = g(!1), r = d((o) => o.connection), [t, s] = m({ loading: !0, error: null, users: [] }), n = h( async ({ includeSystemGenerated: o = !1, includeInactiveUsers: l = !1 } = {}) => { if (!r) return t; c.current = !0, s((e) => ({ ...e, error: null, loading: !0 })); try { const f = { loading: !1, error: null, users: (await r.sendMessagePromise({ type: "config/auth/list" })).filter((i) => !(!o && i.system_generated || !l && !i.is_active)) }; return s(f), f; } catch (e) { const a = { loading: !1, error: e instanceof Error ? e.message : "Unknown error", users: [] }; return s(a), a; } }, [r, t] ); return S(() => { c.current || n(u); }, [r, n, u]), { ...t, refetch: n }; } export { y as useUsers }; //# sourceMappingURL=index.js.map