Skip to content

Commit

Permalink
fix(linux)!: handle hwmon chips with the same name
Browse files Browse the repository at this point in the history
BREAKING CHANGE: When more than one chip exposed
by the hwmon userspace API have the same name, the
agent was not treating them as unique. This commit
fixes the code to ensure every chip gets its own
sensors. This unfortunately required changing the
naming format of all chips, so will result in new
sensors being recorded in Home Assistant.

The new naming convention will have a number
appended to the chip name. So for example, where
most Intel CPUs had a hwmon chip called
"Coretemp", producing sensor names like "Coretemp
Core 0 Temp", these will now be called "Coretemp 0
Core 0 Temp" (i.e., a number after "Coretemp").
Similar naming patterns are used for other chips.

Users may want to remove the old sensors manually,
under Developer Tools->Statistics in Home
Assistant, for example. Or they can wait until
they age out of the Home Assistant long-term
statistics database automatically.
  • Loading branch information
joshuar committed Apr 26, 2024
1 parent 501fe22 commit 16f56dd
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 174 deletions.
13 changes: 10 additions & 3 deletions internal/linux/system/hwmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,17 @@ func newHWSensor(s *hwmon.Sensor) *hwSensor {
func HWSensorUpdater(ctx context.Context) chan sensor.Details {
sensorCh := make(chan sensor.Details, 1)
update := func(_ time.Duration) {
allSensors := hwmon.GetAllSensors()
allSensors, err := hwmon.GetAllSensors()
if err != nil && len(allSensors) > 0 {
log.Warn().Err(err).Msg("Errors fetching some chip/sensor values from hwmon API.")
}
if err != nil && len(allSensors) == 0 {
log.Warn().Err(err).Msg("Could not retrieve any chip/sensor values from hwmon API.")
return
}
for _, s := range allSensors {
sensor := newHWSensor(&s)
sensorCh <- sensor
hwSensor := newHWSensor(s)
sensorCh <- hwSensor
}
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/linux/hwmon/examples/getAllSensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ func main() {
if err = trace.Start(trc); err != nil {
log.Fatal().Err(err).Msg("Could not start trace profiling.")
}
for _, s := range hwmon.GetAllSensors() {
sensors, err := hwmon.GetAllSensors()
if err != nil && len(sensors) > 0 {
log.Warn().Err(err).Msg("Errors fetching some chip/sensor values.")
}
if err != nil && len(sensors) == 0 {
log.Fatal().Err(err).Msg("Could not retrieve any chip/sensor values.")
}
for _, s := range sensors {
println(s.String())
}

Expand Down
Loading

0 comments on commit 16f56dd

Please sign in to comment.