Skip to content

Commit

Permalink
fix(linux/hwmon): 🐛 fix naming of alarm sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuar committed Sep 9, 2024
1 parent fecb599 commit ee78240
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
7 changes: 1 addition & 6 deletions pkg/linux/hwmon/hwmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,6 @@ func (s *Sensor) ID() string {
id.WriteString("_")
id.WriteString(s.id)

if s.MonitorType == Alarm || s.MonitorType == Intrusion {
id.WriteString("_")
id.WriteString(s.MonitorType.String())
}

return strcase.ToSnake(id.String())
}

Expand Down Expand Up @@ -365,7 +360,7 @@ func (s *Sensor) updateInfo(file *sensorFile) error {

if len(parts) == 2 { // 2 parts, limit alarm
s.label = strings.Join([]string{id, parts[0], file.sensorType.String()}, " ")
s.id = strings.Join([]string{id, parts[0], file.sensorType.String()}, "_")
s.id = strings.Join([]string{id, parts[0], "alarm"}, "_")
} else { // channel alarm
s.label = strings.Join([]string{id, file.sensorType.String()}, " ")
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/linux/hwmon/hwmon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,8 @@ func TestChip_getSensors(t *testing.T) {
alarmSensor := &Sensor{
value: false,
label: "Temp1 Crit Alarm",
id: "temp1_crit",
id: "temp1_crit_alarm",
MonitorType: Alarm,
Attributes: []Attribute{
{Name: "max", Value: 80},
{Name: "crit", Value: 100},
},
}

type fields struct {
Expand Down Expand Up @@ -143,6 +139,7 @@ func TestChip_getSensors(t *testing.T) {
if !tt.wantErr {
for i := range tt.want {
if !slices.ContainsFunc(got, func(s *Sensor) bool {
t.Logf("Chip.getSensors() = %v, want %v", s.id, tt.want[i].id)
return s.id == tt.want[i].id
}) {
t.Errorf("Chip.getSensors() = %v, want %v", got, tt.want)
Expand Down

0 comments on commit ee78240

Please sign in to comment.