Update devices

This commit is contained in:
appkins
2025-03-11 20:08:57 -05:00
parent b8cd78c83f
commit 39c704d3ec
3 changed files with 29 additions and 53 deletions

View File

@@ -104,6 +104,8 @@ type Device struct {
X float64 `json:"x,omitempty"` X float64 `json:"x,omitempty"`
XBaresipPassword string `json:"x_baresip_password,omitempty"` // ^[a-zA-Z0-9_.\-!~*'()]* XBaresipPassword string `json:"x_baresip_password,omitempty"` // ^[a-zA-Z0-9_.\-!~*'()]*
Y float64 `json:"y,omitempty"` Y float64 `json:"y,omitempty"`
PortTable []PortTable `json:"port_table,omitempty"`
} }
func (dst *Device) UnmarshalJSON(b []byte) error { func (dst *Device) UnmarshalJSON(b []byte) error {
@@ -310,6 +312,8 @@ type DevicePortOverrides struct {
StpPortMode bool `json:"stp_port_mode,omitempty"` StpPortMode bool `json:"stp_port_mode,omitempty"`
TaggedVLANMgmt string `json:"tagged_vlan_mgmt,omitempty"` // auto|block_all|custom TaggedVLANMgmt string `json:"tagged_vlan_mgmt,omitempty"` // auto|block_all|custom
VoiceNetworkID string `json:"voice_networkconf_id,omitempty"` VoiceNetworkID string `json:"voice_networkconf_id,omitempty"`
PortPoe *bool `json:"port_poe,omitempty"`
} }
func (dst *DevicePortOverrides) UnmarshalJSON(b []byte) error { func (dst *DevicePortOverrides) UnmarshalJSON(b []byte) error {

View File

@@ -23,6 +23,31 @@ const (
DeviceStateIsolated DeviceState = 11 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) { func (c *Client) ListDevice(ctx context.Context, site string) ([]Device, error) {
return c.listDevice(ctx, site) return c.listDevice(ctx, site)
} }

View File

@@ -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
}