From 8826a9643af422584cb6fea8e85b9e5db32cb9ac Mon Sep 17 00:00:00 2001 From: brchri <126272303+brchri@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:53:46 -0600 Subject: [PATCH] fix: myq api auth (#22) MyQ recently updated their auth flow process. Updated the myq package dependency to account for changes and now bumping here to consume those updates. Hopefully it sticks and they don't change again. [Related Issue](https://github.com/home-assistant/core/issues/101763) --- go.mod | 4 ++-- go.sum | 12 ++++++++++++ internal/geo/geo.go | 2 +- internal/geo/geo_test.go | 38 ++++++++++++++++++++------------------ 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index bef303d..36f7864 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/brchri/tesla-youq go 1.19 require ( - github.com/brchri/myq v0.0.0-20231002041725-18aa0c937db3 + github.com/brchri/myq v0.0.0-20231011234622-15e50fb789db github.com/eclipse/paho.mqtt.golang v1.4.2 github.com/google/uuid v1.3.0 github.com/stretchr/testify v1.8.4 @@ -15,6 +15,6 @@ require ( github.com/gorilla/websocket v1.4.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/objx v0.5.0 // indirect - golang.org/x/net v0.15.0 // indirect + golang.org/x/net v0.17.0 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect ) diff --git a/go.sum b/go.sum index 5408d33..4940c29 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,15 @@ github.com/brchri/myq v0.0.0-20231002041725-18aa0c937db3 h1:t5edNn/KiV1Kgz1Ll1kdpupABPUtOUDIebHLm5JmDV8= github.com/brchri/myq v0.0.0-20231002041725-18aa0c937db3/go.mod h1:EDuAgiwrpS8cfzKCUrXpelEw1YOjxO/jhklEthAKmEs= +github.com/brchri/myq v0.0.0-20231011144103-b24617ee607a h1:BMPw9+y9A60fk3NAvknSJp/vJXWCsKf5xYAxp5IvxQ4= +github.com/brchri/myq v0.0.0-20231011144103-b24617ee607a/go.mod h1:EDuAgiwrpS8cfzKCUrXpelEw1YOjxO/jhklEthAKmEs= +github.com/brchri/myq v0.0.0-20231011144527-624a68a134f7 h1:3Uht+0sMKLk9x8+QWZUBfivHtuprFJ4fpe++c8OzZRI= +github.com/brchri/myq v0.0.0-20231011144527-624a68a134f7/go.mod h1:EDuAgiwrpS8cfzKCUrXpelEw1YOjxO/jhklEthAKmEs= +github.com/brchri/myq v0.0.0-20231011145427-af9fc472ba40 h1:umY7pdRNohhcfNWs3BGV9br4gYoPGxo/q/NvGr5pYg0= +github.com/brchri/myq v0.0.0-20231011145427-af9fc472ba40/go.mod h1:EDuAgiwrpS8cfzKCUrXpelEw1YOjxO/jhklEthAKmEs= +github.com/brchri/myq v0.0.0-20231011223614-977a9792b054 h1:NbR/KNuDzmSGXi78b5K5KY0Dre7t9dMoqHMcZbZ0hMM= +github.com/brchri/myq v0.0.0-20231011223614-977a9792b054/go.mod h1:EDuAgiwrpS8cfzKCUrXpelEw1YOjxO/jhklEthAKmEs= +github.com/brchri/myq v0.0.0-20231011234622-15e50fb789db h1:7ann1FJumNDQsCpWh7laZqp6VNb9N0QDcCjcVZ5reFs= +github.com/brchri/myq v0.0.0-20231011234622-15e50fb789db/go.mod h1:EDuAgiwrpS8cfzKCUrXpelEw1YOjxO/jhklEthAKmEs= github.com/davecgh/go-spew v1.1.0/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= @@ -24,6 +34,8 @@ golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/internal/geo/geo.go b/internal/geo/geo.go index f948c0a..491520c 100644 --- a/internal/geo/geo.go +++ b/internal/geo/geo.go @@ -131,7 +131,7 @@ func CheckGeofence(config util.ConfigStruct, car *util.Car) { } // create retry loop to set the garage door state - for i := 3; i > 0; i-- { + for i := 1; i > 0; i-- { // temporarily setting to 1 to disable retry logic while myq auth endpoint stabilizes to avoid rate limiting if err := setGarageDoor(config, car.GarageDoor.MyQSerial, action); err == nil { // no error received, so breaking retry loop break diff --git a/internal/geo/geo_test.go b/internal/geo/geo_test.go index e85cca2..50e9f0a 100644 --- a/internal/geo/geo_test.go +++ b/internal/geo/geo_test.go @@ -168,24 +168,26 @@ func Test_CheckCircularGeofence_Arriving_LoggedIn(t *testing.T) { assert.Equal(t, checkGeofenceWrapper(distanceCar), true) } -func Test_CheckCircularGeofence_Arriving_LoggedIn_Retry(t *testing.T) { - myqSession := &mocks.MyqSessionInterface{} - myqSession.Test(t) - defer myqSession.AssertExpectations(t) - myqExec = myqSession - - // TEST 1 - Arriving home, garage open - myqSession.EXPECT().DeviceState(mock.AnythingOfType("string")).Return(myq.StateClosed, nil).Times(3) - myqSession.EXPECT().SetDoorState(mock.AnythingOfType("string"), myq.ActionOpen).Return(errors.New("some error")).Twice() - myqSession.EXPECT().SetDoorState(mock.AnythingOfType("string"), myq.ActionOpen).Return(nil).Once() - myqSession.EXPECT().DeviceState(mock.AnythingOfType("string")).Return(myq.StateOpen, nil).Once() - - distanceCar.CurDistance = 100 - distanceCar.CurrentLocation.Lat = distanceGarageDoor.CircularGeofence.Center.Lat - distanceCar.CurrentLocation.Lng = distanceGarageDoor.CircularGeofence.Center.Lng - - assert.Equal(t, checkGeofenceWrapper(distanceCar), true) -} +// retry logic has been temporarily disabled, so this test is not needed until it's re-enabled +// this is due to the myq api changes that need stabilizing so we don't retry and hit api rate limiting +// func Test_CheckCircularGeofence_Arriving_LoggedIn_Retry(t *testing.T) { +// myqSession := &mocks.MyqSessionInterface{} +// myqSession.Test(t) +// defer myqSession.AssertExpectations(t) +// myqExec = myqSession + +// // TEST 1 - Arriving home, garage open +// myqSession.EXPECT().DeviceState(mock.AnythingOfType("string")).Return(myq.StateClosed, nil).Times(3) +// myqSession.EXPECT().SetDoorState(mock.AnythingOfType("string"), myq.ActionOpen).Return(errors.New("some error")).Twice() +// myqSession.EXPECT().SetDoorState(mock.AnythingOfType("string"), myq.ActionOpen).Return(nil).Once() +// myqSession.EXPECT().DeviceState(mock.AnythingOfType("string")).Return(myq.StateOpen, nil).Once() + +// distanceCar.CurDistance = 100 +// distanceCar.CurrentLocation.Lat = distanceGarageDoor.CircularGeofence.Center.Lat +// distanceCar.CurrentLocation.Lng = distanceGarageDoor.CircularGeofence.Center.Lng + +// assert.Equal(t, checkGeofenceWrapper(distanceCar), true) +// } func Test_CheckCircularGeofence_LeaveThenArrive_NotLoggedIn(t *testing.T) { myqSession := &mocks.MyqSessionInterface{}