mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00
Enhancement: configurable CPU temp scale (#3332)
--------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
parent
068e664f16
commit
c95837f54e
@ -19,6 +19,8 @@ _Note: unfortunately, the package used for getting CPU temp ([systeminformation]
|
|||||||
memory: true
|
memory: true
|
||||||
disk: /disk/mount/path
|
disk: /disk/mount/path
|
||||||
cputemp: true
|
cputemp: true
|
||||||
|
tempmin: 0 # optional, minimum cpu temp
|
||||||
|
tempmax: 100 # optional, maximum cpu temp
|
||||||
uptime: true
|
uptime: true
|
||||||
units: imperial # only used by cpu temp
|
units: imperial # only used by cpu temp
|
||||||
refresh: 3000 # optional, in ms
|
refresh: 3000 # optional, in ms
|
||||||
|
@ -9,7 +9,7 @@ function convertToFahrenheit(t) {
|
|||||||
return (t * 9) / 5 + 32;
|
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 { t } = useTranslation();
|
||||||
|
|
||||||
const { data, error } = useSWR(`/api/widgets/resources?type=cputemp`, {
|
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";
|
const unit = units === "imperial" ? "fahrenheit" : "celsius";
|
||||||
mainTemp = unit === "celsius" ? mainTemp : convertToFahrenheit(mainTemp);
|
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 (
|
return (
|
||||||
<Resource
|
<Resource
|
||||||
@ -58,7 +63,7 @@ export default function CpuTemp({ expanded, units, refresh = 1500 }) {
|
|||||||
unit,
|
unit,
|
||||||
})}
|
})}
|
||||||
expandedLabel={t("resources.max")}
|
expandedLabel={t("resources.max")}
|
||||||
percentage={Math.round((mainTemp / maxTemp) * 100)}
|
percentage={Math.round(((mainTemp - minTemp) / (maxTemp - minTemp)) * 100)}
|
||||||
expanded={expanded}
|
expanded={expanded}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -8,7 +8,7 @@ import CpuTemp from "./cputemp";
|
|||||||
import Uptime from "./uptime";
|
import Uptime from "./uptime";
|
||||||
|
|
||||||
export default function Resources({ options }) {
|
export default function Resources({ options }) {
|
||||||
const { expanded, units, diskUnits } = options;
|
const { expanded, units, diskUnits, tempmin, tempmax } = options;
|
||||||
let { refresh } = options;
|
let { refresh } = options;
|
||||||
if (!refresh) refresh = 1500;
|
if (!refresh) refresh = 1500;
|
||||||
refresh = Math.max(refresh, 1000);
|
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} />
|
<Disk key={disk} options={{ disk }} expanded={expanded} diskUnits={diskUnits} refresh={refresh} />
|
||||||
))
|
))
|
||||||
: options.disk && <Disk options={options} 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} />}
|
{options.uptime && <Uptime refresh={refresh} />}
|
||||||
</div>
|
</div>
|
||||||
{options.label && (
|
{options.label && (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user