Add AdoptDevice and ForgetDevice methods (#45)
* Add `AdoptDevice` and `ForgetDevice` methods * Address comments
This commit is contained in:
@@ -2,6 +2,24 @@ package unifi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type DeviceState int
|
||||
|
||||
const (
|
||||
DeviceStateUnknown DeviceState = 0
|
||||
DeviceStateConnected DeviceState = 1
|
||||
DeviceStatePending DeviceState = 2
|
||||
DeviceStateFirmwareMismatch DeviceState = 3
|
||||
DeviceStateUpgrading DeviceState = 4
|
||||
DeviceStateProvisioning DeviceState = 5
|
||||
DeviceStateHeartbeatMissed DeviceState = 6
|
||||
DeviceStateAdopting DeviceState = 7
|
||||
DeviceStateDeleting DeviceState = 8
|
||||
DeviceStateInformError DeviceState = 9
|
||||
DeviceStateAdoptFailed DeviceState = 10
|
||||
DeviceStateIsolated DeviceState = 11
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
return nil, &NotFoundError{}
|
||||
}
|
||||
|
||||
func (c *Client) AdoptDevice(ctx context.Context, site, mac string) error {
|
||||
reqBody := struct {
|
||||
Cmd string `json:"cmd"`
|
||||
MAC string `json:"mac"`
|
||||
}{
|
||||
Cmd: "adopt",
|
||||
MAC: mac,
|
||||
}
|
||||
|
||||
var respBody struct {
|
||||
Meta meta `json:"meta"`
|
||||
}
|
||||
|
||||
err := c.do(ctx, "POST", fmt.Sprintf("s/%s/cmd/devmgr", site), reqBody, &respBody)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) ForgetDevice(ctx context.Context, site, mac string) error {
|
||||
reqBody := struct {
|
||||
Cmd string `json:"cmd"`
|
||||
MACs []string `json:"macs"`
|
||||
}{
|
||||
Cmd: "delete-device",
|
||||
MACs: []string{mac},
|
||||
}
|
||||
|
||||
var respBody struct {
|
||||
Meta meta `json:"meta"`
|
||||
Data []Device `json:"data"`
|
||||
}
|
||||
|
||||
err := c.do(ctx, "POST", fmt.Sprintf("s/%s/cmd/sitemgr", site), reqBody, &respBody)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user