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