-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpacket.go
50 lines (42 loc) · 1.04 KB
/
packet.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
package bthome
import "fmt"
type Packet struct {
Encrypted bool
Trigger Trigger
BTHomeVersion uint8
ID uint8
FirmwareVersion *string
DeviceTypeID *int16
Battery []uint8
Humidity []uint8
Temperature []float32
Raw [][]byte
Button []Button
}
func (p Packet) String() string {
s := "BTHomePacket{"
s += fmt.Sprintf("Encrypted: %t, Trigger: %s, BTHomeVersion: %d, ID: %d", p.Encrypted, p.Trigger, p.BTHomeVersion, p.ID)
if p.FirmwareVersion != nil {
s += fmt.Sprintf(", FirmwareVersion: %s", *p.FirmwareVersion)
}
if p.DeviceTypeID != nil {
s += fmt.Sprintf(", DeviceTypeID: %d", *p.DeviceTypeID)
}
if len(p.Battery) > 0 {
s += fmt.Sprintf(", Battery: %d", p.Battery)
}
if len(p.Humidity) > 0 {
s += fmt.Sprintf(", Humidity: %d", p.Humidity)
}
if len(p.Temperature) > 0 {
s += fmt.Sprintf(", Temperature: %0.2f", p.Temperature)
}
if len(p.Raw) > 0 {
s += fmt.Sprintf(", Raw: %x", p.Raw)
}
if len(p.Button) > 0 {
s += fmt.Sprintf(", Button: %v", p.Button)
}
s += "}"
return s
}