Skip to content

Commit 4671574

Browse files
committed
Use Go generics (caching, vehicle id, x/exp/slices, replace go-funk)
1 parent c4628ee commit 4671574

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+447
-728
lines changed

charger/easee.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"github.com/evcc-io/evcc/util/request"
3434
"github.com/evcc-io/evcc/util/sponsor"
3535
"github.com/philippseith/signalr"
36-
"github.com/thoas/go-funk"
3736
"golang.org/x/oauth2"
3837
)
3938

@@ -109,7 +108,7 @@ func NewEasee(user, password, charger string) (*Easee, error) {
109108
}
110109

111110
if len(chargers) != 1 {
112-
return c, fmt.Errorf("cannot determine charger id, found: %v", funk.Map(chargers, func(c easee.Charger) string { return c.ID }))
111+
return c, fmt.Errorf("cannot determine charger id, found: %v", util.Map(chargers, func(c easee.Charger) string { return c.ID }))
113112
}
114113

115114
c.charger = chargers[0].ID

charger/easee/log.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66

77
"github.com/philippseith/signalr"
8-
"github.com/thoas/go-funk"
8+
"golang.org/x/exp/slices"
99
)
1010

1111
// Logger is a simple logger interface
@@ -34,7 +34,7 @@ func (l *logger) Log(keyVals ...interface{}) error {
3434
}
3535

3636
if i%2 == 0 {
37-
if funk.Contains(skipped, v) {
37+
if slices.Contains(skipped, v.(string)) {
3838
skip = true
3939
continue
4040
}

charger/template_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/evcc-io/evcc/util/templates"
77
"github.com/evcc-io/evcc/util/test"
8-
"github.com/thoas/go-funk"
8+
"golang.org/x/exp/slices"
99
)
1010

1111
var acceptable = []string{
@@ -44,7 +44,7 @@ func TestTemplates(t *testing.T) {
4444
if values[templates.ParamModbus] != nil {
4545
modbusChoices := tmpl.ModbusChoices()
4646
// we only test one modbus setup
47-
if funk.ContainsString(modbusChoices, templates.ModbusChoiceTCPIP) {
47+
if slices.Contains(modbusChoices, templates.ModbusChoiceTCPIP) {
4848
values[templates.ModbusKeyTCPIP] = true
4949
} else {
5050
values[templates.ModbusKeyRS485TCPIP] = true

cmd/configure/helper.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"github.com/evcc-io/evcc/util"
1111
"github.com/evcc-io/evcc/util/sponsor"
1212
"github.com/evcc-io/evcc/util/templates"
13-
"github.com/thoas/go-funk"
1413
stripmd "github.com/writeas/go-strip-markdown"
14+
"golang.org/x/exp/slices"
1515
"gopkg.in/yaml.v3"
1616
)
1717

@@ -128,7 +128,7 @@ func (c *CmdConfigure) processDeviceValues(values map[string]interface{}, templa
128128
}
129129

130130
func (c *CmdConfigure) processDeviceCapabilities(capabilitites []string) {
131-
if funk.ContainsString(capabilitites, templates.CapabilitySMAHems) {
131+
if slices.Contains(capabilitites, templates.CapabilitySMAHems) {
132132
c.capabilitySMAHems = true
133133
}
134134
}
@@ -148,14 +148,14 @@ func (c *CmdConfigure) processDeviceRequirements(templateItem templates.Template
148148
}
149149

150150
// check if sponsorship is required
151-
if funk.ContainsString(templateItem.Requirements.EVCC, templates.RequirementSponsorship) && c.configuration.config.SponsorToken == "" {
151+
if slices.Contains(templateItem.Requirements.EVCC, templates.RequirementSponsorship) && c.configuration.config.SponsorToken == "" {
152152
if err := c.askSponsortoken(true, false); err != nil {
153153
return err
154154
}
155155
}
156156

157157
// check if we need to setup an MQTT broker
158-
if funk.ContainsString(templateItem.Requirements.EVCC, templates.RequirementMQTT) {
158+
if slices.Contains(templateItem.Requirements.EVCC, templates.RequirementMQTT) {
159159
if c.configuration.config.MQTT == "" {
160160
mqttConfig, err := c.configureMQTT(templateItem)
161161
if err != nil {
@@ -172,7 +172,7 @@ func (c *CmdConfigure) processDeviceRequirements(templateItem templates.Template
172172
}
173173

174174
// check if we need to setup an EEBUS HEMS
175-
if funk.ContainsString(templateItem.Requirements.EVCC, templates.RequirementEEBUS) {
175+
if slices.Contains(templateItem.Requirements.EVCC, templates.RequirementEEBUS) {
176176
if c.configuration.config.EEBUS == "" {
177177
fmt.Println()
178178
fmt.Println("-- EEBUS -----------------------------------")
@@ -219,7 +219,7 @@ func (c *CmdConfigure) processParamRequirements(param templates.Param) error {
219219
}
220220

221221
// check if sponsorship is required
222-
if funk.ContainsString(param.Requirements.EVCC, templates.RequirementSponsorship) && c.configuration.config.SponsorToken == "" {
222+
if slices.Contains(param.Requirements.EVCC, templates.RequirementSponsorship) && c.configuration.config.SponsorToken == "" {
223223
if err := c.askSponsortoken(true, true); err != nil {
224224
return err
225225
}
@@ -384,7 +384,7 @@ func (c *CmdConfigure) fetchElements(deviceCategory DeviceCategory) []templates.
384384
func (c *CmdConfigure) paramChoiceContains(params []templates.Param, name, filter string) bool {
385385
choices := c.paramChoiceValues(params, name)
386386

387-
return funk.ContainsString(choices, filter)
387+
return slices.Contains(choices, filter)
388388
}
389389

390390
// paramChoiceValues provides a list of possible values for a param choice
@@ -533,7 +533,7 @@ func (c *CmdConfigure) processInputConfig(param templates.Param) string {
533533
}
534534

535535
help := param.Help.String(c.lang)
536-
if funk.ContainsString(param.Requirements.EVCC, templates.RequirementSponsorship) {
536+
if slices.Contains(param.Requirements.EVCC, templates.RequirementSponsorship) {
537537
help = fmt.Sprintf("%s\n\n%s", help, c.localizedString("Requirements_Sponsorship_Feature_Title", nil))
538538
}
539539

cmd/configure/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/evcc-io/evcc/util"
1717
"github.com/evcc-io/evcc/util/templates"
1818
"github.com/nicksnyder/go-i18n/v2/i18n"
19-
"github.com/thoas/go-funk"
19+
"golang.org/x/exp/slices"
2020
"golang.org/x/text/language"
2121
)
2222

@@ -320,7 +320,7 @@ func (c *CmdConfigure) configureLoadpoints() {
320320
}
321321

322322
var minValue int = 6
323-
if funk.ContainsString(capabilities, templates.CapabilityISO151182) {
323+
if slices.Contains(capabilities, templates.CapabilityISO151182) {
324324
minValue = 2
325325
}
326326

cmd/configure/survey.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/AlecAivazis/survey/v2/terminal"
1212
"github.com/evcc-io/evcc/api"
1313
"github.com/evcc-io/evcc/util/templates"
14-
"github.com/thoas/go-funk"
1514
stripmd "github.com/writeas/go-strip-markdown"
15+
"golang.org/x/exp/slices"
1616
)
1717

1818
// surveyAskOne asks the user for input
@@ -49,7 +49,7 @@ func (c *CmdConfigure) askSelection(message string, items []string) (string, int
4949
var selection string
5050
err := c.surveyAskOne(prompt, &selection)
5151

52-
return selection, funk.IndexOf(items, selection), err
52+
return selection, slices.Index(items, selection), err
5353
}
5454

5555
// selectItem selects item from list
@@ -153,11 +153,11 @@ func (c *CmdConfigure) askValue(q question) string {
153153

154154
validate := func(val interface{}) error {
155155
value := val.(string)
156-
if q.invalidValues != nil && funk.ContainsString(q.invalidValues, value) {
156+
if q.invalidValues != nil && slices.Contains(q.invalidValues, value) {
157157
return errors.New(c.localizedString("ValueError_Used", nil))
158158
}
159159

160-
if q.validValues != nil && !funk.ContainsString(q.validValues, value) {
160+
if q.validValues != nil && !slices.Contains(q.validValues, value) {
161161
return errors.New(c.localizedString("ValueError_Invalid", nil))
162162
}
163163

cmd/token.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/evcc-io/evcc/util"
99
"github.com/spf13/cobra"
1010
"github.com/spf13/viper"
11-
"github.com/thoas/go-funk"
11+
"golang.org/x/exp/slices"
1212
"golang.org/x/oauth2"
1313
)
1414

@@ -37,15 +37,19 @@ func runToken(cmd *cobra.Command, args []string) {
3737
if len(conf.Vehicles) == 1 {
3838
vehicleConf = conf.Vehicles[0]
3939
} else if len(args) == 1 {
40-
vehicleConf = funk.Find(conf.Vehicles, func(v qualifiedConfig) bool {
40+
idx := slices.IndexFunc(conf.Vehicles, func(v qualifiedConfig) bool {
4141
return strings.EqualFold(v.Name, args[0])
42-
}).(qualifiedConfig)
42+
})
43+
44+
if idx >= 0 {
45+
vehicleConf = conf.Vehicles[idx]
46+
}
4347
}
4448

4549
if vehicleConf.Name == "" {
46-
vehicles := funk.Map(conf.Vehicles, func(v qualifiedConfig) string {
50+
vehicles := util.Map(conf.Vehicles, func(v qualifiedConfig) string {
4751
return v.Name
48-
}).([]string)
52+
})
4953
log.FATAL.Fatalf("vehicle not found, have %v", vehicles)
5054
}
5155

core/loadpoint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/evcc-io/evcc/provider"
1717
"github.com/evcc-io/evcc/push"
1818
"github.com/evcc-io/evcc/util"
19-
"github.com/thoas/go-funk"
19+
"golang.org/x/exp/slices"
2020

2121
evbus "github.com/asaskevich/EventBus"
2222
"github.com/avast/retry-go/v3"
@@ -754,7 +754,7 @@ func (lp *LoadPoint) identifyVehicle() {
754754
func (lp *LoadPoint) selectVehicleByID(id string) api.Vehicle {
755755
// find exact match
756756
for _, vehicle := range lp.vehicles {
757-
if funk.ContainsString(vehicle.Identifiers(), id) {
757+
if slices.Contains(vehicle.Identifiers(), id) {
758758
return vehicle
759759
}
760760
}

detect/work.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Work(log *util.Logger, num int, hosts []string) []tasks.Result {
3939
// log.INFO.Println(
4040
// "\n" +
4141
// strings.Join(
42-
// funk.Map(taskList.tasks, func(t tasks.Task) string {
42+
// util.Map(taskList.tasks, func(t tasks.Task) string {
4343
// return fmt.Sprintf("task: %s\ttype: %s\tdepends: %s\n", t.ID, t.Type, t.Depends)
4444
// }).([]string),
4545
// "",

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ require (
6969
github.com/spf13/pflag v1.0.5
7070
github.com/spf13/viper v1.10.2-0.20220212101550-5986bd9c0c19
7171
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942
72-
github.com/thoas/go-funk v0.9.1
7372
github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c
7473
github.com/volkszaehler/mbmd v0.0.0-20220208145932-d2d3cba909f5
7574
github.com/writeas/go-strip-markdown v2.0.1+incompatible
7675
gitlab.com/bboehmke/sunny v0.15.1-0.20211022160056-2fba1c86ade6
76+
golang.org/x/exp v0.0.0-20220318154914-8dddf5d87bd8
7777
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
7878
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a
7979
golang.org/x/text v0.3.7
@@ -146,11 +146,12 @@ require (
146146
github.com/spf13/cast v1.4.1 // indirect
147147
github.com/subosito/gotenv v1.2.0 // indirect
148148
github.com/teivah/onecontext v1.3.0 // indirect
149+
github.com/thoas/go-funk v0.9.1 // indirect
149150
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
150151
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
151152
go.opencensus.io v0.23.0 // indirect
152153
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
153-
golang.org/x/mod v0.5.1 // indirect
154+
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 // indirect
154155
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
155156
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
156157
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect

go.sum

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ cloud.google.com/go v0.94.1/go.mod h1:qAlAugsXlC+JWO+Bke5vCtc9ONxjQT3drlTTnAplMW
2929
cloud.google.com/go v0.97.0/go.mod h1:GF7l59pYBVlXQIBLx3a761cZ41F9bBH3JUlihCt2Udc=
3030
cloud.google.com/go v0.98.0/go.mod h1:ua6Ush4NALrHk5QXDWnjvZHN93OuF0HfuEPq9I1X0cM=
3131
cloud.google.com/go v0.99.0/go.mod h1:w0Xx2nLzqWJPuozYQX+hFfCSI8WioryfRDzkoI/Y2ZA=
32-
cloud.google.com/go v0.100.2 h1:t9Iw5QH5v4XtlEQaCtUY7x6sCABps8sW0acw7e2WQ6Y=
3332
cloud.google.com/go v0.100.2/go.mod h1:4Xra9TjzAeYHrl5+oeLlzbM2k3mjVhZh4UqTZ//w99A=
3433
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
3534
cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
@@ -123,7 +122,6 @@ github.com/cenkalti/backoff/v4 v4.1.2 h1:6Yo7N8UP2K6LWZnW94DLVSSrbobcWdVzAYOisuD
123122
github.com/cenkalti/backoff/v4 v4.1.2/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
124123
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
125124
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
126-
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
127125
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
128126
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
129127
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
@@ -341,7 +339,6 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
341339
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
342340
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
343341
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
344-
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
345342
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
346343
github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=
347344
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
@@ -457,7 +454,6 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
457454
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
458455
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
459456
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
460-
github.com/influxdata/influxdb-client-go v1.4.0 h1:+KavOkwhLClHFfYcJMHHnTL5CZQhXJzOm5IKHI9BqJk=
461457
github.com/influxdata/influxdb-client-go v1.4.0/go.mod h1:S+oZsPivqbcP1S9ur+T+QqXvrYS3NCZeMQtBoH4D1dw=
462458
github.com/influxdata/influxdb-client-go/v2 v2.6.0 h1:bIOaGTgvvv1Na2hG+nIvqyv7PK2UiU2WrJN1ck1ykyM=
463459
github.com/influxdata/influxdb-client-go/v2 v2.6.0/go.mod h1:Y/0W1+TZir7ypoQZYd2IrnVOKB3Tq6oegAQeSVN/+EU=
@@ -824,7 +820,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
824820
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
825821
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
826822
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
827-
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
828823
gitlab.com/bboehmke/sunny v0.15.1-0.20211022160056-2fba1c86ade6 h1:73pM5aQqFkQfmXyGf3+xeWWg98J03xtDIkA5TE37ERU=
829824
gitlab.com/bboehmke/sunny v0.15.1-0.20211022160056-2fba1c86ade6/go.mod h1:F5AIuL7kYteSJFR5E+YEocxIdpyCXmtDciFmMQVjP88=
830825
go.coder.com/go-tools v0.0.0-20190317003359-0c6a35b74a16/go.mod h1:iKV5yK9t+J5nG9O3uF6KYdPEz3dyfMyB15MN1rbQ8Qw=
@@ -883,6 +878,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
883878
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
884879
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
885880
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
881+
golang.org/x/exp v0.0.0-20220318154914-8dddf5d87bd8 h1:s/+U+w0teGzcoH2mdIlFQ6KfVKGaYpgyGdUefZrn9TU=
882+
golang.org/x/exp v0.0.0-20220318154914-8dddf5d87bd8/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
886883
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
887884
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
888885
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@@ -910,8 +907,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
910907
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
911908
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
912909
golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
913-
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
914-
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
910+
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 h1:LQmS1nU0twXLA96Kt7U9qtHJEbBk3z6Q0V4UXjZkpr4=
911+
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
915912
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
916913
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
917914
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -970,9 +967,7 @@ golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qx
970967
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
971968
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
972969
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
973-
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
974970
golang.org/x/net v0.0.0-20211111160137-58aab5ef257a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
975-
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
976971
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
977972
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
978973
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
@@ -1095,7 +1090,6 @@ golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBc
10951090
golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
10961091
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
10971092
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1098-
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
10991093
golang.org/x/sys v0.0.0-20211031064116-611d5d643895/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11001094
golang.org/x/sys v0.0.0-20211112164355-7580c6e521dc/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11011095
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

meter/discovergy.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import (
1010
"github.com/evcc-io/evcc/util"
1111
"github.com/evcc-io/evcc/util/request"
1212
"github.com/evcc-io/evcc/util/transport"
13-
"github.com/thoas/go-funk"
1413
)
1514

1615
func init() {
1716
registry.Add("discovergy", NewDiscovergyFromConfig)
1817
}
1918

2019
type Discovergy struct {
21-
dataG func() (interface{}, error)
20+
dataG func() (discovergy.Reading, error)
2221
scale float64
2322
}
2423

@@ -63,17 +62,17 @@ func NewDiscovergyFromConfig(other map[string]interface{}) (api.Meter, error) {
6362
}
6463

6564
if meterID == "" {
66-
return nil, fmt.Errorf("could not determine meter id: %v", funk.Map(meters, func(m discovergy.Meter) string {
65+
return nil, fmt.Errorf("could not determine meter id: %v", util.Map(meters, func(m discovergy.Meter) string {
6766
return m.FullSerialNumber
6867
}))
6968
}
7069

71-
dataG := provider.NewCached(func() (interface{}, error) {
70+
dataG := provider.Cached(func() (discovergy.Reading, error) {
7271
var res discovergy.Reading
7372
uri := fmt.Sprintf("%s/last_reading?meterId=%s", discovergy.API, meterID)
7473
err := client.GetJSON(uri, &res)
7574
return res, err
76-
}, cc.Cache).InterfaceGetter()
75+
}, cc.Cache)
7776

7877
m := &Discovergy{
7978
dataG: dataG,
@@ -91,18 +90,12 @@ var _ api.Meter = (*Discovergy)(nil)
9190

9291
func (m *Discovergy) CurrentPower() (float64, error) {
9392
res, err := m.dataG()
94-
if res, ok := res.(discovergy.Reading); err == nil && ok {
95-
return m.scale * float64(res.Values.Power) / 1e3, nil
96-
}
97-
return 0, err
93+
return m.scale * float64(res.Values.Power) / 1e3, err
9894
}
9995

10096
var _ api.MeterEnergy = (*Discovergy)(nil)
10197

10298
func (m *Discovergy) TotalEnergy() (float64, error) {
10399
res, err := m.dataG()
104-
if res, ok := res.(discovergy.Reading); err == nil && ok {
105-
return float64(res.Values.Energy) / 1e10, nil
106-
}
107-
return 0, err
100+
return float64(res.Values.Energy) / 1e10, err
108101
}

0 commit comments

Comments
 (0)