-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbthome_sensor.go
166 lines (134 loc) · 4.08 KB
/
bthome_sensor.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package shelly
import (
"context"
"github.com/mongoose-os/mos/common/mgrpc"
"github.com/mongoose-os/mos/common/mgrpc/frame"
)
type BTHomeSensorConfig struct {
// ID of the component instance.
ID int `json:"id"`
// Name of the component instance.
Name *string `json:"name"`
// ObjID is the BTHome object id in decimal
ObjID int `json:"obj_id"`
// IDX is the BTHome object index in decimal
IDX int `json:"idx"`
// MAC address of the physical device
Addr string `json:"addr"`
// Meta contains meta data for the component.
Meta BTHomeSensorConfigMeta `json:"meta"`
}
// Object for storing meta data
type BTHomeSensorConfigMeta struct {
// UI contains setting for how the component will be rendered in the UI.
UI BTHomeSensorConfigMetaUI `json:"ui"`
}
// BTHomeSensorConfigMetaUI contains setting for how the component will be rendered in the UI.
type BTHomeSensorConfigMetaUI struct {
// Icon allows setting custom icon for the component's card by providing an external hosted image via link.
Icon *string `json:"icon"`
}
// BTHomeSensorGetConfigRequest contains parameters for the BTHomeSensor.GetConfig RPC request.
type BTHomeSensorGetConfigRequest struct {
// ID of the BTHomeSensor component instance.
ID int `json:"id"`
}
func (r *BTHomeSensorGetConfigRequest) Method() string {
return "BTHomeSensor.GetConfig"
}
func (r *BTHomeSensorGetConfigRequest) NewTypedResponse() *BTHomeSensorConfig {
return &BTHomeSensorConfig{}
}
func (r *BTHomeSensorGetConfigRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeSensorGetConfigRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*BTHomeSensorConfig,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
// BTHomeSensorSetConfigRequest contains parameters for the BTHomeSensor.SetConfig RPC request.
type BTHomeSensorSetConfigRequest struct {
// ID of the BTHomeSensor component instance.
ID int `json:"id"`
// Config that the method takes.
Config BTHomeSensorConfig `json:"config"`
}
func (r *BTHomeSensorSetConfigRequest) Method() string {
return "BTHomeSensor.SetConfig"
}
func (r *BTHomeSensorSetConfigRequest) NewTypedResponse() *SetConfigResponse {
return &SetConfigResponse{}
}
func (r *BTHomeSensorSetConfigRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeSensorSetConfigRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*SetConfigResponse,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
// BTHomeSensorGetStatusRequst contains parameters for the BTHomeSensor.GetStatus RPC request.
type BTHomeSensorGetStatusRequest struct {
// ID of the BTHomeSensor component instance.
ID int `json:"id"`
}
func (r *BTHomeSensorGetStatusRequest) Method() string {
return "BTHomeSensor.GetStatus"
}
func (r *BTHomeSensorGetStatusRequest) NewTypedResponse() *BTHomeSensorStatus {
return &BTHomeSensorStatus{}
}
func (r *BTHomeSensorGetStatusRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeSensorGetStatusRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*BTHomeSensorStatus,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
// BTHomeSensorStatus describes the status of BTHomeSensor component instances.
type BTHomeSensorStatus struct {
// ID of the BTHomeSensor component instance.
ID int `json:"id"`
// Value of the sensor (latest).
Value interface{} `json:"value,omitempty"`
// LastUpdateTS is the timestamp of the last received value.
LastUpdateTS *float64 `json:"last_update_ts,omitempty"`
}
func (r *BTHomeSensorStatus) GetIntValue() (int, bool) {
v, ok := r.Value.(int)
return v, ok
}
func (r *BTHomeSensorStatus) GetFloatValue() (float64, bool) {
v, ok := r.Value.(float64)
return v, ok
}
func (r *BTHomeSensorStatus) GetStringValue() (string, bool) {
v, ok := r.Value.(string)
return v, ok
}