@hakit/core
Version:
A collection of React hooks and helpers for Home Assistant to easily communicate with the Home Assistant WebSocket API.
86 lines (85 loc) • 2.39 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-DnHwXFlq.js";
import "../../HassConnect/HassContext.js";
import "@iconify/react";
import "use-debounce";
import "deep-object-diff";
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;
}
}, n = (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" };
}, O = (t, e, i) => {
if (i === void 0)
return e?.type !== void 0 && e?.forecast && e?.forecast?.length > 2 ? { forecast: e.forecast, type: e?.type } : n(t);
if (i === "legacy")
return n(t);
if (i === e?.type && e?.forecast && e?.forecast?.length > 2)
return { forecast: e.forecast, type: i };
}, S = (t, e, i, o) => t.subscribeMessage(o, {
type: "weather/subscribe_forecast",
forecast_type: i,
entity_id: e
}), C = (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;
}, L = (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,
L as getDefaultForecastType,
O as getForecast,
C as getSupportedForecastTypes,
S as subscribeForecast
};
//# sourceMappingURL=helpers.js.map