From df937016b0056b2742ea4030f51e501ad3edc171 Mon Sep 17 00:00:00 2001
From: Ben Davies <ben.davies@ourscienceistight.com>
Date: Fri, 9 Oct 2020 15:27:46 +0100
Subject: [PATCH] Moved handling of string response to int using the existing
 emptyStringInt method as part of UnmarshalJSON as per Pauls suggestion

---
 fields/main.go        |  8 --------
 unifi/network.go      |  2 ++
 unifi/network_test.go | 13 +++++++++++++
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/fields/main.go b/fields/main.go
index 87da6ac..f02d4be 100644
--- a/fields/main.go
+++ b/fields/main.go
@@ -260,14 +260,6 @@ func main() {
 				f.OmitEmpty = true
 				return nil
 			}
-		case "NetworkConf":
-			resource.FieldProcessor = func(name string, f *FieldInfo) error {
-				switch name {
-				case "WANEgressQOS":
-					f.FieldType = "string"
-				}
-				return nil
-			}
 		case "SettingUsg":
 			resource.FieldProcessor = func(name string, f *FieldInfo) error {
 				if strings.HasSuffix(name, "Timeout") && name != "ArpCacheTimeout" {
diff --git a/unifi/network.go b/unifi/network.go
index f89d83b..8c99dae 100644
--- a/unifi/network.go
+++ b/unifi/network.go
@@ -11,6 +11,7 @@ func (dst *Network) UnmarshalJSON(b []byte) error {
 	aux := &struct {
 		VLAN           emptyStringInt `json:"vlan"`
 		DHCPDLeaseTime emptyStringInt `json:"dhcpd_leasetime"`
+		WANEgressQOS   emptyStringInt `json:"wan_egress_qos"`
 
 		*Alias
 	}{
@@ -24,6 +25,7 @@ func (dst *Network) UnmarshalJSON(b []byte) error {
 
 	dst.VLAN = int(aux.VLAN)
 	dst.DHCPDLeaseTime = int(aux.DHCPDLeaseTime)
+	dst.WANEgressQOS = int(aux.WANEgressQOS)
 
 	return nil
 }
diff --git a/unifi/network_test.go b/unifi/network_test.go
index f2fe8ae..588d219 100644
--- a/unifi/network_test.go
+++ b/unifi/network_test.go
@@ -38,6 +38,19 @@ func TestNetworkUnmarshalJSON(t *testing.T) {
 			expected: unifi.Network{DHCPDLeaseTime: 0},
 			json:     `{ "dhcpd_leasetime": "" }`,
 		},
+
+		"int wan_egress_qos": {
+			expected: unifi.Network{WANEgressQOS: 1},
+			json:     `{ "wan_egress_qos": 1 }`,
+		},
+		"string wan_egress_qos": {
+			expected: unifi.Network{WANEgressQOS: 1},
+			json:     `{ "wan_egress_qos": "1" }`,
+		},
+		"empty string wan_egress_qos": {
+			expected: unifi.Network{WANEgressQOS: 0},
+			json:     `{ "wan_egress_qos": "" }`,
+		},
 	} {
 		t.Run(n, func(t *testing.T) {
 			var actual unifi.Network