forked from tobias-kuendig/hacompanion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
definitions.go
91 lines (89 loc) · 2.75 KB
/
definitions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"hacompanion/entity"
"hacompanion/sensor"
)
// sensorDefinitions is used to map the configuration to internal types.
var sensorDefinitions = map[string]func(m entity.Meta) entity.SensorDefinition{
"cpu_temp": func(m entity.Meta) entity.SensorDefinition {
unit := "C"
if !m.GetBool("celsius") {
unit = "F"
}
return entity.SensorDefinition{
Type: "sensor",
Runner: func(m entity.Meta) entity.Runner { return sensor.NewCPUTemp(m) },
DeviceClass: "temperature",
Icon: "mdi:thermometer",
Unit: unit,
}
},
"cpu_usage": func(_ entity.Meta) entity.SensorDefinition {
return entity.SensorDefinition{
Type: "sensor",
Runner: func(m entity.Meta) entity.Runner { return sensor.NewCPUUsage() },
Icon: "mdi:gauge",
Unit: "%",
}
},
"memory": func(_ entity.Meta) entity.SensorDefinition {
return entity.SensorDefinition{
Type: "sensor",
Runner: func(meta entity.Meta) entity.Runner { return sensor.NewMemory() },
Icon: "mdi:memory",
}
},
"power": func(_ entity.Meta) entity.SensorDefinition {
return entity.SensorDefinition{
Type: "sensor",
Runner: func(m entity.Meta) entity.Runner { return sensor.NewPower(m) },
Icon: "mdi:battery",
DeviceClass: "battery",
Unit: "%",
}
},
"uptime": func(_ entity.Meta) entity.SensorDefinition {
return entity.SensorDefinition{
Runner: func(meta entity.Meta) entity.Runner { return sensor.NewUptime() },
Type: "sensor",
Icon: "mdi:sort-clock-descending",
DeviceClass: "timestamp",
}
},
"load_avg": func(_ entity.Meta) entity.SensorDefinition {
return entity.SensorDefinition{
Type: "sensor",
Runner: func(meta entity.Meta) entity.Runner { return sensor.NewLoadAVG() },
Icon: "mdi:gauge",
}
},
"webcam": func(_ entity.Meta) entity.SensorDefinition {
return entity.SensorDefinition{
Type: "sensor",
Runner: func(meta entity.Meta) entity.Runner { return sensor.NewWebCam() },
Icon: "mdi:webcam",
}
},
"audio_volume": func(_ entity.Meta) entity.SensorDefinition {
return entity.SensorDefinition{
Type: "sensor",
Runner: func(meta entity.Meta) entity.Runner { return sensor.NewAudioVolume() },
Icon: "mdi:volume-high",
Unit: "%",
}
},
"online_check": func(_ entity.Meta) entity.SensorDefinition {
return entity.SensorDefinition{
Type: "binary_sensor",
Runner: func(m entity.Meta) entity.Runner { return sensor.NewOnlineCheck(m) },
Icon: "mdi:shield-check-outline",
}
},
"companion_running": func(_ entity.Meta) entity.SensorDefinition {
return entity.SensorDefinition{
Type: "binary_sensor",
Runner: func(meta entity.Meta) entity.Runner { return NullRunner{} },
Icon: "mdi:heart-pulse",
}
},
}