Files
litoral-central-frontend/src/features/climate/hooks/useClimateChartCatalog.ts
T

37 lines
1.2 KiB
TypeScript

import { useMemo } from "react";
import type { ChartVariable } from "../../telemetry/types/telemetryCatalog";
import { useClimateHistory } from "./useClimateHistory";
export function useClimateChartCatalog() {
const climate = useClimateHistory();
const chartableVariables = useMemo<ChartVariable[]>(
() =>
climate.sensors.map((sensor) => ({
sensorId: sensor.sensorId,
key: sensor.key,
label: sensor.name,
value:
typeof sensor.value === "number" ||
typeof sensor.value === "string" ||
typeof sensor.value === "boolean" ||
sensor.value === null
? sensor.value
: null,
unit: sensor.unit ?? "",
timestamp: sensor.timestamp,
category: "Clima",
group: "Climate",
chartable: true,
})),
[climate.sensors],
);
return {
chartableVariables,
connected: climate.connected,
loading: !climate.module,
sensorCount: climate.sensorCount,
lastTimestamp: climate.lastTimestamp,
};
}