Skip to content

Commit

Permalink
fix: myq api auth (#22)
Browse files Browse the repository at this point in the history
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](home-assistant/core#101763)
  • Loading branch information
brchri authored Oct 11, 2023
1 parent 490eef2 commit 8826a96
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion internal/geo/geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 20 additions & 18 deletions internal/geo/geo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit 8826a96

Please sign in to comment.