Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication using Husqvarna-API takes endless... #187

Open
jacky-coke opened this issue Jan 4, 2024 · 21 comments
Open

Authentication using Husqvarna-API takes endless... #187

jacky-coke opened this issue Jan 4, 2024 · 21 comments

Comments

@jacky-coke
Copy link

....and I really mean: ENDLESS!
Ongoing since 3 days (yes, I forgot about it 🙈)

image

Any suggestions?

@grm
Copy link
Contributor

grm commented Jan 4, 2024

Yes, it seem very long foir the integration to connect :)

Could you put the plugin in debug mode and share the home assistant logs please ?

@jacky-coke
Copy link
Author

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: gardena.smart_system
Source: custom_components/gardena_smart_system/init.py:86
Integration: Gardena Smart System integration (documentation, issues)
First occurred: 20:57:31 (9 occurrences)
Last logged: 20:59:42

404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']}

@grm
Copy link
Contributor

grm commented Jan 4, 2024

Hum, have you activated the authentication api in the husqvarna website ?

Did you set the level of the logs to debug for the plugin ? (think about hiding/masking your client id client secret if there are in the logs).

@jacky-coke
Copy link
Author

jacky-coke commented Jan 4, 2024

Not sure what especially you mean:
After creating the application, I added "Gardena smart system API" as well so I see this:
image

Also not used to work with HA logs yet; all I could get out is the following:

2024-01-04 20:57:31.009 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']} 2024-01-04 20:57:31.010 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 0.1s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations' 2024-01-04 20:57:31.232 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']} 2024-01-04 20:57:31.233 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 1.1s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations' 2024-01-04 20:57:32.417 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']} 2024-01-04 20:57:32.418 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 0.6s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations' 2024-01-04 20:57:33.161 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']} 2024-01-04 20:57:33.162 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 4.4s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations' 2024-01-04 20:57:37.679 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']} 2024-01-04 20:57:37.680 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 14.7s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations' 2024-01-04 20:57:52.569 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']} 2024-01-04 20:57:52.570 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 3.8s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations' 2024-01-04 20:57:56.526 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']} 2024-01-04 20:57:56.527 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 25.7s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations' 2024-01-04 20:58:22.518 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']} 2024-01-04 20:58:22.519 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 79.5s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations' 2024-01-04 20:59:42.215 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']} 2024-01-04 20:59:42.216 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 200.5s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations' 2024-01-04 21:03:02.912 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']} 2024-01-04 21:03:02.913 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 186.0s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations' 2024-01-04 21:06:09.215 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']} 2024-01-04 21:06:09.216 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 895.9s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations' 2024-01-04 21:07:02.661 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry for gardena_smart_system File "/usr/local/lib/python3.11/site-packages/gardena/smart_system.py", line 141, in __call_smart_system_get File "/usr/local/lib/python3.11/site-packages/gardena/smart_system.py", line 131, in __response_has_errors httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations' File "/config/custom_components/gardena_smart_system/__init__.py", line 49, in async_setup_entry await gardena_system.start() File "/config/custom_components/gardena_smart_system/__init__.py", line 86, in start File "/usr/local/lib/python3.11/site-packages/gardena/smart_system.py", line 146, in update_locations

Oh, this time I'm getting at least some feedback:

image

@schluetter
Copy link

schluetter commented Jan 12, 2024

I have the same problem, I deactivated the integration for now (as there's not much gardening going on currently). The Husqvarna Website is not too snappy either, but I can login there and the example 'curl' commands for my application get me an authorization token.

But when I try the OpenAPI SwaggerUI at https://developer.husqvarnagroup.cloud/apis/gardena-smart-system-api?tab=openapi, I also get errors - usually "TypeError: Load failed":

image

Using curl from my machine, this one yields something:

$ curl -X 'GET' \ 'https://api.smart.gardena.dev/v1/health' \ -H 'accept: */*'

Yes I am alive%

So it seems as if Husqvarna/Gardena did something with their API, although I don't know what. Somehow my authentication doesn't seem to work, as I can use the "authorize" button on the SwaggerUI, but there I won't get any valid response (again: "TypeError: Load failed"). But using curl (redacted API key here, but I used mine from the Website) I get:

curl -X 'GET' \ 'https://api.smart.gardena.dev/v1/locations' \ -H 'accept: application/vnd.api+json' \ -H 'X-Api-Key: 12345678-0000-0000-0000-701ee3456666'

{"message":"Unauthorized"}%

@grm
Copy link
Contributor

grm commented Jan 20, 2024

hum, that is a strange behaviour.

I am not sure the health endpoint requires a token.
Have you tried to renew your token ?

@grm
Copy link
Contributor

grm commented Jan 20, 2024

__call_smart_system_get

After creating the application, I added "Gardena smart system API" as well so I see this:

Yes, I was talking of these 2 APIs

@schluetter
Copy link

hum, that is a strange behaviour.

I am not sure the health endpoint requires a token. Have you tried to renew your token ?

What I wanted to say is, that the API call via curl does work (without authentication when checking the 'health' endpoint), but their website - or the SwaggerUI frontend on the site - does not work. I can generate new authentication Tokens via curl, but they can't be used within the SwaggerUI, always resulting in the error message "TypeError: LoadFailed". Even when I authorize with both API key (see below) and a fresh token.

I generated a new client secret and tried again, which did get me a fresh token. My main problem was choosing the right UUID for the API key. In the documentation they call it , but it is not the "client secret", it's the "client id" from the developer portal. When I tried to use that, it did indeed work - but I don't have any locations set up yet:

curl -X 'GET' \ 'https://api.smart.gardena.dev/v1/locations' \ -H 'accept: application/vnd.api+json' \ -H 'X-Api-Key: <redacted, the client_id>' \ -H 'Authorization: Bearer eyJhbGci...5362KPPn'

{"errors":[{"id":"<another UUID>","status":"Not Found","title":"List Locations","detail":"No locations found for user: <redacted>"}]}%

So maybe the lag in the HomeAssistant integration might come from that.

@andrepura
Copy link

i have the same issue here. try to connect to api does not work

Source: config_entries.py:406
First occurred: 09:37:23 (2 occurrences)
Last logged: 09:43:24

Error setting up entry for gardena_smart_system
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/backoff/_async.py", line 151, in retry
    ret = await target(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/gardena/smart_system.py", line 141, in __call_smart_system_get
    if self.__response_has_errors(response):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/gardena/smart_system.py", line 131, in __response_has_errors
    response.raise_for_status()
  File "/usr/local/lib/python3.11/site-packages/httpx/_models.py", line 759, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 406, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gardena_smart_system/__init__.py", line 49, in async_setup_entry
    await gardena_system.start()
  File "/config/custom_components/gardena_smart_system/__init__.py", line 86, in start
    await self.smart_system.update_locations()
  File "/usr/local/lib/python3.11/site-packages/gardena/smart_system.py", line 146, in update_locations
    response_data = await self.__call_smart_system_get(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/backoff/_async.py", line 183, in retry
    await asyncio.sleep(seconds)
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 649, in sleep
    return await future
           ^^^^^^^^^^^^
asyncio.exceptions.CancelledError: Global task timeout

@Slowmover321
Copy link

Same here. No luck installing the api, takes forever until it falls.

@Tintan-S
Copy link

Tintan-S commented Feb 2, 2024

I have this Problem too. I installed the api again, deleted the authentication and tied to register ha again.

The connection originally worked, then I had to change the gateway because the mower had a defect and was replaced. I deleted the old gateway and could not connect the new gateway. I get the same error after endless authentication.

@grm
Copy link
Contributor

grm commented Feb 9, 2024

Could you give it another try woth latest version please ? (1.1.0-rc3)

@grm
Copy link
Contributor

grm commented Feb 10, 2024

I just released version 1.1.0.

Can you try with this version please ?

@andrepura
Copy link

i had no luck. you can find the log attached. @grm : thank you for your support!

2024-02-11 19:54:13.609 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry  for gardena_smart_system
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/backoff/_async.py", line 151, in retry
    ret = await target(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/gardena/smart_system.py", line 141, in __call_smart_system_get
    if self.__response_has_errors(response):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/gardena/smart_system.py", line 131, in __response_has_errors
    response.raise_for_status()
  File "/usr/local/lib/python3.11/site-packages/httpx/_models.py", line 759, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 406, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gardena_smart_system/__init__.py", line 49, in async_setup_entry
    await gardena_system.start()
  File "/config/custom_components/gardena_smart_system/__init__.py", line 86, in start
    await self.smart_system.update_locations()
  File "/usr/local/lib/python3.11/site-packages/gardena/smart_system.py", line 146, in update_locations
    response_data = await self.__call_smart_system_get(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/backoff/_async.py", line 183, in retry
    await asyncio.sleep(seconds)
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 649, in sleep
    return await future
           ^^^^^^^^^^^^
asyncio.exceptions.CancelledError
2024-02-11 19:54:28.339 DEBUG (MainThread) [custom_components.gardena_smart_system] Setting up Gardena Smart System component
2024-02-11 19:54:28.339 DEBUG (MainThread) [custom_components.gardena_smart_system] Starting GardenaSmartSystem
2024-02-11 19:54:28.899 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']}
2024-02-11 19:54:28.899 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 0.1s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404)
2024-02-11 19:54:29.143 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']}
2024-02-11 19:54:29.143 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 1.4s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404)
2024-02-11 19:54:30.773 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']}
2024-02-11 19:54:30.773 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 3.3s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404)
2024-02-11 19:54:34.207 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: gardena_smart_system
2024-02-11 19:54:34.294 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']}
2024-02-11 19:54:34.294 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 7.6s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404)
2024-02-11 19:54:42.026 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']}
2024-02-11 19:54:42.026 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 5.0s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404)
2024-02-11 19:54:47.275 ERROR (MainThread) [gardena.smart_system] 404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']}
2024-02-11 19:54:47.276 INFO (MainThread) [gardena.smart_system] Backing off __call_smart_system_get(...) for 16.9s (httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://api.smart.gardena.dev/v1/locations'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404)

@Slowmover321
Copy link

For me as well, results are the same errors as posted above. My logs looks the same.

@Slowmover321
Copy link

Got it working… email adresses for Gardena Gateway and husqvarna API Must be the same, otherwise you get in the endless authentification loop

@andyblac
Copy link

same issue here, email is the same for app and API

@andyblac
Copy link

andyblac commented Sep 3, 2024

any update on this issue ?

This error originated from a custom integration.

Logger: gardena.smart_system
Source: custom_components/gardena_smart_system/__init__.py:87
integration: Gardena Smart System integration (documentation, issues)
First occurred: 10:27:06 (9 occurrences)
Last logged: 10:29:36

404 : {r['errors'][0]['title']} - {r['errors'][0]['detail']}

@grm
Copy link
Contributor

grm commented Sep 3, 2024

Got it working… email adresses for Gardena Gateway and husqvarna API Must be the same, otherwise you get in the endless authentification loop

I was not aware of that ! That is a very strange behaviour ...
Thanks. for the info @Slowmover321 :)

@andyblac can you it a try to see if that solve your issue ? Or is it not your case ?

The 404 seems very odd, as this is a standard endpoint and is not spefic to your context (especially for the token) which may. why the solution from @Slowmover321 may work.

@andyblac
Copy link

andyblac commented Sep 3, 2024

Got it working… email adresses for Gardena Gateway and husqvarna API Must be the same, otherwise you get in the endless authentification loop

I was not aware of that ! That is a very strange behaviour ... Thanks. for the info @Slowmover321 :)

@andyblac can you it a try to see if that solve your issue ? Or is it not your case ?

The 404 seems very odd, as this is a standard endpoint and is not spefic to your context (especially for the token) which may. why the solution from @Slowmover321 may work.

It already uses the same address for both, so is not relevant to my issue.

@andyblac
Copy link

andyblac commented Sep 3, 2024

ok I just deleted my account from both dev and main husqvarnagroup and then setup them from scratch, that seemed to have sorted it, I can now use the integration, so it must have been a server side issue.

Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants