import { useQuery } from '@tanstack/react-query'; import { Gauge } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { api } from '../api/client'; import type { PrinterHASensorReading } from '../api/client'; import { describeHASensorReading, iconForHASensor } from '../utils/haSensorDisplay'; /** * The Home Assistant sensors bound to a printer, on its card (#1148, #448). * * Read-only by design — these are contacts and thermometers, not switches, so * nothing here is clickable. The sibling "HA:" row above handles the entities * you can actually operate. */ interface Props { printerId: number; } export function PrinterHASensorRow({ printerId }: Props) { const { t } = useTranslation(); const { data: readings } = useQuery({ queryKey: ['haSensorReadings', printerId], queryFn: () => api.getHASensorReadings(printerId), // Served from the backend poller's cache, so this costs a local request // and never a Home Assistant round trip. Matched to the poller's own // cadence — refetching faster would only re-read the same reading. refetchInterval: 15000, }); if (!readings?.length) return null; const describe = (reading: PrinterHASensorReading): string => describeHASensorReading(reading, t); return (