mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-27 17:00:54 +01:00
* 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
26 lines
893 B
TypeScript
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",
|
|
});
|