import useSWR from "swr"; import { FaThermometerHalf } from "react-icons/fa"; import { useTranslation } from "next-i18next"; import Resource from "../widget/resource"; import Error from "../widget/error"; function convertToFahrenheit(t) { return (t * 9) / 5 + 32; } export default function CpuTemp({ expanded, units, refresh = 1500, tempmin = 0, tempmax = -1 }) { const { t } = useTranslation(); const { data, error } = useSWR(`/api/widgets/resources?type=cputemp`, { refreshInterval: refresh, }); if (error || data?.error) { return ; } if (!data || !data.cputemp) { return ( ); } let mainTemp = data.cputemp.main; if (data.cputemp.cores?.length) { mainTemp = data.cputemp.cores.reduce((a, b) => a + b) / data.cputemp.cores.length; } const unit = units === "imperial" ? "fahrenheit" : "celsius"; mainTemp = unit === "celsius" ? mainTemp : convertToFahrenheit(mainTemp); const minTemp = tempmin < mainTemp ? tempmin : mainTemp; let maxTemp = tempmax; if (maxTemp < minTemp) { maxTemp = unit === "celsius" ? data.cputemp.max : convertToFahrenheit(data.cputemp.max); } return ( ); }