@@ -490,44 +490,24 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
490490 }
491491
492492 // Add discovered temperature sensor to the list
493+ optional := optionalProperties (filepath .Join (directory , basename ))
493494 temperatures = append (temperatures , TemperatureStat {
494495 SensorKey : name ,
495496 Temperature : temperature / hostTemperatureScale ,
496- High : optionalValueReadFromFile ( basepath + "_max" ) / hostTemperatureScale ,
497- Critical : optionalValueReadFromFile ( basepath + "_crit" ) / hostTemperatureScale ,
498- Optional : optionalProperties ( filepath . Join ( directory , basename )) ,
497+ High : optional [ "max" ] ,
498+ Critical : optional [ "crit" ] ,
499+ Optional : optional ,
499500 })
500501 }
501502
502503 return temperatures , warns .Reference ()
503504}
504505
505- func optionalValueReadFromFile (filename string ) float64 {
506- var raw []byte
507- var err error
508- var value float64
509-
510- // Check if file exists
511- if _ , err := os .Stat (filename ); os .IsNotExist (err ) {
512- return 0
513- }
514-
515- if raw , err = os .ReadFile (filename ); err != nil {
516- return 0
517- }
518-
519- if value , err = strconv .ParseFloat (strings .TrimSpace (string (raw )), 64 ); err != nil {
520- return 0
521- }
522-
523- return value
524- }
525-
526506func optionalProperties (basename string ) map [string ]float64 {
527507 // Determine all files with the base-prefix
528508 matches , err := filepath .Glob (basename + "_*" )
529509 if err != nil {
530- return nil
510+ return map [ string ] float64 {}
531511 }
532512
533513 // Collect the information from all files that are not already handled
0 commit comments