Skip to content

Commit

Permalink
chore: apply gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jul 12, 2022
1 parent 4afed29 commit 815cc58
Show file tree
Hide file tree
Showing 48 changed files with 99 additions and 83 deletions.
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ type VehicleRange interface {

// VehicleClimater provides climatisation data
type VehicleClimater interface {
Climater() (active bool, outsideTemp float64, targetTemp float64, err error)
Climater() (active bool, outsideTemp, targetTemp float64, err error)
}

// VehicleOdometer returns the vehicles milage
Expand Down
4 changes: 2 additions & 2 deletions charger/abl.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ func (wb *ABLeMH) set(reg, val uint16) error {
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, val)

//write two times
// write two times
_, _ = wb.conn.WriteMultipleRegisters(reg, 1, b)
_, err := wb.conn.WriteMultipleRegisters(reg, 1, b)

return err
}

func (wb *ABLeMH) get(reg, count uint16) ([]byte, error) {
//read two times
// read two times
_, _ = wb.conn.ReadHoldingRegisters(reg, count)
b, err := wb.conn.ReadHoldingRegisters(reg, count)

Expand Down
2 changes: 1 addition & 1 deletion charger/daheimladen.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewDaheimLadenFromConfig(other map[string]interface{}) (api.Charger, error)
}

// NewDaheimLaden creates DaheimLaden charger
func NewDaheimLaden(token string, stationID string) (*DaheimLaden, error) {
func NewDaheimLaden(token, stationID string) (*DaheimLaden, error) {
c := &DaheimLaden{
Helper: request.NewHelper(util.NewLogger("daheim")),
stationID: stationID,
Expand Down
12 changes: 7 additions & 5 deletions charger/daheimladen/const.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package daheimladen

type ChargePointStatus string
type RemoteStartStatus string
type RemoteStopStatus string
type ConfigKey string
type ChangeConfigStatus string
type (
ChargePointStatus string
RemoteStartStatus string
RemoteStopStatus string
ConfigKey string
ChangeConfigStatus string
)

const BASE_URL string = "https://api.daheimladen.com/v1"

Expand Down
1 change: 0 additions & 1 deletion charger/eebus.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ func (c *EEBus) showCurrentChargingSetup() {
timestamp := time.Now()
c.log.WARN.Println("!! ", timestamp.Format("2006-01-02 15:04:05"), " ev-charger-self-consumption-support support changed from ", prevSelfConsumptionSupport, " to ", data.EVData.UCSelfConsumptionAvailable)
}

}

func (c *EEBus) dataUpdateHandler(dataType communication.EVDataElementUpdateType, data *communication.EVSEClientDataType) {
Expand Down
1 change: 1 addition & 0 deletions charger/go-e/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestLocalV1(t *testing.T) {
t.Error(err)
}
}

func TestLocalV2(t *testing.T) {
h := &handler{}
srv := httptest.NewServer(h)
Expand Down
2 changes: 1 addition & 1 deletion charger/hardybarth-salia.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (wb *Salia) Enabled() (bool, error) {

func (wb *Salia) pause(enable bool) {
// ignore error for FW <1.52
var offOn = map[bool]string{false: "1", true: "0"}
offOn := map[bool]string{false: "1", true: "0"}
_ = wb.post(salia.PauseCharging, offOn[enable])
}

Expand Down
3 changes: 1 addition & 2 deletions charger/mcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewMobileConnectFromConfig(other map[string]interface{}) (api.Charger, erro
}

// NewMobileConnect creates MCC charger
func NewMobileConnect(uri string, password string) (*MobileConnect, error) {
func NewMobileConnect(uri, password string) (*MobileConnect, error) {
log := util.NewLogger("mcc")

mcc := &MobileConnect{
Expand Down Expand Up @@ -153,7 +153,6 @@ func (mcc *MobileConnect) refresh() error {

// creates a http request that contains the auth token
func (mcc *MobileConnect) request(method, uri string) (*http.Request, error) {

// do we need a token refresh?
if mcc.token != "" {
// is it time to refresh the token?
Expand Down
2 changes: 1 addition & 1 deletion charger/nrgble_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func NewNRGKickBLE(device, mac string, pin int) (*NRGKickBLE, error) {
return nil, err
}

//Connect DBus System bus
// Connect DBus System bus
conn, err := dbus.SystemBus()
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion charger/ocpp/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ func detectSmartChargingCapabilities(options map[string]core.ConfigurationKey) (
}

return profile, nil

}

func parseIntOption(key SmartchargingChargeProfileKey, options map[string]core.ConfigurationKey) (int, error) {
Expand Down
1 change: 0 additions & 1 deletion charger/ocpp/cs_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func (cs *CS) OnFirmwareStatusNotification(chargePointId string, request *firmwa
}

return cp.FirmwareStatusNotification(request)

}

func (cs *CS) TriggerResetRequest(cp *CP, resetType core.ResetType) {
Expand Down
4 changes: 2 additions & 2 deletions charger/pcelectric.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (wb *PCElectric) Enabled() (bool, error) {
// Enable implements the api.Charger interface
func (wb *PCElectric) Enable(enable bool) error {
if wb.slaveIndex > 0 {
return nil //Slave wird immer mit dem Master geschaltet!
return nil // Slave wird immer mit dem Master geschaltet!
}

// Master Only !!
Expand Down Expand Up @@ -216,7 +216,7 @@ func (wb *PCElectric) MinCurrent(current int64) error {
// MaxCurrent implements the api.Charger interface
func (wb *PCElectric) MaxCurrent(current int64) error {
if wb.slaveIndex > 0 {
return nil //Slave wird immer mit dem Master geschaltet!
return nil // Slave wird immer mit dem Master geschaltet!
}

// Ohne Loadbalancer Regelung über currentlimit:
Expand Down
4 changes: 2 additions & 2 deletions charger/smaevcharger.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewSmaevchargerFromConfig(other map[string]interface{}) (api.Charger, error
}

// NewSmaevcharger creates an SMA EV Charger
func NewSmaevcharger(uri string, user string, password string, cache time.Duration) (api.Charger, error) {
func NewSmaevcharger(uri, user, password string, cache time.Duration) (api.Charger, error) {
log := util.NewLogger("smaevcharger").Redact(user, password)

wb := &Smaevcharger{
Expand Down Expand Up @@ -343,7 +343,7 @@ func (wb *Smaevcharger) Send(values ...smaevcharger.Value) error {
}

// value creates an smaevcharger.Value
func value(id string, value string) smaevcharger.Value {
func value(id, value string) smaevcharger.Value {
return smaevcharger.Value{
Timestamp: time.Now().UTC().Format(smaevcharger.TimestampFormat),
ChannelId: id,
Expand Down
20 changes: 13 additions & 7 deletions cmd/configure/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (c *CmdConfigure) processParamRequirements(param templates.Param) error {
return nil
}

func (c *CmdConfigure) askSponsortoken(required bool, feature bool) error {
func (c *CmdConfigure) askSponsortoken(required, feature bool) error {
fmt.Println("-- Sponsorship -----------------------------")
if required {
fmt.Println()
Expand All @@ -239,7 +239,8 @@ func (c *CmdConfigure) askSponsortoken(required bool, feature bool) error {
sponsortoken := c.askValue(question{
label: c.localizedString("Requirements_Sponsorship_Token_Input", nil),
mask: true,
required: true})
required: true,
})

err := sponsor.ConfigureSponsorship(sponsortoken)
if err != nil {
Expand Down Expand Up @@ -273,22 +274,26 @@ func (c *CmdConfigure) configureMQTT(templateItem templates.Template) (map[strin
host := c.askValue(question{
label: paramHost.Description.String(c.lang),
mask: false,
required: true})
required: true,
})

port := c.askValue(question{
label: paramPort.Description.String(c.lang),
mask: false,
required: true})
required: true,
})

user := c.askValue(question{
label: paramUser.Description.String(c.lang),
mask: false,
required: false})
required: false,
})

password := c.askValue(question{
label: paramPassword.Description.String(c.lang),
mask: true,
required: false})
required: false,
})

fmt.Println()
fmt.Println("--------------------------------------------")
Expand Down Expand Up @@ -532,7 +537,8 @@ func (c *CmdConfigure) processInputConfig(param templates.Param) string {
valueType: param.ValueType,
validValues: param.ValidValues,
mask: param.Mask,
required: param.Required})
required: param.Required,
})

if param.ValueType == templates.ParamValueTypeBool && value == "true" {
if err := c.processParamRequirements(param); err != nil {
Expand Down
22 changes: 14 additions & 8 deletions cmd/configure/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (c *CmdConfigure) flowNewConfigFile() {
filename := DefaultConfigFilename

for ok := true; ok; {
file, err := os.OpenFile(filename, os.O_WRONLY, 0666)
file, err := os.OpenFile(filename, os.O_WRONLY, 0o666)
if errors.Is(err, os.ErrNotExist) {
break
}
Expand All @@ -196,10 +196,11 @@ func (c *CmdConfigure) flowNewConfigFile() {
filename = c.askValue(question{
label: c.localizedString("File_NewFilename", nil),
exampleValue: "evcc_neu.yaml",
required: true})
required: true,
})
}

err = os.WriteFile(filename, yaml, 0755)
err = os.WriteFile(filename, yaml, 0o755)
if err != nil {
fmt.Printf("%s: ", c.localizedString("File_Error_SaveFailed", localizeMap{"FileName": filename}))
c.log.FATAL.Fatal(err)
Expand Down Expand Up @@ -283,7 +284,8 @@ func (c *CmdConfigure) configureLoadpoints() {
loadpointTitle := c.askValue(question{
label: c.localizedString("Loadpoint_Title", nil),
defaultValue: c.localizedString("Loadpoint_DefaultTitle", nil),
required: true})
required: true,
})
loadpoint := loadpoint{
Title: loadpointTitle,
Phases: 3,
Expand Down Expand Up @@ -330,14 +332,16 @@ func (c *CmdConfigure) configureLoadpoints() {
valueType: templates.ParamValueTypeNumber,
minNumberValue: int64(minValue),
maxNumberValue: 32,
required: true})
required: true,
})
loadpoint.MinCurrent, _ = strconv.Atoi(minAmperage)
maxAmperage := c.askValue(question{
label: c.localizedString("Loadpoint_WallboxMaxAmperage", nil),
valueType: templates.ParamValueTypeNumber,
minNumberValue: 6,
maxNumberValue: 32,
required: true})
required: true,
})
loadpoint.MaxCurrent, _ = strconv.Atoi(maxAmperage)

if !chargerHasMeter {
Expand Down Expand Up @@ -378,7 +382,8 @@ func (c *CmdConfigure) configureLoadpoints() {
valueType: templates.ParamValueTypeNumber,
minNumberValue: int64(minValue),
maxNumberValue: 32,
required: true})
required: true,
})
loadpoint.MaxCurrent, _ = strconv.Atoi(amperage)

if !chargerHasMeter {
Expand Down Expand Up @@ -415,6 +420,7 @@ func (c *CmdConfigure) configureSite() {
siteTitle := c.askValue(question{
label: c.localizedString("Site_Title", nil),
defaultValue: c.localizedString("Site_DefaultTitle", nil),
required: true})
required: true,
})
c.configuration.config.Site.Title = siteTitle
}
2 changes: 1 addition & 1 deletion cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func runHealth(cmd *cobra.Command, args []string) {

u.RegisterLocation(serviceName, server.SocketPath)

var client = http.Client{
client := http.Client{
Transport: u,
}

Expand Down
1 change: 0 additions & 1 deletion core/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ func TestVehicleDetectByStatus(t *testing.T) {
c.release(res)
}
}

}
3 changes: 1 addition & 2 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,6 @@ func (lp *LoadPoint) UpdateChargePower() {

return nil
}, retryOptions...)

if err != nil {
lp.log.ERROR.Printf("charge meter: %v", err)
}
Expand Down Expand Up @@ -1409,7 +1408,7 @@ func (lp *LoadPoint) publishSoCAndRange() {
}

// Update is the main control function. It reevaluates meters and charger state
func (lp *LoadPoint) Update(sitePower float64, cheap bool, batteryBuffered bool) {
func (lp *LoadPoint) Update(sitePower float64, cheap, batteryBuffered bool) {
mode := lp.GetMode()
lp.publish("mode", mode)

Expand Down
2 changes: 2 additions & 0 deletions core/loadpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ func TestChargedEnergyAtDisconnect(t *testing.T) {

ctrl.Finish()
}

func TestTargetSoC(t *testing.T) {
ctrl := gomock.NewController(t)
vhc := mock.NewMockVehicle(ctrl)
Expand Down Expand Up @@ -634,6 +635,7 @@ func TestTargetSoC(t *testing.T) {
}
}
}

func TestSoCPoll(t *testing.T) {
clock := clock.NewMock()
tRefresh := pollInterval
Expand Down
6 changes: 4 additions & 2 deletions core/savings.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"github.com/evcc-io/evcc/tariff"
)

const DefaultGridPrice = 0.30
const DefaultFeedInPrice = 0.08
const (
DefaultGridPrice = 0.30
DefaultFeedInPrice = 0.08
)

// publisher gives access to the site's publish function
type publisher interface {
Expand Down
2 changes: 1 addition & 1 deletion core/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// Updater abstracts the LoadPoint implementation for testing
type Updater interface {
Update(availablePower float64, cheapRate bool, batteryBuffered bool)
Update(availablePower float64, cheapRate, batteryBuffered bool)
}

// Site is the main configuration container. A site can host multiple loadpoints.
Expand Down
2 changes: 1 addition & 1 deletion core/soc/estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestRemainingChargeDuration(t *testing.T) {
ctrl := gomock.NewController(t)
charger := mock.NewMockCharger(ctrl)
vehicle := mock.NewMockVehicle(ctrl)
//9 kWh userBatCap => 10 kWh virtualBatCap
// 9 kWh userBatCap => 10 kWh virtualBatCap
vehicle.EXPECT().Capacity().Return(int64(9))

ce := NewEstimator(util.NewLogger("foo"), charger, vehicle, false)
Expand Down
4 changes: 1 addition & 3 deletions hems/semp/semp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ const (
maxAge = 1800
)

var (
serverName = "EVCC SEMP Server " + server.Version
)
var serverName = "EVCC SEMP Server " + server.Version

// SEMP is the SMA SEMP server
type SEMP struct {
Expand Down
2 changes: 1 addition & 1 deletion meter/fritzdect/fritzdect.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (c *Connection) getSessionID() error {
}

// createChallengeResponse creates the Fritzbox challenge response string
func createChallengeResponse(challenge string, pass string) (string, error) {
func createChallengeResponse(challenge, pass string) (string, error) {
encoder := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM).NewEncoder()
utf16le, err := encoder.String(challenge + "-" + pass)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion provider/sma.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewSMAFromConfig(other map[string]interface{}) (IntProvider, error) {
return nil, fmt.Errorf("failed to get discoverer failed: %w", err)
}

var provider = &SMA{
provider := &SMA{
scale: cc.Scale,
}
switch {
Expand Down
Loading

0 comments on commit 815cc58

Please sign in to comment.