UNPKG

@hakit/core

Version:

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

31 lines (30 loc) 895 B
import { useInternalStore as r } from "./HassContext.js"; async function h(a, e) { try { const { connection: t, hassUrl: o } = r.getState(), s = await fetch(`${o}/api${a}`, { method: "GET", ...e ?? {}, headers: { Authorization: "Bearer " + t?.options.auth?.accessToken, "Content-type": "application/json;charset=UTF-8", ...e?.headers ?? {} } }); return s.status === 200 ? { status: "success", data: await s.json() } : { status: "error", data: s.statusText }; } catch (t) { return console.error("API Error:", t), { status: "error", data: `API Request failed for endpoint "${a}", follow instructions here: https://shannonhochkins.github.io/ha-component-kit/?path=/docs/core-hooks-usehass-hass-callapi--docs.` }; } } export { h as callApi }; //# sourceMappingURL=callApi.js.map