mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-03 16:01:00 +00:00 
			
		
		
		
	Fix glances cpu temp detection & fahrenheit conversion
This commit is contained in:
		
							parent
							
								
									2ab8e63df2
								
							
						
					
					
						commit
						f3ec238a2c
					
				@ -6,6 +6,12 @@ import { useTranslation } from "next-i18next";
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import UsageBar from "../resources/usage-bar";
 | 
					import UsageBar from "../resources/usage-bar";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const cpuSensorLabels = ["cpu_thermal", "Core"];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function convertToFahrenheit(t) {
 | 
				
			||||||
 | 
					  return t * 9/5 + 32
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function Widget({ options }) {
 | 
					export default function Widget({ options }) {
 | 
				
			||||||
  const { t, i18n } = useTranslation();
 | 
					  const { t, i18n } = useTranslation();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -65,11 +71,20 @@ export default function Widget({ options }) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const unit = options.units === "imperial" ? "fahrenheit" : "celsius";
 | 
					  const unit = options.units === "imperial" ? "fahrenheit" : "celsius";
 | 
				
			||||||
  let mainTemp;
 | 
					  let mainTemp = 0;
 | 
				
			||||||
  let maxTemp = 80;
 | 
					  let maxTemp = 80;
 | 
				
			||||||
  if (options.cputemp && data.sensors) {
 | 
					  const cpuSensors = data.sensors?.filter(s => cpuSensorLabels.some(label => s.label.startsWith(label)) && s.type === "temperature_core");
 | 
				
			||||||
    mainTemp = unit === "celsius" ? data.sensors.find(s => s.label.includes("cpu_thermal")).value : data.sensors.find(s => s.label.includes("cpu_thermal")).value * 5/9 + 32;
 | 
					  if (options.cputemp && cpuSensors) {
 | 
				
			||||||
    if (data.sensors.warning) maxTemp = data.sensors.warning;
 | 
					    try {
 | 
				
			||||||
 | 
					      mainTemp = cpuSensors.reduce((acc, s) => acc + s.value, 0) / cpuSensors.length;
 | 
				
			||||||
 | 
					      maxTemp = Math.max(cpuSensors.reduce((acc, s) => acc + s.warning, 0) / cpuSensors.length, maxTemp);
 | 
				
			||||||
 | 
					      if (unit === "fahrenheit") {
 | 
				
			||||||
 | 
					        mainTemp = convertToFahrenheit(mainTemp);
 | 
				
			||||||
 | 
					        maxTemp = convertToFahrenheit(maxTemp);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } catch (e) {
 | 
				
			||||||
 | 
					      // cpu sensor retrieval failed
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  const tempPercent = Math.round((mainTemp / maxTemp) * 100);
 | 
					  const tempPercent = Math.round((mainTemp / maxTemp) * 100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -110,7 +125,7 @@ export default function Widget({ options }) {
 | 
				
			|||||||
            <UsageBar percent={data.quicklook.mem} />
 | 
					            <UsageBar percent={data.quicklook.mem} />
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        {options.cputemp && mainTemp &&
 | 
					        {options.cputemp && mainTemp > 0 &&
 | 
				
			||||||
            (<div className="flex-none flex flex-row items-center mr-3 py-1.5">
 | 
					            (<div className="flex-none flex flex-row items-center mr-3 py-1.5">
 | 
				
			||||||
            <FaThermometerHalf className="text-theme-800 dark:text-theme-200 w-5 h-5" />
 | 
					            <FaThermometerHalf className="text-theme-800 dark:text-theme-200 w-5 h-5" />
 | 
				
			||||||
            <div className="flex flex-col ml-3 text-left min-w-[85px]">
 | 
					            <div className="flex flex-col ml-3 text-left min-w-[85px]">
 | 
				
			||||||
 | 
				
			|||||||
@ -6,7 +6,7 @@ import { useTranslation } from "next-i18next";
 | 
				
			|||||||
import UsageBar from "./usage-bar";
 | 
					import UsageBar from "./usage-bar";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function convertToFahrenheit(t) {
 | 
					function convertToFahrenheit(t) {
 | 
				
			||||||
  return t * 5/9 + 32
 | 
					  return t * 9/5 + 32
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function CpuTemp({ expanded, units }) {
 | 
					export default function CpuTemp({ expanded, units }) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user