diff --git a/README.md b/README.md index 000bf52..d8c81a8 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,9 @@ Current Grid Status. (closed/opened) - **v21** - Bug fix for Enpower nil error, Thanks to RollyandSam. + +- **v22** + - Fixes for Auth flow. ## Compiled Driver Available from Releases: https://github.com/Leighm0/enphase_gateway/releases diff --git a/driver.lua b/driver.lua index 3040d18..eadc6f3 100644 --- a/driver.lua +++ b/driver.lua @@ -294,15 +294,19 @@ end function GetProductionData() if (gNeedAuth == true) and (gAuth == false) then + gAuthToken = nil CreateAuth() return end if (gNeedAuth == true) and (gAuth == true) then if (gAuthToken == nil) then dbg("GetProductionData(): No Auth Token yet, not continuing.") + gAuth = false return elseif (type(gAuthToken) ~= "string") then dbg("GetProductionData(): No Auth Token yet, not continuing.") + gAuth = false + gAuthToken = nil return else HEADERS["Authorization"] = "Bearer " .. gAuthToken @@ -315,15 +319,19 @@ end function GetTotals() if (gNeedAuth == true) and (gAuth == false) then + gAuthToken = nil CreateAuth() return end if (gNeedAuth == true) and (gAuth == true) then if (gAuthToken == nil) then dbg("GetTotals(): No Auth Token yet, not continuing.") + gAuth = false return elseif (type(gAuthToken) ~= "string") then dbg("GetTotals(): No Auth Token yet, not continuing.") + gAuth = false + gAuthToken = nil return else HEADERS["Authorization"] = "Bearer " .. gAuthToken @@ -336,15 +344,19 @@ end function GetGridStatus() if (gNeedAuth == true) and (gAuth == false) then + gAuthToken = nil CreateAuth() return end if (gNeedAuth == true) and (gAuth == true) then if (gAuthToken == nil) then dbg("GetGridStatus(): No Auth Token yet, not continuing.") + gAuth = false return elseif (type(gAuthToken) ~= "string") then dbg("GetTotals(): No Auth Token yet, not continuing.") + gAuth = false + gAuthToken = nil return else HEADERS["Authorization"] = "Bearer " .. gAuthToken @@ -440,6 +452,7 @@ function GetDataResponse(strError, responseCode, tHeaders, data, context, url) dbg("GetDataResponse: " .. context.data_type .. " Error 400.") elseif (responseCode == 401) then dbg("GetDataResponse: " .. context.data_type .. " Error 401.") + gAuth = false gAuthToken = nil CreateAuth() elseif (responseCode == 404) then diff --git a/driver.xml b/driver.xml index bc7ca12..527c48e 100644 --- a/driver.xml +++ b/driver.xml @@ -5,8 +5,8 @@ Enphase Gateway IQ/Envoy S Metered Gateways 11/3/2023 12:00 AM - 8/15/2024 12:00 AM - 21 + 10/15/2024 12:00 AM + 22 lua_gen DriverWorks icons\device_lg.png diff --git a/www/documentation.md b/www/documentation.md index 5920b70..dc1feef 100644 --- a/www/documentation.md +++ b/www/documentation.md @@ -189,4 +189,7 @@ Current Grid Status. (closed/opened) - Added Discovery Mode (Auto/Manual) for the ability to manually set which Envoy IP to use. (Useful if you run multiple Envoy Gateways) - **v21** - - Bug fix for Enpower nil error, Thanks to RollyandSam. \ No newline at end of file + - Bug fix for Enpower nil error, Thanks to RollyandSam. + +- **v22** + - Fixes for Auth flow. \ No newline at end of file