py-smart-gardena / hass-gardena-smart-system

Home Assistant custom component integration for Gardena Smart System
Apache License 2.0
191 stars 46 forks source link

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

Open jacky-coke opened 6 months ago

jacky-coke commented 6 months ago

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

image

Any suggestions?

grm commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 5 months ago

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 commented 5 months ago

hum, that is a strange behaviour.

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

grm commented 5 months ago

__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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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

Tintan-S commented 5 months ago

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 commented 4 months ago

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

grm commented 4 months ago

I just released version 1.1.0.

Can you try with this version please ?

andrepura commented 4 months ago

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 commented 4 months ago

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

Slowmover321 commented 4 months ago

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

andyblac commented 1 month ago

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