package unifi import ( "context" "fmt" ) //go:generate go run golang.org/x/tools/cmd/stringer -trimprefix DeviceState -type DeviceState 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) { return c.listDevice(ctx, site) } func (c *client) GetDeviceByMAC(ctx context.Context, site, mac string) (*Device, error) { return c.getDevice(ctx, site, mac) } func (c *client) DeleteDevice(ctx context.Context, site, id string) error { return c.deleteDevice(ctx, site, id) } func (c *client) CreateDevice(ctx context.Context, site string, d *Device) (*Device, error) { return c.createDevice(ctx, site, d) } func (c *client) UpdateDevice(ctx context.Context, site string, d *Device) (*Device, error) { return c.updateDevice(ctx, site, d) } func (c *client) GetDevice(ctx context.Context, site, id string) (*Device, error) { devices, err := c.ListDevice(ctx, site) if err != nil { return nil, err } for _, d := range devices { if d.ID == id { return &d, nil } } return nil, ErrNotFound } 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.Post(ctx, 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.Post(ctx, fmt.Sprintf("s/%s/cmd/sitemgr", site), reqBody, &respBody) if err != nil { return err } return nil }