@hakit/core
Version:
A collection of React hooks and helpers for Home Assistant to easily communicate with the Home Assistant WebSocket API.
85 lines (84 loc) • 2.36 kB
JavaScript
import "lodash";
import "../../utils/light/index.js";
import "react";
import "../useLocale/locales/index.js";
import { supportsFeatureFromAttributes as r } from "../../utils/supports-feature.js";
import "../../../index-BfdcdUoC.js";
import "../../HassConnect/HassContext.js";
import "@iconify/react";
import "use-debounce";
import "home-assistant-js-websocket";
var s = /* @__PURE__ */ ((t) => (t[t.FORECAST_DAILY = 1] = "FORECAST_DAILY", t[t.FORECAST_HOURLY = 2] = "FORECAST_HOURLY", t[t.FORECAST_TWICE_DAILY = 4] = "FORECAST_TWICE_DAILY", t))(s || {});
const u = 288e5, c = 864e5, d = (t) => {
if (t && t?.length && t?.length > 2) {
const e = new Date(t[1].datetime);
return new Date(t[2].datetime).getTime() - e.getTime() < u;
}
}, f = (t) => {
if (t && t?.length && t?.length > 2) {
const e = new Date(t[1].datetime);
return new Date(t[2].datetime).getTime() - e.getTime() < c;
}
}, o = (t) => {
if (t?.forecast && t.forecast.length > 2)
return d(t.forecast) ? {
forecast: t.forecast,
type: "hourly"
} : f(t.forecast) ? {
forecast: t.forecast,
type: "twice_daily"
} : { forecast: t.forecast, type: "daily" };
}, I = (t, e, i) => {
if (i === void 0)
return e?.type !== void 0 && e?.forecast && e?.forecast?.length > 2 ? { forecast: e.forecast, type: e?.type } : o(t);
if (i === "legacy")
return o(t);
if (i === e?.type && e?.forecast && e?.forecast?.length > 2)
return { forecast: e.forecast, type: i };
}, O = (t, e, i, n) => t.subscribeMessage(n, {
type: "weather/subscribe_forecast",
forecast_type: i,
entity_id: e
}), S = (t) => {
const e = [];
return r(
t.attributes,
1
/* FORECAST_DAILY */
) && e.push("daily"), r(
t.attributes,
4
/* FORECAST_TWICE_DAILY */
) && e.push("twice_daily"), r(
t.attributes,
2
/* FORECAST_HOURLY */
) && e.push("hourly"), e;
}, C = (t) => {
if (r(
t.attributes,
1
/* FORECAST_DAILY */
))
return "daily";
if (r(
t.attributes,
4
/* FORECAST_TWICE_DAILY */
))
return "twice_daily";
if (r(
t.attributes,
2
/* FORECAST_HOURLY */
))
return "hourly";
};
export {
s as WeatherEntityFeature,
C as getDefaultForecastType,
I as getForecast,
S as getSupportedForecastTypes,
O as subscribeForecast
};
//# sourceMappingURL=helpers.js.map