-
Notifications
You must be signed in to change notification settings - Fork 0
/
bthome.go
246 lines (199 loc) · 6.24 KB
/
bthome.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
package shelly
import (
"context"
"github.com/mongoose-os/mos/common/mgrpc"
"github.com/mongoose-os/mos/common/mgrpc/frame"
)
// BTHomeAddDeviceRequest contains parameters for the BTHome.GetConfig RPC request.
type BTHomeAddDeviceRequest struct {
// ID for the new component. Accepted range: [200..299]. Optional. If omitted, the first free
// ID will be used. If the desired ID is not available, an error will be returned.
ID int `json:"id"`
// Config to be used for the new component.
Config BTHomeDeviceConfig `json:"config"`
}
func (r *BTHomeAddDeviceRequest) Method() string {
return "BTHome.AddDevice"
}
func (r *BTHomeAddDeviceRequest) NewTypedResponse() *BTHomeAddDeviceResponse {
return &BTHomeAddDeviceResponse{}
}
func (r *BTHomeAddDeviceRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeAddDeviceRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*BTHomeAddDeviceResponse,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
type BTHomeAddDeviceResponse struct {
// Key of the newly created component. (in format <type>:<cid>, for example bthomedevice:200)
Key string `json:"key"`
}
// BTHomeDeleteDeviceRequest contains parameters for the BTHome.DeleteDevice RPC request.
type BTHomeDeleteDeviceRequest struct {
// ID of existing BTHomeDevice component (Required)
ID int `json:"id"`
}
func (r *BTHomeDeleteDeviceRequest) Method() string {
return "BTHome.DeleteDevice"
}
func (r *BTHomeDeleteDeviceRequest) NewTypedResponse() *BTHomeDeleteDeviceResponse {
return &BTHomeDeleteDeviceResponse{}
}
func (r *BTHomeDeleteDeviceRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeDeleteDeviceRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*BTHomeDeleteDeviceResponse,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
type BTHomeDeleteDeviceResponse struct{}
// BTHomeAddSensorRequest contains parameters for the BTHome.AddSensor RPC request.
type BTHomeAddSensorRequest struct {
// ID for the new component. Accepted range: [200..299]. Optional. If omitted, the first free
// ID will be used. If the desired ID is not available, an error will be returned.
ID *int `json:"id"`
// Config to be used for the new component.
Config BTHomeSensorConfig `json:"config"`
}
func (r *BTHomeAddSensorRequest) Method() string {
return "BTHome.AddSensor"
}
func (r *BTHomeAddSensorRequest) NewTypedResponse() *BTHomeAddSensorResponse {
return &BTHomeAddSensorResponse{}
}
func (r *BTHomeAddSensorRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeAddSensorRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*BTHomeAddSensorResponse,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
type BTHomeAddSensorResponse struct {
// Key of the newly created component. (in format <type>:<cid>, for example bthomesensor:200)
Key string `json:"key"`
}
// BTHomeDeleteSensorRequest contains parameters for the BTHome.DeleteSensor RPC request.
type BTHomeDeleteSensorRequest struct {
// ID of existing BTHomeSensor component (Required)
ID int `json:"id"`
}
func (r *BTHomeDeleteSensorRequest) Method() string {
return "BTHome.DeleteSensor"
}
func (r *BTHomeDeleteSensorRequest) NewTypedResponse() *BTHomeDeleteSensorResponse {
return &BTHomeDeleteSensorResponse{}
}
func (r *BTHomeDeleteSensorRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeDeleteSensorRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*BTHomeDeleteSensorResponse,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
type BTHomeDeleteSensorResponse struct{}
// BTHomeStartDeviceDiscoveryRequest contains parameters for the BTHome.GetConfig RPC request.
type BTHomeStartDeviceDiscoveryRequest struct {
// Duration of the discovery process in seconds. Default is 30 seconds.
Duration int `json:"duration,omitempty"`
}
func (r *BTHomeStartDeviceDiscoveryRequest) Method() string {
return "BTHome.StartDeviceDiscovery"
}
func (r *BTHomeStartDeviceDiscoveryRequest) NewTypedResponse() *BTHomeStartDeviceDiscoveryResponse {
return &BTHomeStartDeviceDiscoveryResponse{}
}
func (r *BTHomeStartDeviceDiscoveryRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeStartDeviceDiscoveryRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*BTHomeStartDeviceDiscoveryResponse,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
type BTHomeStartDeviceDiscoveryResponse struct{}
// BTHomeGetObjectInfosRequest contains parameters for the BTHome.GetConfig RPC request.
type BTHomeGetObjectInfosRequest struct {
// Offset index of the component from which to start generating the result (Optional)
Offset *int `json:"offset,omitempty"`
}
func (r *BTHomeGetObjectInfosRequest) Method() string {
return "BTHome.GetObjectInfos"
}
func (r *BTHomeGetObjectInfosRequest) NewTypedResponse() *BTHomeGetObjectInfosResponse {
return &BTHomeGetObjectInfosResponse{}
}
func (r *BTHomeGetObjectInfosRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeGetObjectInfosRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*BTHomeGetObjectInfosResponse,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
// BTHomeGetObjectInfosResponse ...
// As of 2024-12-17 this isn't officially documented.
type BTHomeGetObjectInfosResponse struct {
Objects []BTHomeGetObjectInfo `json:"objects"`
Offset int `json:"offset,omitempty"`
Count int `json:"count,omitempty"`
Total int `json:"total,omitempty"`
}
type BTHomeGetObjectInfo struct {
ObjID int `json:"obj_id,omitempty"`
ObjName string `json:"obj_name,omitempty"`
Type string `json:"type,omitempty"`
Unit string `json:"unit,omitempty"`
}