Skip to content

Commit

Permalink
chore: fix linter (evcc-io#11028)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Dec 6, 2023
1 parent 098a0fc commit 58e2421
Show file tree
Hide file tree
Showing 91 changed files with 374 additions and 280 deletions.
45 changes: 45 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,55 @@
run:
go: "1.21"

issues:
exclude:
- .regActualCurrent. is unused
- "`routeLogger` is unused"

linters-settings:
staticcheck:
checks:
- "-SA1019"

linters:
disable-all: true
enable:
- dogsled
- durationcheck
- exportloopref
- gci
- gofmt
- gofumpt
- goimports
- goprintffuncname
- govet
- importas
- ineffassign
- makezero
- misspell
- nolintlint
- rowserrcheck
- sqlclosecheck
- staticcheck
- tparallel
- typecheck
- unconvert
- unused
- wastedassign
- whitespace

# fixme
# - bodyclose
# - exhaustive
# - gocritic
# - godot
# - gomoddirectives
# - nakedret
# - nilerr
# - noctx
# - prealloc
# - predeclared
# - revive
# - stylecheck
# - unparam
# - dupl
2 changes: 1 addition & 1 deletion charger/alphatec.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func NewAlphatec(uri, device, comset string, baudrate int, proto modbus.Protocol

func (wb *Alphatec) setCurrent(current uint16) error {
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, uint16(current))
binary.BigEndian.PutUint16(b, current)

_, err := wb.conn.WriteMultipleRegisters(alphatecRegAmpsConfig, 1, b)

Expand Down
2 changes: 1 addition & 1 deletion charger/easee.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (c *Easee) ProductUpdate(i json.RawMessage) {
}

// OpMode changed FROM >1 ("car connected") TO 1/disconnected - stop ticker if channel exists
// channel may not exist regulary if the car was connected but charging never started
// channel may not exist regularly if the car was connected but charging never started
if c.opMode != easee.ModeDisconnected && opMode == easee.ModeDisconnected && c.stopTicker != nil {
close(c.stopTicker)
c.stopTicker = nil
Expand Down
4 changes: 2 additions & 2 deletions charger/easee/signalr.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const (
LOCAL_PRE_AUTHORIZE_ENABLED ObservationID = 15 // Preauthorize with whitelist enabled. Readback on setting [event] [Boolean]
LOCAL_AUTHORIZE_OFFLINE_ENABLED ObservationID = 16 // Allow offline charging for whitelisted RFID token. Readback on setting [event] [Boolean]
ALLOW_OFFLINE_TX_FOR_UNKNOWN_ID ObservationID = 17 // Allow offline charging for all RFID tokens. Readback on setting [event] [Boolean]
ERRATIC_EVMAX_TOGGLES ObservationID = 18 // 0 == erratic checking disabled, otherwise the number of toggles between states Charging and Charging Complate that will trigger an error [Integer]
ERRATIC_EVMAX_TOGGLES ObservationID = 18 // 0 == erratic checking disabled, otherwise the number of toggles between states Charging and Charging Complete that will trigger an error [Integer]
BACKPLATE_TYPE ObservationID = 19 // Readback on backplate type [Integer]
SITE_STRUCTURE ObservationID = 20 // Site Structure [boot] [String]
DETECTED_POWER_GRID_TYPE ObservationID = 21 // Detected power grid type according to PowerGridType table [boot] [Integer]
Expand All @@ -94,7 +94,7 @@ const (
FORCED_THREE_PHASE_ON_ITWITH_GND_FAULT ObservationID = 39 // Default disabled. Must be set manually if grid type is indeed three phase IT [Boolean]
LED_STRIP_BRIGHTNESS ObservationID = 40 // LED strip brightness, 0-100% [Integer]
LOCAL_AUTHORIZATION_REQUIRED ObservationID = 41 // Local RFID authorization is required for charging [user options] [event] [Boolean]
AUTHORIZATION_REQUIRED ObservationID = 42 // Authorization is requried for charging [Boolean]
AUTHORIZATION_REQUIRED ObservationID = 42 // Authorization is required for charging [Boolean]
REMOTE_START_REQUIRED ObservationID = 43 // Remote start required flag [event] [Boolean]
SMART_BUTTON_ENABLED ObservationID = 44 // Smart button is enabled [Boolean]
OFFLINE_CHARGING_MODE ObservationID = 45 // Charger behavior when offline [Integer]
Expand Down
2 changes: 0 additions & 2 deletions charger/fronius-wattpilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ func NewWattpilotFromConfig(other map[string]interface{}) (api.Charger, error) {
}

return NewWattpilot(cc.URI, cc.Password, cc.Cache)

}

// NewWattpilot creates Wattpilot charger
func NewWattpilot(uri, password string, cache time.Duration) (api.Charger, error) {

c := &Wattpilot{
api: wattpilot.New(uri, password),
}
Expand Down
2 changes: 1 addition & 1 deletion charger/go-e/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c *LocalAPI) upgradeV2() {
err := c.response("api/status?filter=alw", &res)

if err == nil {
c.uri = c.uri + "/api"
c.uri += "/api"
} else {
c.v2 = false
}
Expand Down
2 changes: 1 addition & 1 deletion charger/huawei-ac.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (wb *HuaweiACCharger) Status() (api.ChargeStatus, error) {
return api.StatusNone, err
}

//ToDo: Real status
// ToDo: Real status
switch u := binary.BigEndian.Uint16(b); u {
case 0:
return api.StatusA, nil
Expand Down
4 changes: 2 additions & 2 deletions charger/mcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (mcc *MobileConnect) fetchToken(request *http.Request) error {
}

// login as the home user with the given password
func (mcc *MobileConnect) login(password string) error {
func (mcc *MobileConnect) login() error {
uri := fmt.Sprintf("%s/%s", mcc.uri, mccAPILogin)

data := url.Values{
Expand Down Expand Up @@ -170,7 +170,7 @@ func (mcc *MobileConnect) request(method, uri string) (*http.Request, error) {

// do we need to login?
if mcc.token == "" {
if err := mcc.login(mcc.password); err != nil {
if err := mcc.login(); err != nil {
return nil, err
}
}
Expand Down
38 changes: 24 additions & 14 deletions charger/mcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type apiResponse struct {
// NewTestClient returns *http.Client with Transport replaced to avoid making real calls
func NewTestClient(fn roundTripFunc) *http.Client {
return &http.Client{
Transport: roundTripFunc(fn),
Transport: fn,
}
}

Expand All @@ -50,13 +50,13 @@ func NewTestMobileConnect(t *testing.T, responses []apiResponse) *MobileConnect
// response string for the currently invoked call
var responseString string
for _, s := range responses {
if strings.Contains("/"+string(s.apiCall), req.URL.Path) {
if strings.Contains("/"+s.apiCall, req.URL.Path) {
responseString = s.apiResponse
}
}

return &http.Response{
StatusCode: 200,
StatusCode: http.StatusOK,
// Send response to be tested
Body: io.NopCloser(bytes.NewBufferString(responseString)),
// Must be set to non-nil value or it panics
Expand All @@ -83,7 +83,7 @@ func TestMobileConnectLogin(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
mcc := NewTestMobileConnect(t, tc.responses)

if err := mcc.login(tc.password); (err != nil) != tc.wantErr {
if err := mcc.login(); (err != nil) != tc.wantErr {
t.Errorf("MobileConnect.login() error = %v, wantErr %v", err, tc.wantErr)
}
})
Expand Down Expand Up @@ -263,13 +263,15 @@ func TestMobileConnectCurrentPower(t *testing.T) {
"no data response",
[]apiResponse{
{mccAPIEnergy, "\"\"\n"},
}, 0, false,
},
0, false,
},
{
"home plug - error response",
[]apiResponse{
{mccAPIEnergy, "\"{\\n \\\"L1\\\": {\\n \\\"Ampere\\\": 0,\\n \\\"Power\\\": 0,\\n \\\"Volts\\\": 246.60000000000002\\n },\\n \\\"L2\\\": {\\n \\\"Ampere\\\": 0,\\n \\\"Power\\\": 0,\\n \\\"Volts\\\": 16.800000000000001\\n },\\n \\\"L3\\\": {\\n \\\"Ampere\\\": 0,\\n \\\"Power\\\": 0,\\n \\\"Volts\\\": 16.300000000000001\\n }\\n}\\n\""},
}, 0, false,
},
0, false,
},
}
for _, tc := range tests {
Expand Down Expand Up @@ -300,19 +302,22 @@ func TestMobileConnectChargedEnergy(t *testing.T) {
"valid response",
[]apiResponse{
{mccAPICurrentSession, "\"{\\n \\\"account\\\": \\\"PRIVATE\\\",\\n \\\"chargingRate\\\": 0,\\n \\\"chargingType\\\": \\\"AC\\\",\\n \\\"clockSrc\\\": \\\"NTP\\\",\\n \\\"costs\\\": 0,\\n \\\"currency\\\": \\\"\\\",\\n \\\"departTime\\\": \\\"\\\",\\n \\\"duration\\\": 30789,\\n \\\"endOfChargeTime\\\": \\\"\\\",\\n \\\"endSoc\\\": 0,\\n \\\"endTime\\\": \\\"\\\",\\n \\\"energySumKwh\\\": 18.832000000000001,\\n \\\"evChargingRatekW\\\": 0,\\n \\\"evTargetSoc\\\": -1,\\n \\\"evVasAvailability\\\": false,\\n \\\"pcid\\\": \\\"\\\",\\n \\\"powerRange\\\": 0,\\n \\\"selfEnergy\\\": 0,\\n \\\"sessionId\\\": 13,\\n \\\"soc\\\": -1,\\n \\\"solarEnergyShare\\\": 0,\\n \\\"startSoc\\\": 0,\\n \\\"startTime\\\": \\\"2020-04-15T10:07:22+02:00\\\",\\n \\\"totalRange\\\": 0,\\n \\\"vehicleBrand\\\": \\\"\\\",\\n \\\"vehicleModel\\\": \\\"\\\",\\n \\\"whitelist\\\": false\\n}\\n\""},
}, 18.832000000000001, false,
},
18.832000000000001, false,
},
{
"no data response",
[]apiResponse{
{mccAPICurrentSession, "\"\"\n"},
}, 0, false,
},
0, false,
},
{
"error response",
[]apiResponse{
{mccAPICurrentSession, "invalidjson"},
}, 0, true,
},
0, true,
},
}
for _, tc := range tests {
Expand Down Expand Up @@ -342,19 +347,22 @@ func TestMobileConnectChargingTime(t *testing.T) {
"valid response",
[]apiResponse{
{mccAPICurrentSession, "\"{\\n \\\"account\\\": \\\"PRIVATE\\\",\\n \\\"chargingRate\\\": 0,\\n \\\"chargingType\\\": \\\"AC\\\",\\n \\\"clockSrc\\\": \\\"NTP\\\",\\n \\\"costs\\\": 0,\\n \\\"currency\\\": \\\"\\\",\\n \\\"departTime\\\": \\\"\\\",\\n \\\"duration\\\": 30789,\\n \\\"endOfChargeTime\\\": \\\"\\\",\\n \\\"endSoc\\\": 0,\\n \\\"endTime\\\": \\\"\\\",\\n \\\"energySumKwh\\\": 18.832000000000001,\\n \\\"evChargingRatekW\\\": 0,\\n \\\"evTargetSoc\\\": -1,\\n \\\"evVasAvailability\\\": false,\\n \\\"pcid\\\": \\\"\\\",\\n \\\"powerRange\\\": 0,\\n \\\"selfEnergy\\\": 0,\\n \\\"sessionId\\\": 13,\\n \\\"soc\\\": -1,\\n \\\"solarEnergyShare\\\": 0,\\n \\\"startSoc\\\": 0,\\n \\\"startTime\\\": \\\"2020-04-15T10:07:22+02:00\\\",\\n \\\"totalRange\\\": 0,\\n \\\"vehicleBrand\\\": \\\"\\\",\\n \\\"vehicleModel\\\": \\\"\\\",\\n \\\"whitelist\\\": false\\n}\\n\""},
}, 30789 * time.Second, false,
},
30789 * time.Second, false,
},
{
"no data response",
[]apiResponse{
{mccAPICurrentSession, "\"\"\n"},
}, 0, false,
},
0, false,
},
{
"error response",
[]apiResponse{
{mccAPICurrentSession, "invalidjson"},
}, 0, true,
},
0, true,
},
}
for _, tc := range tests {
Expand Down Expand Up @@ -399,13 +407,15 @@ func TestMobileConnectCurrents(t *testing.T) {
"no data response",
[]apiResponse{
{mccAPIEnergy, "\"\"\n"},
}, 0, 0, 0, false,
},
0, 0, 0, false,
},
{
"home plug - error response",
[]apiResponse{
{mccAPIEnergy, "\"{\\n \\\"L1\\\": {\\n \\\"Ampere\\\": 0,\\n \\\"Power\\\": 0,\\n \\\"Volts\\\": 246.60000000000002\\n },\\n \\\"L2\\\": {\\n \\\"Ampere\\\": 0,\\n \\\"Power\\\": 0,\\n \\\"Volts\\\": 16.800000000000001\\n },\\n \\\"L3\\\": {\\n \\\"Ampere\\\": 0,\\n \\\"Power\\\": 0,\\n \\\"Volts\\\": 16.300000000000001\\n }\\n}\\n\""},
}, 0, 0, 0, false,
},
0, 0, 0, false,
},
}
for _, tc := range tests {
Expand Down
10 changes: 5 additions & 5 deletions charger/ocpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ func (suite *ocppTestSuite) TestConnect() {

// status
_, err = c1.Status()
suite.NoError(err)
suite.Require().NoError(err)

// power
f, err := c1.currentPower()
suite.NoError(err)
suite.Require().NoError(err)
suite.Equal(1e3, f)

// energy
f, err = c1.totalEnergy()
suite.NoError(err)
suite.Require().NoError(err)
suite.Equal(1.2, f)
}

Expand Down Expand Up @@ -148,7 +148,7 @@ func (suite *ocppTestSuite) TestConnect() {

res, err := cp1.StopTransaction(0, types.NewDateTime(suite.clock.Now()), expectedTxn)
suite.Require().NoError(err)
suite.Equal(res.IdTagInfo.Status, types.AuthorizationStatusAccepted)
suite.Equal(types.AuthorizationStatusAccepted, res.IdTagInfo.Status)
}

// 2nd charge point - remote
Expand All @@ -166,7 +166,7 @@ func (suite *ocppTestSuite) TestConnect() {

// status
_, err = c2.Status()
suite.NoError(err)
suite.Require().NoError(err)
}

// error on unconfigured 2nd charge point
Expand Down
5 changes: 3 additions & 2 deletions charger/pantabox.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package charger

import (
"fmt"
"strconv"
"strings"

"github.com/evcc-io/evcc/api"
Expand Down Expand Up @@ -69,7 +70,7 @@ func (wb *Pantabox) Enabled() (bool, error) {

// Enable implements the api.Charger interface
func (wb *Pantabox) Enable(enable bool) error {
resp, err := wb.Post(wb.uri+"/charger/enable", request.PlainContent, strings.NewReader(fmt.Sprintf("%t", enable)))
resp, err := wb.Post(wb.uri+"/charger/enable", request.PlainContent, strings.NewReader(strconv.FormatBool(enable)))
if err == nil {
defer resp.Body.Close()

Expand All @@ -83,7 +84,7 @@ func (wb *Pantabox) Enable(enable bool) error {

// MaxCurrent implements the api.Charger interface
func (wb *Pantabox) MaxCurrent(current int64) error {
resp, err := wb.Post(wb.uri+"/charger/current", request.PlainContent, strings.NewReader(fmt.Sprintf("%d", current)))
resp, err := wb.Post(wb.uri+"/charger/current", request.PlainContent, strings.NewReader(strconv.FormatInt(current, 10)))
if err == nil {
defer resp.Body.Close()

Expand Down
2 changes: 1 addition & 1 deletion charger/smaevcharger/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type SendParameter struct {
Values []Value `json:"values"`
}

// part of Paramter Send structure
// part of Parameter Send structure
type Value struct {
Timestamp string `json:"timestamp"`
ChannelId string `json:"channelId"`
Expand Down
1 change: 1 addition & 0 deletions charger/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var acceptable = []string{

func TestTemplates(t *testing.T) {
templates.TestClass(t, templates.Charger, func(t *testing.T, values map[string]any) {
t.Helper()
if _, err := NewFromConfig("template", values); err != nil && !test.Acceptable(err, acceptable) {
t.Log(values)
t.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion charger/twc3.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Vitals struct {
SessionEnergyWh float64 `json:"session_energy_wh"` // 22864.699
ConfigStatus int `json:"config_status"` // 5
EvseState int `json:"evse_state"` // 1
CurrentAlerts []any `json:"current_alerts"` //[]
CurrentAlerts []any `json:"current_alerts"` // []
}

// NewTwc3FromConfig creates a new vehicle
Expand Down
1 change: 0 additions & 1 deletion cmd/configure/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func (c *CmdConfigure) configureLinkedTemplate(templateItem templates.Template,
if c.askConfigFailureNextStep() {
continue
}

} else {
c.configuration.AddDevice(deviceItem, category)
c.processDeviceCapabilities(templateItem.Capabilities)
Expand Down
Loading

0 comments on commit 58e2421

Please sign in to comment.