Files
Homarr/packages/request-handler/src/smart-home-entity-state.ts
Meier Lukas 3804d530ec feat(pihole): add support for v6 (#2448)
* feat(pihole): add support for v6

* fix: add session-store to keep using same session for pi-hole requests

* chore: address pull request feedback

* fix: import issue

* fix: other import errors
2025-03-04 21:17:35 +01:00

26 lines
893 B
TypeScript

import dayjs from "dayjs";
import type { IntegrationKindByCategory } from "@homarr/definitions";
import { createIntegrationAsync } from "@homarr/integrations";
import { createCachedIntegrationRequestHandler } from "./lib/cached-integration-request-handler";
export const smartHomeEntityStateRequestHandler = createCachedIntegrationRequestHandler<
string,
IntegrationKindByCategory<"smartHomeServer">,
{ entityId: string }
>({
async requestAsync(integration, input) {
const integrationInstance = await createIntegrationAsync(integration);
const result = await integrationInstance.getEntityStateAsync(input.entityId);
if (!result.success) {
throw new Error(`Unable to fetch data from Home Assistant error='${result.error as string}'`);
}
return result.data.state;
},
cacheDuration: dayjs.duration(1, "minute"),
queryKey: "smartHome-entityState",
});