Enhancement: configurable CPU temp scale (#3332)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
pull/3343/head
David Hirsch 2 weeks ago committed by GitHub
parent 068e664f16
commit c95837f54e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -19,6 +19,8 @@ _Note: unfortunately, the package used for getting CPU temp ([systeminformation]
memory: true
disk: /disk/mount/path
cputemp: true
tempmin: 0 # optional, minimum cpu temp
tempmax: 100 # optional, maximum cpu temp
uptime: true
units: imperial # only used by cpu temp
refresh: 3000 # optional, in ms

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

@ -8,7 +8,7 @@ import CpuTemp from "./cputemp";
import Uptime from "./uptime";
export default function Resources({ options }) {
const { expanded, units, diskUnits } = options;
const { expanded, units, diskUnits, tempmin, tempmax } = options;
let { refresh } = options;
if (!refresh) refresh = 1500;
refresh = Math.max(refresh, 1000);
@ -23,7 +23,9 @@ export default function Resources({ options }) {
<Disk key={disk} options={{ disk }} expanded={expanded} diskUnits={diskUnits} refresh={refresh} />
))
: options.disk && <Disk options={options} expanded={expanded} diskUnits={diskUnits} refresh={refresh} />}
{options.cputemp && <CpuTemp expanded={expanded} units={units} refresh={refresh} />}
{options.cputemp && (
<CpuTemp expanded={expanded} units={units} refresh={refresh} tempmin={tempmin} tempmax={tempmax} />
)}
{options.uptime && <Uptime refresh={refresh} />}
</div>
{options.label && (

Loading…
Cancel
Save