[sensors] allow sensor readings when there are warnings

This commit is contained in:
anxdpanic 2025-04-13 20:32:36 -04:00
parent 0daa620b11
commit 41e74ba9b5
2 changed files with 5 additions and 5 deletions

View File

@ -96,20 +96,20 @@ func parseCliOptions() (*cliOptions, error) {
func cliSensorsPrint() int {
tempSensors, err := sensors.SensorsTemperatures()
if err != nil {
fmt.Printf("Failed to retrieve list of sensors: %v\n", err)
fmt.Printf("Errors encountered while retrieving list of sensors:\n %v\n", err)
if warns, ok := err.(*sensors.Warnings); ok {
for _, w := range warns.List {
fmt.Printf(" - %v\n", w)
}
}
return 1
}
if len(tempSensors) == 0 {
if tempSensors == nil || len(tempSensors) == 0 {
fmt.Println("No sensors found")
return 0
}
fmt.Println("Sensors found:")
for _, sensor := range tempSensors {
fmt.Printf(" %s: %.1f°C\n", sensor.SensorKey, sensor.Temperature)
}

View File

@ -205,7 +205,7 @@ func Collect(req *SystemInfoRequest) (*SystemInfo, []error) {
// also disabled on openbsd because it's not implemented by go-psutil
if runtime.GOOS != "windows" && runtime.GOOS != "openbsd" {
sensorReadings, err := sensors.SensorsTemperatures()
if err == nil {
if sensorReadings != nil && len(sensorReadings) > 0 {
if req.CPUTempSensor != "" {
for i := range sensorReadings {
if sensorReadings[i].SensorKey == req.CPUTempSensor {