@@ -2,6 +2,24 @@ package unifi
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
6
+ )
7
+
8
+ type DeviceState int
9
+
10
+ const (
11
+ DeviceStateUnknown DeviceState = 0
12
+ DeviceStateConnected DeviceState = 1
13
+ DeviceStatePending DeviceState = 2
14
+ DeviceStateFirmwareMismatch DeviceState = 3
15
+ DeviceStateUpgrading DeviceState = 4
16
+ DeviceStateProvisioning DeviceState = 5
17
+ DeviceStateHeartbeatMissed DeviceState = 6
18
+ DeviceStateAdopting DeviceState = 7
19
+ DeviceStateDeleting DeviceState = 8
20
+ DeviceStateInformError DeviceState = 9
21
+ DeviceStateAdoptFailed DeviceState = 10
22
+ DeviceStateIsolated DeviceState = 11
5
23
)
6
24
7
25
func (c * Client ) ListDevice (ctx context.Context , site string ) ([]Device , error ) {
@@ -39,3 +57,46 @@ func (c *Client) GetDevice(ctx context.Context, site, id string) (*Device, error
39
57
40
58
return nil , & NotFoundError {}
41
59
}
60
+
61
+ func (c * Client ) AdoptDevice (ctx context.Context , site , mac string ) error {
62
+ reqBody := struct {
63
+ Cmd string `json:"cmd"`
64
+ MAC string `json:"mac"`
65
+ }{
66
+ Cmd : "adopt" ,
67
+ MAC : mac ,
68
+ }
69
+
70
+ var respBody struct {
71
+ Meta meta `json:"meta"`
72
+ }
73
+
74
+ err := c .do (ctx , "POST" , fmt .Sprintf ("s/%s/cmd/devmgr" , site ), reqBody , & respBody )
75
+ if err != nil {
76
+ return err
77
+ }
78
+
79
+ return nil
80
+ }
81
+
82
+ func (c * Client ) ForgetDevice (ctx context.Context , site , mac string ) error {
83
+ reqBody := struct {
84
+ Cmd string `json:"cmd"`
85
+ MACs []string `json:"macs"`
86
+ }{
87
+ Cmd : "delete-device" ,
88
+ MACs : []string {mac },
89
+ }
90
+
91
+ var respBody struct {
92
+ Meta meta `json:"meta"`
93
+ Data []Device `json:"data"`
94
+ }
95
+
96
+ err := c .do (ctx , "POST" , fmt .Sprintf ("s/%s/cmd/sitemgr" , site ), reqBody , & respBody )
97
+ if err != nil {
98
+ return err
99
+ }
100
+
101
+ return nil
102
+ }
0 commit comments