From d84cee40f8df20feb146386bde03062d69544233 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 15 Oct 2018 09:45:29 +0200 Subject: [PATCH 1/2] .travis.yml: Use golint's preferred import path. Previously, tests failed with: $ go get github.com/golang/lint/golint package github.com/golang/lint/golint: code in directory /home/travis/gopath/src/github.com/golang/lint/golint expects import "golang.org/x/lint/golint" --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7c6bd11..d489bf8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ before_install: - go get github.com/axw/gocov/gocov - go get github.com/mattn/goveralls - go get golang.org/x/tools/cmd/cover - - go get github.com/golang/lint/golint + - go get golang.org/x/lint/golint before_script: - go get -d ./... script: From 9d3de47072ae5157bb0b81b86720d2ab9e3a401b Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 15 Oct 2018 08:52:23 +0200 Subject: [PATCH 2/2] Package unifi: Implement Device.String(). Behaves like the Unifi UI, i.e. returns the device's name if set and the serial otherwise. If the serial has exactly 12 characters, it is formatted like a MAC address, again like the UI does. --- devices.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/devices.go b/devices.go index 7a952ec..21e1805 100644 --- a/devices.go +++ b/devices.go @@ -5,6 +5,7 @@ import ( "fmt" "net" "net/url" + "strings" "time" ) @@ -224,6 +225,20 @@ func (d *Device) UnmarshalJSON(b []byte) error { return nil } +func (d Device) String() string { + if d.Name != "" { + return d.Name + } + if d.Serial != "" { + if len(d.Serial) != 12 { + return d.Serial + } + s := strings.ToLower(d.Serial) + return strings.Join([]string{s[0:2], s[2:4], s[4:6], s[6:8], s[8:10], s[10:12]}, ":") + } + return d.ID +} + // A device is the raw structure of a Device returned from the UniFi Controller // API. type device struct {