From 2f7eee3a6aad03280f6565937a337fadecad08b1 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Wed, 16 Jun 2021 16:02:24 +1000 Subject: [PATCH] Add `dev_id_override` to user --- fields/main.go | 1 + unifi/user.generated.go | 21 +++++++++++---------- unifi/user.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/fields/main.go b/fields/main.go index 494849a..3d45ed1 100644 --- a/fields/main.go +++ b/fields/main.go @@ -146,6 +146,7 @@ func NewResource(structName string, resourcePath string) *Resource { baseType.Fields[" MAC"] = NewFieldInfo("MAC", "mac", "string", "", true, false) case resource.StructName == "User": baseType.Fields[" IP"] = NewFieldInfo("IP", "ip", "string", "non-generated field", true, false) + baseType.Fields[" DevIdOverride"] = NewFieldInfo("DevIdOverride", "dev_id_override", "int", "non-generated field", true, false) case resource.StructName == "WLAN": // this field removed in v6, retaining for backwards compatibility baseType.Fields["WLANGroupID"] = NewFieldInfo("WLANGroupID", "wlangroup_id", "string", "", false, false) diff --git a/unifi/user.generated.go b/unifi/user.generated.go index b119b48..911e9da 100644 --- a/unifi/user.generated.go +++ b/unifi/user.generated.go @@ -27,16 +27,17 @@ type User struct { IP string `json:"ip,omitempty"` // non-generated field - Blocked bool `json:"blocked,omitempty"` - FixedIP string `json:"fixed_ip,omitempty"` - Hostname string `json:"hostname,omitempty"` - LastSeen int `json:"last_seen,omitempty"` - MAC string `json:"mac,omitempty"` // ^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$ - Name string `json:"name,omitempty"` - NetworkID string `json:"network_id"` - Note string `json:"note,omitempty"` - UseFixedIP bool `json:"use_fixedip"` - UserGroupID string `json:"usergroup_id"` + Blocked bool `json:"blocked,omitempty"` + DevIdOverride int `json:"dev_id_override,omitempty"` // non-generated field + FixedIP string `json:"fixed_ip,omitempty"` + Hostname string `json:"hostname,omitempty"` + LastSeen int `json:"last_seen,omitempty"` + MAC string `json:"mac,omitempty"` // ^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$ + Name string `json:"name,omitempty"` + NetworkID string `json:"network_id"` + Note string `json:"note,omitempty"` + UseFixedIP bool `json:"use_fixedip"` + UserGroupID string `json:"usergroup_id"` } func (dst *User) UnmarshalJSON(b []byte) error { diff --git a/unifi/user.go b/unifi/user.go index f240df2..970cef0 100644 --- a/unifi/user.go +++ b/unifi/user.go @@ -131,6 +131,34 @@ func (c *Client) DeleteUserByMAC(ctx context.Context, site, mac string) error { return nil } +func (c *Client) OverrideUserFingerprint(ctx context.Context, site, mac string, devIdOveride int) error { + reqBody := map[string]interface{}{ + "mac": mac, + "dev_id_override": devIdOveride, + "search_query": "", + } + + var reqMethod string + if devIdOveride == 0 { + reqMethod = "DELETE" + } else { + reqMethod = "PUT" + } + + var respBody struct { + Mac string `json:"mac"` + DevIdOverride int `json:"dev_id_override"` + SearchQuery string `json:"search_query"` + } + + err := c.do(ctx, reqMethod, fmt.Sprintf("%s/site/%s/station/%s/fingerprint_override", c.apiV2Path, site, mac), reqBody, &respBody) + if err != nil { + return err + } + + return nil +} + func (c *Client) ListUser(ctx context.Context, site string) ([]User, error) { return c.listUser(ctx, site) }