diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17cef03..65bdd03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,10 +10,10 @@ jobs: test: strategy: matrix: - go-version: [1.16.x, 1.17.x, tip] + go-version: [1.21.x, 1.22.x, tip] full-tests: [false] include: - - go-version: 1.18.x + - go-version: 1.23.x full-tests: true runs-on: ubuntu-latest @@ -21,7 +21,7 @@ jobs: steps: - name: Setup go run: | - curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.3/install-go.pl | + curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.6/install-go.pl | perl - ${{ matrix.go-version }} $HOME/go - name: Checkout code uses: actions/checkout@v2 @@ -30,14 +30,13 @@ jobs: if: matrix.full-tests run: | curl -sL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | - sh -s -- -b $HOME/go/bin v1.46.2 + sh -s -- -b $HOME/go/bin v1.61.0 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 \ @@ -54,7 +53,7 @@ jobs: if [ ${{ matrix.full-tests }} = true ]; then GO_TEST_FLAGS="-covermode=atomic -coverprofile=coverage.out" fi - go test $GO_TEST_FLAGS ./... + go test $GO_TEST_FLAGS . - name: Reporting if: matrix.full-tests env: diff --git a/cmd/vitotrol/actions.go b/cmd/vitotrol/actions.go index 58295fb..0613f31 100644 --- a/cmd/vitotrol/actions.go +++ b/cmd/vitotrol/actions.go @@ -4,7 +4,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "os" "strconv" "strings" @@ -239,7 +239,7 @@ type devicesAction struct { authAction } -func (a *devicesAction) Do(pOptions *Options, params []string) error { +func (a *devicesAction) Do(pOptions *Options, _ []string) error { err := a.initVitotrol(pOptions) if err != nil { return err @@ -267,7 +267,7 @@ func (a *listAction) NeedAuth() bool { return false } -func (a *listAction) Do(pOptions *Options, params []string) error { +func (a *listAction) Do(_ *Options, params []string) error { if len(params) == 0 || params[0] == "attrs" { for _, pAttrRef := range vitotrol.AttributesRef { fmt.Println(pAttrRef) @@ -419,7 +419,7 @@ type errorsAction struct { authAction } -func (a *errorsAction) Do(pOptions *Options, params []string) error { +func (a *errorsAction) Do(pOptions *Options, _ []string) error { err := a.initVitotrol(pOptions) if err != nil { return err @@ -465,7 +465,7 @@ func (a *setTimesheetAction) Do(pOptions *Options, params []string) error { tss := make(map[string]vitotrol.TimeslotSlice) var data []byte if strings.HasPrefix(params[1], "@") && len(params[1]) > 1 { - data, err = ioutil.ReadFile(params[1][1:]) + data, err = os.ReadFile(params[1][1:]) if err != nil { return fmt.Errorf("Cannot read file %s: %s", params[1][1:], err) } @@ -548,7 +548,7 @@ type remoteAttrsAction struct { authAction } -func (a *remoteAttrsAction) Do(pOptions *Options, params []string) error { +func (a *remoteAttrsAction) Do(pOptions *Options, _ []string) error { err := a.initVitotrol(pOptions) if err != nil { return err diff --git a/go.mod b/go.mod index 2cce2d3..24de260 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.11.0 +require github.com/maxatome/go-testdeep v1.14.0 require github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index c446431..1979d1d 100644 --- a/go.sum +++ b/go.sum @@ -1,23 +1,4 @@ -github.com/davecgh/go-spew v0.0.0-20180221232628-8991bc29aa16 h1:HqkufMBR7waVfFFRABWqHa1WgTvjtVDJTLJe3CR576A= -github.com/davecgh/go-spew v0.0.0-20180221232628-8991bc29aa16/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/maxatome/go-testdeep v1.0.3 h1:xTds+j0BxPnSJbBEc3jqj8M6mUcffoIGbXCUgCs7Ybc= -github.com/maxatome/go-testdeep v1.0.3/go.mod h1:n887vr2m8DvuP4YfGAZBug2HhsEiVOC+RMvCDxo70X4= -github.com/maxatome/go-testdeep v1.0.4 h1:Oq/Hr9suAUJ3p11Xr2bcpN4Urlv1ZgJ8FysHGQvYTNo= -github.com/maxatome/go-testdeep v1.0.4/go.mod h1:n887vr2m8DvuP4YfGAZBug2HhsEiVOC+RMvCDxo70X4= -github.com/maxatome/go-testdeep v1.0.5/go.mod h1:n887vr2m8DvuP4YfGAZBug2HhsEiVOC+RMvCDxo70X4= -github.com/maxatome/go-testdeep v1.3.0 h1:r66U/hnWMFYAEwbHeZvJWmTGfXddhZ8TzHSzi2kMFJo= -github.com/maxatome/go-testdeep v1.3.0/go.mod h1:011SgQ6efzZYAen6fDn4BqQ+lUR72ysdyKe7Dyogw70= -github.com/maxatome/go-testdeep v1.4.0 h1:vKQh3/lHKAMsxggya/fXB6fLbf70c7k6wlLveuS9sKE= -github.com/maxatome/go-testdeep v1.4.0/go.mod h1:011SgQ6efzZYAen6fDn4BqQ+lUR72ysdyKe7Dyogw70= -github.com/maxatome/go-testdeep v1.7.0 h1:FdH/t2zHa+I43pKIjeUAwfUPoSADSkX0NwY6nvvxT7o= -github.com/maxatome/go-testdeep v1.7.0/go.mod h1:011SgQ6efzZYAen6fDn4BqQ+lUR72ysdyKe7Dyogw70= -github.com/maxatome/go-testdeep v1.8.0 h1:7QpuvRvyCUefU41jbEU1+k8N4DhuE6jbu/CvFeUUOhU= -github.com/maxatome/go-testdeep v1.8.0/go.mod h1:011SgQ6efzZYAen6fDn4BqQ+lUR72ysdyKe7Dyogw70= -github.com/maxatome/go-testdeep v1.9.2 h1:5D7u/JkeG0A/HDTbZ/CFFmpYZPeWN+uGQ1IbsEHYlCo= -github.com/maxatome/go-testdeep v1.9.2/go.mod h1:011SgQ6efzZYAen6fDn4BqQ+lUR72ysdyKe7Dyogw70= -github.com/maxatome/go-testdeep v1.10.0 h1:s1pP+gqiylIm2Fqhscvec1bnvGmCLayVQW8iFkGNGKw= -github.com/maxatome/go-testdeep v1.10.0/go.mod h1:011SgQ6efzZYAen6fDn4BqQ+lUR72ysdyKe7Dyogw70= -github.com/maxatome/go-testdeep v1.11.0 h1:Tgh5efyCYyJFGUYiT0qxBSIDeXw0F5zSoatlou685kk= -github.com/maxatome/go-testdeep v1.11.0/go.mod h1:011SgQ6efzZYAen6fDn4BqQ+lUR72ysdyKe7Dyogw70= +github.com/maxatome/go-testdeep v1.14.0 h1:rRlLv1+kI8eOI3OaBXZwb3O7xY3exRzdW5QyX48g9wI= +github.com/maxatome/go-testdeep v1.14.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM= diff --git a/time.go b/time.go index d1327ba..2a70b98 100644 --- a/time.go +++ b/time.go @@ -25,7 +25,9 @@ func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { } // String returns the time formatted using the format string +// // 2006-01-02 15:04:05 +// // considered as being a localtime value. func (t Time) String() string { return time.Time(t).Format(vitodataTimeFormat) diff --git a/types.go b/types.go index 192c16b..2343f85 100644 --- a/types.go +++ b/types.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "strconv" + "strings" ) // Singletons matching Vitodataâ„¢ types. @@ -56,19 +57,23 @@ func (v *VitodataDouble) Human2VitodataValue(value string) (string, error) { if err != nil { return "", err } - return strconv.FormatFloat(num, 'f', -1, 64), nil + return strings.Replace(strconv.FormatFloat(num, 'f', -1, 64), ".", ",", 1), nil } // Vitodata2HumanValue checks that the value is a float number and // returns it after reformatting. func (v *VitodataDouble) Vitodata2HumanValue(value string) (string, error) { - return v.Human2VitodataValue(value) + num, err := strconv.ParseFloat(strings.Replace(value, ",", ".", 1), 64) + if err != nil { + return "", err + } + return strconv.FormatFloat(num, 'f', -1, 64), nil } // Vitodata2NativeValue extract the number from the passed string and // returns it as a float64. func (v *VitodataDouble) Vitodata2NativeValue(value string) (interface{}, error) { - num, err := strconv.ParseFloat(value, 64) + num, err := strconv.ParseFloat(strings.Replace(value, ",", ".", 1), 64) if err != nil { return nil, err } diff --git a/types_test.go b/types_test.go index cac1d4d..a1a7766 100644 --- a/types_test.go +++ b/types_test.go @@ -14,7 +14,7 @@ func TestVitodataDouble(tt *testing.T) { // Human2VitodataValue str, err := TypeDouble.Human2VitodataValue("1.200") - t.CmpDeeply(str, "1.2") + t.CmpDeeply(str, "1,2") t.CmpNoError(err) str, err = TypeDouble.Human2VitodataValue("foo") @@ -26,6 +26,10 @@ func TestVitodataDouble(tt *testing.T) { t.CmpDeeply(str, "1.2") t.CmpNoError(err) + str, err = TypeDouble.Vitodata2HumanValue("1,200") + t.CmpDeeply(str, "1.2") + t.CmpNoError(err) + str, err = TypeDouble.Vitodata2HumanValue("foo") t.Empty(str) t.CmpError(err) @@ -35,6 +39,10 @@ func TestVitodataDouble(tt *testing.T) { t.CmpDeeply(num, float64(1.2)) t.CmpNoError(err) + num, err = TypeDouble.Vitodata2NativeValue("1,200") + t.CmpDeeply(num, float64(1.2)) + t.CmpNoError(err) + num, err = TypeDouble.Vitodata2NativeValue("foo") t.Nil(num) t.CmpError(err) diff --git a/vitotrol.go b/vitotrol.go index 4a4a1e4..48e8937 100644 --- a/vitotrol.go +++ b/vitotrol.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/xml" "fmt" - "io/ioutil" + "io" "log" "net/http" "sort" @@ -55,7 +55,7 @@ func (v *Session) sendRequest(soapAction string, reqBody string, respBody HasRes } defer resp.Body.Close() - respBodyRaw, _ := ioutil.ReadAll(resp.Body) + respBodyRaw, _ := io.ReadAll(resp.Body) if resp.StatusCode == 200 { cookies := resp.Header[http.CanonicalHeaderKey("Set-Cookie")] diff --git a/vitotrol_test.go b/vitotrol_test.go index 9d01d0e..5a74e82 100644 --- a/vitotrol_test.go +++ b/vitotrol_test.go @@ -3,7 +3,7 @@ package vitotrol import ( "encoding/xml" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "reflect" @@ -27,7 +27,7 @@ const ( func extractRequestBody(t *td.T, r *http.Request, reqBody interface{}, testName string) bool { t.Helper() - bodyRaw, err := ioutil.ReadAll(r.Body) + bodyRaw, err := io.ReadAll(r.Body) if !t.CmpNoError(err, "%s: request body ReadAll OK", testName) { return false } @@ -45,7 +45,8 @@ func virginInstance(pOrig interface{}) interface{} { func testSendRequestAny(t *td.T, sendReq func(v *Session) bool, soapAction string, expectedRequest interface{}, serverResponse string, - testName string) bool { + testName string, +) bool { t.Helper() ts := httptest.NewServer(http.HandlerFunc( @@ -113,7 +114,7 @@ func TestSendRequestErrors(tt *testing.T) { // HTTP status error ts := httptest.NewServer(http.HandlerFunc( - func(w http.ResponseWriter, r *http.Request) { + func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusInternalServerError) })) defer ts.Close() @@ -236,9 +237,7 @@ func TestSendRequest(tt *testing.T) { "sendRequest app error") } -// // Login. -// func TestLogin(tt *testing.T) { t := td.NewT(tt) @@ -294,9 +293,7 @@ func TestLogin(tt *testing.T) { "Login with error") } -// // GetDevices. -// func TestGetDevices(tt *testing.T) { t := td.NewT(tt)