Expose Device API
This commit is contained in:
committed by
Paul Tyng
parent
14e88eece9
commit
e93f92a066
@@ -138,7 +138,7 @@ func NewResource(structName string, resourcePath string) *Resource {
|
||||
}
|
||||
|
||||
if resource.StructName == "Device" {
|
||||
baseType.Fields[" MAC"] = NewFieldInfo("MAC", "mac", "string", "", false, false)
|
||||
baseType.Fields[" MAC"] = NewFieldInfo("MAC", "mac", "string", "", true, false)
|
||||
}
|
||||
|
||||
if resource.StructName == "User" {
|
||||
|
||||
@@ -23,7 +23,7 @@ type Device struct {
|
||||
NoDelete bool `json:"attr_no_delete,omitempty"`
|
||||
NoEdit bool `json:"attr_no_edit,omitempty"`
|
||||
|
||||
MAC string `json:"mac"`
|
||||
MAC string `json:"mac,omitempty"`
|
||||
|
||||
AtfEnabled bool `json:"atf_enabled,omitempty"`
|
||||
BandsteeringMode string `json:"bandsteering_mode,omitempty"` // off|equal|prefer_5g
|
||||
|
||||
41
unifi/device.go
Normal file
41
unifi/device.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package unifi
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
func (c *Client) ListDevice(ctx context.Context, site string) ([]Device, error) {
|
||||
return c.listDevice(ctx, site)
|
||||
}
|
||||
|
||||
func (c *Client) GetDevice(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) GetDeviceById(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, &NotFoundError{}
|
||||
}
|
||||
Reference in New Issue
Block a user