Fan Speed improvements (#42)

Add support multiple Fan Speed Key Patterns
Present real fan speed name
Option to show/hide zero speed fans
Implements #41
This commit is contained in:
Meliox 2024-06-16 17:20:18 +02:00 committed by GitHub
parent 94acafdc85
commit f77eadc0a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -207,9 +207,24 @@ function configure {
# Look for fan speeds # Look for fan speeds
msg "\nDetecting support for fan speed readings..." msg "\nDetecting support for fan speed readings..."
if (echo "$sensorsOutput" | grep -q "fan[0-9]*_input"); then if (echo "$sensorsOutput" | grep -q "fan[0-9]*_input"); then
msg "Detected fan speed sensors:\n$(echo "$sensorsOutput" | grep -o 'fan[0-9]*_input[^"]*')" msg "Detected fan speed sensors:\n$(echo $sensorsOutput | grep -Po '"[^"]*":\s*\{\s*"fan[0-9]*_input[^}]*' | sed -E 's/"([^"]*)":.*/\1/')"
enableFanSpeed=true enableFanSpeed=true
sensorsDetected=true sensorsDetected=true
# Prompt user for display zero speed fans
local choiceDisplayZeroSpeedFans=$(read -p "Do you wish to display fans reporting a speed of zero? If no, only active fans will be displayed. (Y/n)")
case "$choiceDisplayZeroSpeedFans" in
# Set temperature search criteria
[yY]|"")
displayZeroSpeedFans=true
;;
[nN] )
displayZeroSpeedFans=false
;;
*)
# If the user enters an invalid input, print an error message and exit the script with a non-zero status code
err "Invalid input. Exiting..."
;;
esac
else else
warn "No fan speed sensors found." warn "No fan speed sensors found."
enableFanSpeed=false enableFanSpeed=false
@ -678,19 +693,40 @@ Ext.define('PVE.mod.TempHelper', {\n\
} catch(e) {\n\ } catch(e) {\n\
objValue = {};\n\ objValue = {};\n\
}\n\ }\n\
\n\
// Recursive function to find fan keys and values\n\
function findFanKeys(obj, fanKeys, parentKey = null) {\n\
Object.keys(obj).forEach(key => {\n\
const value = obj[key];\n\
if (typeof value === 'object' && value !== null) {\n\
// If the value is an object, recursively call the function\n\
findFanKeys(value, fanKeys, key);\n\
} else if (/^fan[0-9]+(_input)?$/.test(key)) {\n\
if ($displayZeroSpeedFans != true && value === 0) {\n\
// Skip this fan if displayZeroSpeedFans is false and value is 0\n\
return;\n\
}\n\
// If the key matches the pattern, add the parent key and value to the fanKeys array\n\
fanKeys.push({ key: parentKey, value: value });\n\
}\n\
});\n\
}\n\
\n\
let speeds = [];\n\ let speeds = [];\n\
// Loop through the parent keys\n\ // Loop through the parent keys\n\
Object.keys(objValue).forEach(parentKey => {\n\ Object.keys(objValue).forEach(parentKey => {\n\
const parentObj = objValue[parentKey];\n\ const parentObj = objValue[parentKey];\n\
// Filter and sort fan keys for each parent object\n\ // Array to store fan keys and values\n\
const fanKeys = Object.keys(parentObj).filter(item => /^fan[0-9]+$/.test(item)).sort();\n\ const fanKeys = [];\n\
fanKeys.forEach((fanKey) => {\n\ // Call the recursive function to find fan keys and values\n\
findFanKeys(parentObj, fanKeys);\n\
// Sort the fan keys\n\
fanKeys.sort();\n\
// Process each fan key and value\n\
fanKeys.forEach(({ key: fanKey, value: fanSpeed }) => {\n\
try {\n\ try {\n\
const fanSpeed = parentObj[fanKey][\`\${fanKey}_input\`];\n\ const fan = fanKey.charAt(0).toUpperCase() + fanKey.slice(1); // Capitalize the first letter of fanKey\n\
const fanNumber = fanKey.replace('fan', ''); // Extract fan number from the key\n\ speeds.push(\`\${fan}: \${fanSpeed} RPM\`);\n\
if (fanSpeed !== undefined) {\n\
speeds.push(\`Fan \${fanNumber}: \${fanSpeed} RPM\`);\n\
}\n\
} catch(e) {\n\ } catch(e) {\n\
console.error(\`Error retrieving fan speed for \${fanKey} in \${parentKey}:\`, e); // Debug: Log specific error\n\ console.error(\`Error retrieving fan speed for \${fanKey} in \${parentKey}:\`, e); // Debug: Log specific error\n\
}\n\ }\n\