Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.

Commit c1e4a30

Browse files
committed
feat: Reduce external dependencies: external Retry library is retired
1 parent ffb79b6 commit c1e4a30

File tree

6 files changed

+17
-19
lines changed

6 files changed

+17
-19
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ run:
4747
### BUILD COMMANDS
4848
########################################################################################################################
4949
build: fmt vet ## Build manager binary.
50-
cd cmd/autoheater && go mod tidy && go build -o ../bin/manager .
50+
cd cmd/autoheater && go mod tidy && go build -o ../../bin/manager .
5151

5252
# If you wish built the manager image targeting other platforms you can use the --platform flag.
5353
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ go 1.21
44

55
require (
66
github.com/achetronic/tapogo v0.2.0
7-
github.com/avast/retry-go v3.0.0+incompatible
8-
github.com/caarlos0/env/v9 v9.0.0
97
github.com/richardjennings/tapo v0.0.1
108
github.com/spf13/cobra v1.7.0
119
go.uber.org/zap v1.25.0

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
github.com/achetronic/tapogo v0.2.0 h1:eMyEPdZsEzKwacj43FihDRLJxfNX4YpiWb/eEmMyVTQ=
22
github.com/achetronic/tapogo v0.2.0/go.mod h1:DVflSfbePg4SAjRy0aeMYJ0vj4Pjesw5sw6y4yP0f8w=
3-
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
4-
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
53
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
64
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
7-
github.com/caarlos0/env/v9 v9.0.0 h1:SI6JNsOA+y5gj9njpgybykATIylrRMklbs5ch6wO6pc=
8-
github.com/caarlos0/env/v9 v9.0.0/go.mod h1:ye5mlCVMYh6tZ+vCgrs/B95sj88cg5Tlnc0XIzgZ020=
95
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
106
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
117
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

internal/schedules/utils.go renamed to internal/globals/globals.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package schedules
1+
package globals
22

33
import (
44
"time"
55
)
66

7-
func retry(function func() error, attempts int, timeBetweenAttempts time.Duration) (err error) {
7+
func Retry(function func() error, attempts int, timeBetweenAttempts time.Duration) (err error) {
88

99
var functionError error
1010

internal/integrations/taposmartplug/taposmartplug.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package taposmartplug
33
import (
44
"encoding/json"
55
"errors"
6+
"time"
7+
68
"github.com/achetronic/autoheater/api/v1alpha1"
9+
"github.com/achetronic/autoheater/internal/globals"
710
tapogotypes "github.com/achetronic/tapogo/api/types"
811
"github.com/achetronic/tapogo/pkg/tapogo"
9-
"github.com/avast/retry-go"
1012
"github.com/richardjennings/tapo/pkg/tapo"
11-
"time"
1213
)
1314

1415
const (
@@ -69,7 +70,9 @@ func TurnOnDevice(ctx *v1alpha1.Context) (tapoResponse map[string]interface{}, e
6970
// New KLAP protocol throws random errors when the requests are done at speed.
7071
// Retrying with a new token mostly solve the issue (jaquecoso...)
7172
tapoResponseNew := &tapogotypes.ResponseSpec{}
72-
err = retry.Do(
73+
74+
//schedules.R
75+
err = globals.Retry(
7376
func() (err error) {
7477
tapoClientNew, err := tapogo.NewTapo(tapoConfig.Address,
7578
tapoConfig.Auth.Username,
@@ -86,8 +89,8 @@ func TurnOnDevice(ctx *v1alpha1.Context) (tapoResponse map[string]interface{}, e
8689
}
8790
return err
8891
},
89-
retry.Attempts(RequestRetryAttempts),
90-
retry.Delay(RequestRetryDelayDuration))
92+
RequestRetryAttempts,
93+
RequestRetryDelayDuration)
9194

9295
if err != nil {
9396
ctx.Logger.Errorf(TurningOnError, err)
@@ -137,7 +140,7 @@ func TurnOffDevice(ctx *v1alpha1.Context) (tapoResponse map[string]interface{},
137140
// New KLAP protocol throws random errors when the requests are done at speed.
138141
// Retrying with a new token mostly solve the issue (jaquecoso...)
139142
tapoResponseNew := &tapogotypes.ResponseSpec{}
140-
err = retry.Do(
143+
err = globals.Retry(
141144
func() (err error) {
142145
tapoClientNew, err := tapogo.NewTapo(tapoConfig.Address,
143146
tapoConfig.Auth.Username,
@@ -155,8 +158,8 @@ func TurnOffDevice(ctx *v1alpha1.Context) (tapoResponse map[string]interface{},
155158
}
156159
return err
157160
},
158-
retry.Attempts(RequestRetryAttempts),
159-
retry.Delay(RequestRetryDelayDuration))
161+
RequestRetryAttempts,
162+
RequestRetryDelayDuration)
160163

161164
if err != nil {
162165
ctx.Logger.Errorf(TurningOffError, err)

internal/schedules/schedules.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/achetronic/autoheater/internal/integrations/webhook"
1111
"github.com/achetronic/autoheater/internal/price"
1212
"github.com/achetronic/autoheater/internal/weather"
13+
"github.com/achetronic/autoheater/internal/globals"
1314
)
1415

1516
const (
@@ -52,7 +53,7 @@ func RunScheduler(ctx *v1alpha1.Context) {
5253
// Disable the scheduler in (hot days for heaters) && (cold days for coolers)
5354
if ctx.Config.Spec.Weather.Enabled {
5455

55-
retryFunctionErr = retry(func() error {
56+
retryFunctionErr = globals.Retry(func() error {
5657
isCold, err = weather.IsColdDay(ctx)
5758
return err
5859
}, RetryAttempts, RetryDelay)
@@ -72,7 +73,7 @@ func RunScheduler(ctx *v1alpha1.Context) {
7273
}
7374

7475
// Get the sections with the best prices to satisfy the hours required by the user
75-
retryFunctionErr = retry(func() error {
76+
retryFunctionErr = globals.Retry(func() error {
7677
schedules, err = price.GetBestSchedules(ctx)
7778
return err
7879
}, RetryAttempts, RetryDelay)

0 commit comments

Comments
 (0)