@hakit/core
Version:
A collection of React hooks and helpers for Home Assistant to easily communicate with the Home Assistant WebSocket API.
27 lines (26 loc) • 1.13 kB
JavaScript
import { useState as _, useRef as g, useMemo as p, useEffect as B } from "react";
import { isEqual as l } from "lodash";
import "../../utils/light/index.js";
import "../useLocale/locales/index.js";
import { u as L } from "../../../index-DnHwXFlq.js";
import "../../HassConnect/HassContext.js";
import "@iconify/react";
import "use-debounce";
import "deep-object-diff";
import "home-assistant-js-websocket";
const O = ({ blacklist: n = [], whitelist: r = [], min: u = 0, max: c = 20 } = {}) => {
const { getAllEntities: f } = L(), [s, d] = _([]), e = f(), m = g(null), a = !l(m.current, e), o = p(
() => Object.values(e).filter((t) => {
const E = t.attributes.unit_of_measurement === "%" && t.attributes.device_class === "battery", b = Number(t.state) <= c && Number(t.state) >= u, h = n.some((i) => t.entity_id.includes(i)), v = r.length === 0 || r.some((i) => t.entity_id.includes(i));
return E && b && v && !h;
}),
[n, e, c, u, r]
);
return B(() => {
a && !l(o, s) && d(o), m.current = e;
}, [a, o, s, e]), p(() => s, [s]);
};
export {
O as useLowDevices
};
//# sourceMappingURL=index.js.map