@@ -8,15 +8,35 @@ type GetRealtimeRequest struct {
8
8
}
9
9
10
10
type GetRealtimeResponse struct {
11
- Current float64 `mapstructure:"current_ma"`
12
- Voltage float64 `mapstructure:"voltage_mv"`
13
- Power float64 `mapstructure:"power_mw"`
14
- Total float64 `mapstructure:"total_wh"`
11
+ // some fw/hw may use the following keys
12
+ Current float64 `mapstructure:"current"` // unit is A
13
+ Voltage float64 `mapstructure:"voltage"` // unit is V
14
+ Power float64 `mapstructure:"power"` // unit is W
15
+ Total float64 `mapstructure:"total"` // unit is kWh
16
+
17
+ // some may use these
18
+ CurrentmA float64 `mapstructure:"current_ma"`
19
+ VoltagemV float64 `mapstructure:"voltage_mv"`
20
+ PowermW float64 `mapstructure:"power_mw"`
21
+ TotalWh float64 `mapstructure:"total_wh"`
22
+ }
23
+
24
+ func (r * GetRealtimeResponse ) Normalize () {
25
+ if r .TotalWh != - 1 {
26
+ r .Current = r .CurrentmA / 1000
27
+ r .Voltage = r .VoltagemV / 1000
28
+ r .Power = r .PowermW / 1000
29
+ r .Total = r .TotalWh / 1000
30
+ }
15
31
}
16
32
17
33
func (s * KasaClientEmeterService ) GetRealtime () (* GetRealtimeResponse , error ) {
18
- var response GetRealtimeResponse
34
+ response := GetRealtimeResponse {
35
+ TotalWh : - 1 ,
36
+ }
19
37
err := s .c .RPC ("emeter" , "get_realtime" , GetRealtimeRequest {}, & response )
20
38
39
+ response .Normalize ()
40
+
21
41
return & response , err
22
42
}
0 commit comments