Enhancement: configurable CPU temp scale (#3332)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
David Hirsch
2024-04-20 01:32:14 +02:00
committed by GitHub
parent 068e664f16
commit c95837f54e
3 changed files with 14 additions and 5 deletions

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}
/>
);