Enhancement: configurable CPU temp scale (#3332)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
David Hirschandshamoon authored and GitHub committed 2024-04-19 16:32:14 -07:00
1 parent 068e664f16
commit c95837f54e
3 files changed
+14 -5

No files matched your search

+8 -3
View File
@@ -9,7 +9,7 @@ function convertToFahrenheit(t) {
return (t * 9) / 5 + 32;
}
export default function CpuTemp({ expanded, units, refresh = 1500 }) {
export default function CpuTemp({ expanded, units, refresh = 1500, tempmin = 0, tempmax = -1 }) {
const { t } = useTranslation();
const { data, error } = useSWR(`/api/widgets/resources?type=cputemp`, {
@@ -39,7 +39,12 @@ export default function CpuTemp({ expanded, units, refresh = 1500 }) {
}
const unit = units === "imperial" ? "fahrenheit" : "celsius";
mainTemp = unit === "celsius" ? mainTemp : convertToFahrenheit(mainTemp);
const maxTemp = unit === "celsius" ? data.cputemp.max : convertToFahrenheit(data.cputemp.max);
const minTemp = tempmin < mainTemp ? tempmin : mainTemp;
let maxTemp = tempmax;
if (maxTemp < minTemp) {
maxTemp = unit === "celsius" ? data.cputemp.max : convertToFahrenheit(data.cputemp.max);
}
return (
<Resource
@@ -58,7 +63,7 @@ export default function CpuTemp({ expanded, units, refresh = 1500 }) {
unit,
})}
expandedLabel={t("resources.max")}
percentage={Math.round((mainTemp / maxTemp) * 100)}
percentage={Math.round(((mainTemp - minTemp) / (maxTemp - minTemp)) * 100)}
expanded={expanded}
/>
);