diff --git a/devices.go b/devices.go index f226f25..f35b3f6 100644 --- a/devices.go +++ b/devices.go @@ -26,6 +26,7 @@ func (u *Unifi) GetDevices(sites []*Site) (*Devices, error) { devices.USWs = append(devices.USWs, loopDevices.USWs...) devices.UDMs = append(devices.UDMs, loopDevices.UDMs...) devices.UXGs = append(devices.UXGs, loopDevices.UXGs...) + devices.PDUs = append(devices.PDUs, loopDevices.PDUs...) } return devices, nil @@ -129,17 +130,20 @@ func (u *Unifi) parseDevices(data []json.RawMessage, site *Site) *Devices { case "ugw", "usg": // in case they ever fix the name in the api. u.unmarshallUSG(site, r, devices) case "usw": - if strings.Contains(model, "PDU") { + if strings.Contains(strings.ToLower(model), "pdu") { + // this may actually happen, unifi APIs are all over the place u.unmarshallPDU(site, r, devices) } else { u.unmarshallUSW(site, r, devices) } + case "pdu": + u.unmarshallPDU(site, r, devices) case "udm": u.unmarshallUDM(site, r, devices) case "uxg": u.unmarshallUXG(site, r, devices) default: - u.ErrorLog("unknown asset type - %v - skipping", assetType) + u.ErrorLog("unknown asset type - %v - skipping: data=%+v", assetType, string(r)) } } diff --git a/mocks/mock_server.go b/mocks/mock_server.go index 1bffff2..708f6a9 100644 --- a/mocks/mock_server.go +++ b/mocks/mock_server.go @@ -154,8 +154,27 @@ func (m *MockHTTPTestServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { return case apiDevicePath.MatchString(p): device, err := m.mocked.GetDevices(nil) - // we need to wrap devices more so - devices := []*unifi.Devices{device} + // we need to change the format response for devices. + // it is an array of mixed types in a singular {"data": [...all]} + devices := make([]any, 0) + for _, d := range device.UAPs { + devices = append(devices, d) + } + for _, d := range device.UDMs { + devices = append(devices, d) + } + for _, d := range device.USGs { + devices = append(devices, d) + } + for _, d := range device.USWs { + devices = append(devices, d) + } + for _, d := range device.PDUs { + devices = append(devices, d) + } + for _, d := range device.UXGs { + devices = append(devices, d) + } respondResultOrErr(w, devices, err, true) return case apiLoginPath.MatchString(p): diff --git a/pdu.go b/pdu.go index e2e49c3..2bb28b3 100644 --- a/pdu.go +++ b/pdu.go @@ -97,7 +97,7 @@ type PDU struct { TotalMaxPower FlexInt `json:"total_max_power"` TwoPhaseAdopt FlexBool `json:"two_phase_adopt"` TxBytes FlexInt `json:"tx_bytes"` - Type string `json:"type"` + Type string `json:"type" fake:"{lexify:pdu}"` Unsupported FlexBool `json:"unsupported"` UnsupportedReason FlexInt `json:"unsupported_reason"` Upgradeable FlexBool `json:"upgradable"` diff --git a/uap.go b/uap.go index b195a0c..8141bb7 100644 --- a/uap.go +++ b/uap.go @@ -144,7 +144,7 @@ type UAP struct { TwoPhaseAdopt FlexBool `json:"two_phase_adopt,omitempty"` TxBytes FlexInt `json:"tx_bytes"` TxBytesD FlexInt `json:"tx_bytes-d"` - Type string `json:"type"` + Type string `json:"type" fake:"{lexify:uap}"` UUptime FlexInt `json:"_uptime"` Unsupported FlexBool `json:"unsupported"` UnsupportedReason FlexInt `json:"unsupported_reason"` diff --git a/udm.go b/udm.go index 4e8f932..8692908 100644 --- a/udm.go +++ b/udm.go @@ -139,7 +139,7 @@ type UDM struct { TwoPhaseAdopt FlexBool `json:"two_phase_adopt"` TxBytes FlexInt `json:"tx_bytes"` TxBytesD FlexInt `json:"tx_bytes-d"` - Type string `json:"type"` + Type string `json:"type" fake:"{lexify:udmp}"` UdapiCaps FlexInt `json:"udapi_caps"` UnifiCare struct { ActivationDismissed FlexBool `json:"activation_dismissed"` diff --git a/usg.go b/usg.go index 5486dcd..df28aeb 100644 --- a/usg.go +++ b/usg.go @@ -27,7 +27,7 @@ type USG struct { Serial string `json:"serial"` SiteID string `json:"site_id" fake:"{uuid}"` SiteName string `json:"-"` - Type string `json:"type"` + Type string `json:"type" fake:"{lexify:usg}"` UsgCaps FlexInt `json:"usg_caps"` Version string `json:"version" fake:"{appversion}"` RequiredVersion string `json:"required_version" fake:"{appversion}"` diff --git a/usw.go b/usw.go index 610b1b2..8b8a144 100644 --- a/usw.go +++ b/usw.go @@ -98,7 +98,7 @@ type USW struct { TotalMaxPower FlexInt `json:"total_max_power"` TwoPhaseAdopt FlexBool `json:"two_phase_adopt"` TxBytes FlexInt `json:"tx_bytes"` - Type string `json:"type"` + Type string `json:"type" fake:"{randomstring:[usg,pdu]}"` Unsupported FlexBool `json:"unsupported"` UnsupportedReason FlexInt `json:"unsupported_reason"` Upgradable FlexBool `json:"upgradable,omitempty"` diff --git a/uxg.go b/uxg.go index 01a3c31..51cf0b8 100644 --- a/uxg.go +++ b/uxg.go @@ -106,7 +106,7 @@ type UXG struct { Temperatures []Temperature `json:"temperatures"` TwoPhaseAdopt FlexBool `json:"two_phase_adopt"` TxBytes FlexInt `json:"tx_bytes"` - Type string `json:"type"` + Type string `json:"type" fake:"{lexify:uxg}"` UdapiCaps FlexInt `json:"udapi_caps"` UnderscoreUptime FlexInt `json:"_uptime"` Unsupported FlexBool `json:"unsupported"`