-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevicepower.go
68 lines (54 loc) · 1.89 KB
/
devicepower.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
package shelly
import (
"context"
"github.com/mongoose-os/mos/common/mgrpc"
"github.com/mongoose-os/mos/common/mgrpc/frame"
)
type DevicePowerStatus struct {
// ID of the devicepower component instance.
ID int `json:"id"`
// Battery is information about the battery charge.
Battery *DevicePowerBatteryStatus `json:"battery,omitempty"`
// External is about the external power source (only available if external power source is supported).
External *DevicePowerExternalStatus `json:"external,omitempty"`
// Errors is a list of error events related to device power.
Errors []string `json:"errors,omitempty"`
}
// DevicePowerBatteryStatus is information about the battery charge.
type DevicePowerBatteryStatus struct {
// V is battery voltage in Volts (null if valid value could not be obtained).
V *float64 `json:"V,omitempty"`
// Percent is the battery charge level in % (null if valid value could not be obtained).
Percent *float64 `json:"percent,omitempty"`
}
// DevicePowerExternalStatus is about the external power source (only available if external power source is supported).
type DevicePowerExternalStatus struct {
// Present is true if external power source is connected, false otherwise.
Present bool `json:"present"`
}
type DevicePowerGetStatusRequest struct {
// ID of the DevicePower component instance.
ID int `json:"id"`
}
func (r *DevicePowerGetStatusRequest) Method() string {
return "DevicePower.GetStatus"
}
func (r *DevicePowerGetStatusRequest) NewTypedResponse() *DevicePowerStatus {
return &DevicePowerStatus{}
}
func (r *DevicePowerGetStatusRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *DevicePowerGetStatusRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*DevicePowerStatus,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}