From 39c704d3ec96bb3e961b8a6916002efe3489f96a Mon Sep 17 00:00:00 2001 From: appkins Date: Tue, 11 Mar 2025 20:08:57 -0500 Subject: [PATCH] Update devices --- unifi/device.generated.go | 4 +++ unifi/device.go | 25 ++++++++++++++++++ unifi/device_v2.go | 53 --------------------------------------- 3 files changed, 29 insertions(+), 53 deletions(-) delete mode 100644 unifi/device_v2.go diff --git a/unifi/device.generated.go b/unifi/device.generated.go index 41aea12..c17d2ec 100644 --- a/unifi/device.generated.go +++ b/unifi/device.generated.go @@ -104,6 +104,8 @@ type Device struct { X float64 `json:"x,omitempty"` XBaresipPassword string `json:"x_baresip_password,omitempty"` // ^[a-zA-Z0-9_.\-!~*'()]* Y float64 `json:"y,omitempty"` + + PortTable []PortTable `json:"port_table,omitempty"` } func (dst *Device) UnmarshalJSON(b []byte) error { @@ -310,6 +312,8 @@ type DevicePortOverrides struct { StpPortMode bool `json:"stp_port_mode,omitempty"` TaggedVLANMgmt string `json:"tagged_vlan_mgmt,omitempty"` // auto|block_all|custom VoiceNetworkID string `json:"voice_networkconf_id,omitempty"` + + PortPoe *bool `json:"port_poe,omitempty"` } func (dst *DevicePortOverrides) UnmarshalJSON(b []byte) error { diff --git a/unifi/device.go b/unifi/device.go index d3ecfa6..07251ec 100644 --- a/unifi/device.go +++ b/unifi/device.go @@ -23,6 +23,31 @@ const ( DeviceStateIsolated DeviceState = 11 ) +type LastConnection struct { + Mac string `json:"mac,omitempty"` + LastSeen int `json:"last_seen,omitempty"` +} +type PortTable struct { + PortIdx int `json:"port_idx,omitempty"` + Media string `json:"media,omitempty"` + PortPoe bool `json:"port_poe,omitempty"` + PoeCaps int `json:"poe_caps,omitempty"` + SpeedCaps int `json:"speed_caps,omitempty"` + LastConnection LastConnection `json:"last_connection,omitempty"` + OpMode string `json:"op_mode,omitempty"` + Forward string `json:"forward,omitempty"` + PoeMode string `json:"poe_mode,omitempty"` + FullDuplex bool `json:"full_duplex,omitempty"` + IsUplink bool `json:"is_uplink,omitempty"` + MacTableCount int `json:"mac_table_count,omitempty"` + PoeClass string `json:"poe_class,omitempty"` + PoeCurrent string `json:"poe_current,omitempty"` + PoeEnable bool `json:"poe_enable,omitempty"` + PoeGood bool `json:"poe_good,omitempty"` + PoePower string `json:"poe_power,omitempty"` + PoeVoltage string `json:"poe_voltage,omitempty"` +} + func (c *Client) ListDevice(ctx context.Context, site string) ([]Device, error) { return c.listDevice(ctx, site) } diff --git a/unifi/device_v2.go b/unifi/device_v2.go deleted file mode 100644 index a300ca3..0000000 --- a/unifi/device_v2.go +++ /dev/null @@ -1,53 +0,0 @@ -package unifi - -import ( - "context" - "fmt" -) - -type LastConnection struct { - Mac string `json:"mac,omitempty"` - LastSeen int `json:"last_seen,omitempty"` -} -type PortTable struct { - PortIdx int `json:"port_idx,omitempty"` - Media string `json:"media,omitempty"` - PortPoe bool `json:"port_poe,omitempty"` - PoeCaps int `json:"poe_caps,omitempty"` - SpeedCaps int `json:"speed_caps,omitempty"` - LastConnection LastConnection `json:"last_connection,omitempty"` - OpMode string `json:"op_mode,omitempty"` - Forward string `json:"forward,omitempty"` - PoeMode string `json:"poe_mode,omitempty"` - FullDuplex bool `json:"full_duplex,omitempty"` - IsUplink bool `json:"is_uplink,omitempty"` - MacTableCount int `json:"mac_table_count,omitempty"` - PoeClass string `json:"poe_class,omitempty"` - PoeCurrent string `json:"poe_current,omitempty"` - PoeEnable bool `json:"poe_enable,omitempty"` - PoeGood bool `json:"poe_good,omitempty"` - PoePower string `json:"poe_power,omitempty"` - PoeVoltage string `json:"poe_voltage,omitempty"` -} -type DeviceV2 struct { - PortTable []PortTable `json:"port_table,omitempty"` -} - -func (c *Client) GetDeviceByMACv2(ctx context.Context, site, mac string) (*DeviceV2, error) { - var respBody struct { - Meta meta `json:"meta"` - Data []DeviceV2 `json:"data"` - } - - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/stat/device/%s", site, mac), nil, &respBody) - if err != nil { - return nil, err - } - - if len(respBody.Data) != 1 { - return nil, &NotFoundError{} - } - - d := respBody.Data[0] - return &d, nil -}