gkreitz / homeassistant-grohe_sense

Grohe Sense integration for Home Assistant
MIT License
42 stars 25 forks source link

Get refresh_token automatically based on the username and password #31

Open rusucosmin opened 1 year ago

rusucosmin commented 1 year ago

Currently, after the refresh_token expires, the app automatically generates a new one. However, when you restart Home Assistant, it actually picks up the old one (the one that's stored in your config file). As such, the integration typically fails after some time, at the next Home Assistant restart.

I've changed the config to be able to specify your username and password, and it will get the first refresh_token automatically. Tested with my local HA and everything seems to be working smoothly.

peternorlander commented 1 year ago

Wow! Fantastic stuff! I checked it out and it works great! It has been running now for 10min. I will let you know in a couple of days if it appears to be fetching new token as excepted but it looks good. Thank you @rusucosmin ! 🥇

peternorlander commented 1 year ago

I see "my guard notification" has a notification that I can't see in the app. In the app it is all green and if I view firmware version it doesn't say anything about a new version here. I'm using firmware version: 01.51.Z22.0400.0101

This is what I get inside HA: image

rusucosmin commented 1 year ago

Hi! Thanks for testing it out 🙌!

That does seem strange. I just checked and my firmware version is 01.44.Z22.04000101 - so mine is older but it says I’m on the latest one. Maybe because I’m in Romania and firmwares differs across countries?

Another thing I want to ask: do you have the Micro Leakage feature turned on? Seems like your notification relates somehow to that feature?

Best, Cosmin

On Sun, May 28, 2023 at 10:13 Peter Norlander @.***> wrote:

I see "my guard notification" has a notification that I can't see in the app. In the app it is all green and if I view firmware version it doesn't say anything about a new version here. I'm using firmware version: 01.51.Z22.0400.0101

This is what I get inside HA: [image: image] https://user-images.githubusercontent.com/1375002/241513915-2c2d129d-010e-45b8-b22e-0853b1e292d6.png

— Reply to this email directly, view it on GitHub https://github.com/gkreitz/homeassistant-grohe_sense/pull/31#issuecomment-1565951365, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLVW5ZQ3C6IXU76PIKMWJ3XIL3KPANCNFSM6AAAAAAYRFQI2U . You are receiving this because you were mentioned.Message ID: @.***>

-- Best, Cosmin

peternorlander commented 1 year ago

Hi!

It feels odd to have different FW versions for countries, I would think it would just be configs but sure, that may be the case.

I have the micro leakage feature enabled and it has actually been pretty good. And it has always been in sync (when I have bothered to setup a token) so this is new for me that it reports something that the app doesn't. Usually they have been in good sync.

My biggest issue with this integration however (except for the one you fixed!) is that the water consumption isn't updating on HA. It is still now the same value as when I rebooted HA. If I reboot it will probably update again but that isn't really what I was hoping for. 😉 Do you have the same issue? The Grohe app is up to date.

Regards Peter

On Sun, 28 May 2023, 21:08 Cosmin Rusu, @.***> wrote:

Hi! Thanks for testing it out 🙌!

That does seem strange. I just checked and my firmware version is 01.44.Z22.04000101 - so mine is older but it says I’m on the latest one. Maybe because I’m in Romania and firmwares differs across countries?

Another thing I want to ask: do you have the Micro Leakage feature turned on? Seems like your notification relates somehow to that feature?

Best, Cosmin

On Sun, May 28, 2023 at 10:13 Peter Norlander @.***> wrote:

I see "my guard notification" has a notification that I can't see in the app. In the app it is all green and if I view firmware version it doesn't say anything about a new version here. I'm using firmware version: 01.51.Z22.0400.0101

This is what I get inside HA: [image: image] < https://user-images.githubusercontent.com/1375002/241513915-2c2d129d-010e-45b8-b22e-0853b1e292d6.png

— Reply to this email directly, view it on GitHub < https://github.com/gkreitz/homeassistant-grohe_sense/pull/31#issuecomment-1565951365 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/ABLVW5ZQ3C6IXU76PIKMWJ3XIL3KPANCNFSM6AAAAAAYRFQI2U

. You are receiving this because you were mentioned.Message ID: @.***>

-- Best, Cosmin

— Reply to this email directly, view it on GitHub https://github.com/gkreitz/homeassistant-grohe_sense/pull/31#issuecomment-1566232720, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKPWGVMMNPCJ4A2XCXZJZDXIOPB3ANCNFSM6AAAAAAYRFQI2U . You are receiving this because you commented.Message ID: @.***>

rusucosmin commented 1 year ago

Yeah - I have the same issue. It seems like the consumption is only updated every day, which is why it won't always be up to date. I believe the app updates itself every 15mins or so. It might be easy to add that too - I'll set some time aside the next weekend to investigate.

Best, Cosmin

On Mon, May 29, 2023 at 12:12 AM Peter Norlander @.***> wrote:

Hi!

It feels odd to have different FW versions for countries, I would think it would just be configs but sure, that may be the case.

I have the micro leakage feature enabled and it has actually been pretty good. And it has always been in sync (when I have bothered to setup a token) so this is new for me that it reports something that the app doesn't. Usually they have been in good sync.

My biggest issue with this integration however (except for the one you fixed!) is that the water consumption isn't updating on HA. It is still now the same value as when I rebooted HA. If I reboot it will probably update again but that isn't really what I was hoping for. 😉 Do you have the same issue? The Grohe app is up to date.

Regards Peter

On Sun, 28 May 2023, 21:08 Cosmin Rusu, @.***> wrote:

Hi! Thanks for testing it out 🙌!

That does seem strange. I just checked and my firmware version is 01.44.Z22.04000101 - so mine is older but it says I’m on the latest one. Maybe because I’m in Romania and firmwares differs across countries?

Another thing I want to ask: do you have the Micro Leakage feature turned on? Seems like your notification relates somehow to that feature?

Best, Cosmin

On Sun, May 28, 2023 at 10:13 Peter Norlander @.***> wrote:

I see "my guard notification" has a notification that I can't see in the app. In the app it is all green and if I view firmware version it doesn't say anything about a new version here. I'm using firmware version: 01.51.Z22.0400.0101

This is what I get inside HA: [image: image] <

https://user-images.githubusercontent.com/1375002/241513915-2c2d129d-010e-45b8-b22e-0853b1e292d6.png

— Reply to this email directly, view it on GitHub <

https://github.com/gkreitz/homeassistant-grohe_sense/pull/31#issuecomment-1565951365

, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/ABLVW5ZQ3C6IXU76PIKMWJ3XIL3KPANCNFSM6AAAAAAYRFQI2U

. You are receiving this because you were mentioned.Message ID: @.***>

-- Best, Cosmin

— Reply to this email directly, view it on GitHub < https://github.com/gkreitz/homeassistant-grohe_sense/pull/31#issuecomment-1566232720 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AAKPWGVMMNPCJ4A2XCXZJZDXIOPB3ANCNFSM6AAAAAAYRFQI2U

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/gkreitz/homeassistant-grohe_sense/pull/31#issuecomment-1566264938, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLVW52Q4YBZNPPYTTYVJO3XIO5VNANCNFSM6AAAAAAYRFQI2U . You are receiving this because you were mentioned.Message ID: @.***>

peternorlander commented 1 year ago

Hi Cosmin,

Mine still hasn't updated, it's still the same value as yesterday.

If you could investigate that would be awesome!

/Peter

On Mon, 29 May 2023, 09:31 Cosmin Rusu, @.***> wrote:

Yeah - I have the same issue. It seems like the consumption is only updated every day, which is why it won't always be up to date. I believe the app updates itself every 15mins or so. It might be easy to add that too - I'll set some time aside the next weekend to investigate.

Best, Cosmin

On Mon, May 29, 2023 at 12:12 AM Peter Norlander @.***> wrote:

Hi!

It feels odd to have different FW versions for countries, I would think it would just be configs but sure, that may be the case.

I have the micro leakage feature enabled and it has actually been pretty good. And it has always been in sync (when I have bothered to setup a token) so this is new for me that it reports something that the app doesn't. Usually they have been in good sync.

My biggest issue with this integration however (except for the one you fixed!) is that the water consumption isn't updating on HA. It is still now the same value as when I rebooted HA. If I reboot it will probably update again but that isn't really what I was hoping for. 😉 Do you have the same issue? The Grohe app is up to date.

Regards Peter

On Sun, 28 May 2023, 21:08 Cosmin Rusu, @.***> wrote:

Hi! Thanks for testing it out 🙌!

That does seem strange. I just checked and my firmware version is 01.44.Z22.04000101 - so mine is older but it says I’m on the latest one. Maybe because I’m in Romania and firmwares differs across countries?

Another thing I want to ask: do you have the Micro Leakage feature turned on? Seems like your notification relates somehow to that feature?

Best, Cosmin

On Sun, May 28, 2023 at 10:13 Peter Norlander @.***> wrote:

I see "my guard notification" has a notification that I can't see in the app. In the app it is all green and if I view firmware version it doesn't say anything about a new version here. I'm using firmware version: 01.51.Z22.0400.0101

This is what I get inside HA: [image: image] <

https://user-images.githubusercontent.com/1375002/241513915-2c2d129d-010e-45b8-b22e-0853b1e292d6.png

— Reply to this email directly, view it on GitHub <

https://github.com/gkreitz/homeassistant-grohe_sense/pull/31#issuecomment-1565951365

, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/ABLVW5ZQ3C6IXU76PIKMWJ3XIL3KPANCNFSM6AAAAAAYRFQI2U

. You are receiving this because you were mentioned.Message ID: @.***>

-- Best, Cosmin

— Reply to this email directly, view it on GitHub <

https://github.com/gkreitz/homeassistant-grohe_sense/pull/31#issuecomment-1566232720

, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AAKPWGVMMNPCJ4A2XCXZJZDXIOPB3ANCNFSM6AAAAAAYRFQI2U

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub < https://github.com/gkreitz/homeassistant-grohe_sense/pull/31#issuecomment-1566264938 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/ABLVW52Q4YBZNPPYTTYVJO3XIO5VNANCNFSM6AAAAAAYRFQI2U

. You are receiving this because you were mentioned.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/gkreitz/homeassistant-grohe_sense/pull/31#issuecomment-1566688645, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKPWGVRIQ3V6SZ27H7V7L3XIRGDXANCNFSM6AAAAAAYRFQI2U . You are receiving this because you commented.Message ID: @.***>

peternorlander commented 1 year ago

Hi again Cosmin,

An update from me. None of the values has updated for four days now. So I triggered a manual restart of HA and then it failed to generate a new token for me and thus was unable to setup the integration. Any idea what I have done wrong?

Logs: 2023-06-01 22:01:13.126 ERROR (MainThread) [custom_components.grohe_sense] Grohe sense refresh token is invalid (or expired), please update your configuration with a new refresh token 2023-06-01 22:01:13.687 ERROR (MainThread) [homeassistant.setup] Error during setup of component grohe_sense Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/setup.py", line 256, in _async_setup_component result = await task File "/config/custom_components/grohe_sense/init.py", line 76, in async_setup await initialize_shared_objects(hass, await get_token(hass, config.get(DOMAIN).get(CONF_USERNAME), config.get(DOMAIN).get(CONF_PASSWORD))) File "/config/custom_components/grohe_sense/init.py", line 89, in initialize_shared_objects locations = await auth_session.get(BASE_URL + f'locations') File "/config/custom_components/grohe_sense/init.py", line 144, in get return await self._http_request(url, auth_token=self, **kwargs) File "/config/custom_components/grohe_sense/init.py", line 157, in _http_request token = await auth_token.token() File "/config/custom_components/grohe_sense/init.py", line 133, in token refresh_response = await self._http_request(BASE_URL + 'oidc/refresh', 'post', headers=headers, json=data) File "/config/custom_components/grohe_sense/init.py", line 170, in _http_request raise OauthException(response.status, await response.text()) custom_components.grohe_sense.OauthException: (401, '{"code":401,"message":"Unauthorized - The token was not validated by the Identity Provider"}')

peternorlander commented 1 year ago

Hi again,

I restarted my HA again today and then the token was generated successfully again, no errors.

I can also confirm that I only get updates upon restarting HA. Water usage has only been updated those few times that I have restarted.

Regarding the discussion about the notifications from "my guard". It has now been updated to instead say "Maximum volume reached Maximum volume reached" and that was actually the last notification I got, but that warning was triggered the day before. So that notification has been cleared in the app and should no longer be visible. image

peternorlander commented 1 year ago

Hi Cosmin,

Finally got some time now during the summer? Nice! I know the feeling! :)

I installed your fixes but now it won't run for me? Can I extend the logs somehow because this is all I get: image

And all Grohe entities has been removed image

Any idea?

rusucosmin commented 1 year ago

HI! Just fixed this. We'll have to wait a few days for the refresh token to expiry before we can see if this works or not

peternorlander commented 1 year ago

Hi Cosmin,

I pulled your fix and now the integration loads correctly again. But I still see the same behavior as I had last:

  1. The usage value seems to be stale, hasn't updated now for 2 hours even though it is changed in the app.
  2. It shows me an old value for the notification. The "Maximum volume reached" warning I got here two days ago and it has been cleared in the app so it shouldn't be showing here.

image

peternorlander commented 1 year ago

Hi Cosmin,

I still have the same values, same values as yesterday. But just to be straight with you, I had the same issues with the other main branch as well. So I can just confirm that I don't need to get a token manually anymore, but it doesn't make the integration much more useful for me.

Do you have the same behavior? Or how often does it update for you?

Regards Peter

rusucosmin commented 1 year ago

Yeah - I have the same behaviour. Will check it out next week.

Best, Cosmin

On Thu, Jul 20, 2023 at 21:35 Peter Norlander @.***> wrote:

Hi Cosmin,

I still have the same values, same values as yesterday. But just to be straight with you, I had the same issues with the other main branch as well. So I can just confirm that I don't need to get a token manually anymore, but it doesn't make the integration much more useful for me.

Do you have the same behavior? Or how often does it update for you?

Regards Peter

— Reply to this email directly, view it on GitHub https://github.com/gkreitz/homeassistant-grohe_sense/pull/31#issuecomment-1644407040, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLVW55FTOSVYVJ5QKQW363XRF26ZANCNFSM6AAAAAAYRFQI2U . You are receiving this because you were mentioned.Message ID: @.***>

-- Best, Cosmin

peternorlander commented 1 year ago

Hi Cosmin,

I updated HA from 2023.7 to 2023.8 the evening of the 17:th and after that it suddenly started to work! Now the water values has been updated very well! Check below for history! :) So right now the only thing that seems off is that notification for the main unit. I don't have any notifications that are unread (I used the app to scroll back all notifications until the date of setup and verified) but it still gives me notifications.

But I would like to vote that this PR gets merged with the master branch!

image

image

Regards Peter