-
Notifications
You must be signed in to change notification settings - Fork 0
/
bthome_device.go
208 lines (167 loc) · 5.3 KB
/
bthome_device.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
package shelly
import (
"context"
"github.com/mongoose-os/mos/common/mgrpc"
"github.com/mongoose-os/mos/common/mgrpc/frame"
)
type BTHomeDeviceConfig struct {
// ID of the component instance.
ID int `json:"id"`
// Name of the component instance.
Name *string `json:"name"`
// MAC address of the physical device
Addr string `json:"addr"`
// AES encryption key as hexadecimal string for encrypted devices
Key *string `json:"key"`
// Meta contains meta data for the component.
Meta BTHomeDeviceConfigMeta `json:"meta"`
}
// Object for storing meta data
type BTHomeDeviceConfigMeta struct {
// UI contains setting for how the component will be rendered in the UI.
UI BTHomeDeviceConfigMetaUI `json:"ui"`
}
// BTHomeDeviceConfigMetaUI contains setting for how the component will be rendered in the UI.
type BTHomeDeviceConfigMetaUI struct {
// Icon allows setting custom icon for the component's card by providing an external hosted image via link.
Icon *string `json:"icon"`
}
type BTHomeDeviceStatus struct {
// ID of the component instance.
ID int `json:"id"`
// RSSI is the Strength of the signal in dBms from the latest packet
RSSI *float64 `json:"rssi,omitempty"`
// Battery is the battery level in percentage
Battery *float64 `json:"battery,omitempty"`
// PacketID is the ID of the latest received packet
PacketID *int `json:"packet_id,omitempty"`
// LastUpdateTS is the timestamp of the received packet.
LastUpdateTS int `json:"last_update_ts"`
// Errors describes component error conditions. May contain key_missing_or_bad, decrypt_failed,
// parse_failed and unencrypted_data.
Errors []string `json:"errors,omitempty"`
}
// BTHomeDeviceGetConfigRequest contains parameters for the BTHomeDevice.GetConfig RPC request.
type BTHomeDeviceGetConfigRequest struct {
// ID of the component instance.
ID int `json:"id"`
}
func (r *BTHomeDeviceGetConfigRequest) Method() string {
return "BTHomeDevice.GetConfig"
}
func (r *BTHomeDeviceGetConfigRequest) NewTypedResponse() *BTHomeDeviceConfig {
return &BTHomeDeviceConfig{}
}
func (r *BTHomeDeviceGetConfigRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeDeviceGetConfigRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*BTHomeDeviceConfig,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
// BTHomeDeviceSetConfigRequest contains parameters for the BTHomeDevice.SetConfig RPC request.
type BTHomeDeviceSetConfigRequest struct {
// ID of the component instance.
ID int `json:"id"`
// Config that the method takes.
Config BTHomeDeviceConfig `json:"config"`
}
func (r *BTHomeDeviceSetConfigRequest) Method() string {
return "BTHomeDevice.SetConfig"
}
func (r *BTHomeDeviceSetConfigRequest) NewTypedResponse() *SetConfigResponse {
return &SetConfigResponse{}
}
func (r *BTHomeDeviceSetConfigRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeDeviceSetConfigRequest) 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
}
// BTHomeDeviceGetStatusRequst contains parameters for the BTHomeDevice.GetStatus RPC request.
type BTHomeDeviceGetStatusRequest struct {
// ID of the component instance.
ID int `json:"id"`
}
func (r *BTHomeDeviceGetStatusRequest) Method() string {
return "BTHomeDevice.GetStatus"
}
func (r *BTHomeDeviceGetStatusRequest) NewTypedResponse() *BTHomeDeviceStatus {
return &BTHomeDeviceStatus{}
}
func (r *BTHomeDeviceGetStatusRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeDeviceGetStatusRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*BTHomeDeviceStatus,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
// BTHomeDeviceGetKnownObjectsRequst contains parameters for the BTHomeDevice.GetKnownObjects RPC request.
type BTHomeDeviceGetKnownObjectsRequest struct {
// ID of the component instance.
ID int `json:"id"`
}
func (r *BTHomeDeviceGetKnownObjectsRequest) Method() string {
return "BTHomeDevice.GetKnownObjects"
}
func (r *BTHomeDeviceGetKnownObjectsRequest) NewTypedResponse() *BTHomeDeviceGetKnownObjectsResponse {
return &BTHomeDeviceGetKnownObjectsResponse{}
}
func (r *BTHomeDeviceGetKnownObjectsRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *BTHomeDeviceGetKnownObjectsRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*BTHomeDeviceGetKnownObjectsResponse,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
type BTHomeDeviceGetKnownObjectsResponse struct {
// ID of the component instance.
ID int `json:"id"`
// Objects is a list of known objects
Objects []BTHomeDeviceKnownObject `json:"objects"`
}
type BTHomeDeviceKnownObject struct {
// 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"`
// Component key if the sensor is managed, otherwise nil.
Component *string `json:"component,omitempty"`
}