ekutner / home-connect-hass

Alternative (and improved) Home Connect integration for Home Assistant
MIT License
549 stars 54 forks source link

Status : LOADING_FAILED #215

Closed tagcashdev closed 9 months ago

tagcashdev commented 1 year ago

BUG (Status : LOADING_FAILED)

After adding home connect alt from HACS, then creating the Application on the home connect developer account, I added ls info in the configuration file as described in the instructions. I then added a new home connect alt integration from "Device and services" connection to the home connect site back connection OK everything works fine until I restart my raspberry pi... after restart... status LOADING_FAILED .. .I waited several minutes .... hours .... day ... but despite some "INIT" status from time to time the status returns to LOADING_FAILED

I then added a new home connect alt integration then deleted the old one READY again but after a few hours back to LOADING_FAILED often after restarting home_assistant but it already happened without restarting...

Result : Entities of all appliance are unavailable :(

entityState ActualState historyStates

Version of the custom_component

0.6.1

Configuration


# Loads default set of integrations. Do not remove.
wake_on_lan:
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

device_tracker:
  ### BLUETOOTH LE ###
  - platform: bluetooth_le_tracker
    consider_home: 180
    interval_seconds: 60
    new_device_defaults:
      track_new_devices: true
  ### BLUETOOTH ###
  - platform: bluetooth_tracker
    consider_home: 180
    interval_seconds: 60
    new_device_defaults:
      track_new_devices: true

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
template: !include templates.yaml
proximity: !include proximity.yaml

home_connect_alt:
  client_id: !secret home_connect_alt_client_id
  client_secret: !secret home_connect_alt_client_secret
  sensor_value_translation: server
  language: fr

Debug log

home_connect_async.common.HomeConnectError: ('Failed to get a valid response from Home Connect server', 902, None, None, None)
tagcashdev commented 1 year ago

I have already tried the following configurations:

home_connect_alt: client_id: !secret home_connect_alt_client_id client_secret: !secret home_connect_alt_client_secret

home_connect_alt: client_id: !secret home_connect_alt_client_id client_secret: !secret home_connect_alt_client_secret language: fr

Nurgus commented 1 year ago

I updated Home Assistant to 2023.5.0 this morning and now I too have this (similar?) problem.

If I click "Check Configuration" I get "Component error: home_connect_alt - No module named 'marshmallow_enum'", do you have the same message?

ekutner commented 1 year ago

@tagcashdev This indicates a problem with getting API responses from HC. If you have a firewall with some kind of URL filtering then try disabling it. Otherwise add log_mode: 7 to the home_connect_alt section of your configuration and upload the complete log file.

@Nurgus That version is working fine for me so it's not related. The "check configuration" is a HA feature, it's not using any of the integration's code so if that is showing an issue then there is something wrong with your HA. You can try removing the home_connect_alt section from the config and test again. My guess is that it will show an error on something else. Either way, this is not related to this issue so if you can't figure it out yourself then please open a separate issue for it.

JohnMoor commented 1 year ago

I have the same problem. added the log_mode:7 to config. Here is the relevante output of the log:

2023-08-06 12:41:23.518 WARNING (MainThread) [home_connect_async.homeconnect] Failed to load data from Home Connect (('Failed to get a valid response from Home Connect server', 902, None, None, None))
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/home_connect_async/homeconnect.py", line 139, in async_load_data
    response = await self._api.async_get('/api/homeappliances')
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/home_connect_async/api.py", line 118, in async_get
    return await self._async_request('GET', endpoint)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/home_connect_async/api.py", line 113, in _async_request
    raise HomeConnectError("Failed to get a valid response from Home Connect server", 902)
home_connect_async.common.HomeConnectError: ('Failed to get a valid response from Home Connect server', 902, None, None, None)
2023-08-06 12:41:23.526 ERROR (MainThread) [custom_components.home_connect_alt] Failed to load data for the HomeConnect object
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/home_connect_async/homeconnect.py", line 139, in async_load_data
    response = await self._api.async_get('/api/homeappliances')
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/home_connect_async/api.py", line 118, in async_get
    return await self._async_request('GET', endpoint)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/home_connect_async/api.py", line 113, in _async_request
    raise HomeConnectError("Failed to get a valid response from Home Connect server", 902)
home_connect_async.common.HomeConnectError: ('Failed to get a valid response from Home Connect server', 902, None, None, None)
JohnMoor commented 1 year ago

I think this error was caused by the new SingleKey ID sign-in requirement, once going through the steps I got it to authenticate.

raducotescu commented 1 year ago

I actually experience this issue on my instance and I don't think it has anything to do with the SingleKey migration, since I've performed that months ago and the integration has stopped working only a few days ago.

Adding log_mode:7 to the config didn't improve the OOTB verbosity of the logging, but once I've switched the relevant loggers to debug I've found this:

2023-08-25 16:23:33.512 DEBUG (MainThread) [home_connect_async.api]
HTTP GET /api/homeappliances (try=1 count=1)

2023-08-25 16:23:33.707 DEBUG (MainThread) [home_connect_async.api] HTTP call failed GET /api/homeappliances
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/home_connect_async/api.py", line 66, in _async_request
    response = await self._auth.request(method, endpoint, self._lang,  data=data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/home_connect_async/auth.py", line 39, in request
    access_token = await self.async_get_access_token()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/home_connect_alt/api.py", line 28, in async_get_access_token
    await self._oauth_session.async_ensure_token_valid()
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 499, in async_ensure_token_valid
    new_token = await self.implementation.async_refresh_token(self.token)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 92, in async_refresh_token
    new_token = await self._async_refresh_token(token)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 182, in _async_refresh_token
    new_token = await self._token_request(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 209, in _token_request
    resp.raise_for_status()
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 1005, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('https://api.home-connect.com/security/oauth/token')

@ekutner, since I'm not familiar with the API, could you please check if there were any API changes recently and the API client you use is maybe behind?

raducotescu commented 1 year ago

I've debugged a bit more and this is the error I get:

2023-08-25 20:35:06.517 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Token request failed with status=400, body={
  "error": "invalid_client",
  "error_description": "client has limited user list - user not assigned to client"
}

The API Docs list this as a 302 at https://api-docs.home-connect.com/authorization/#authorization-errors.

raducotescu commented 1 year ago

As much as I wanted to ignore all the comments I saw here and online about the SingleKey ID, guess what?! That's where the bug was coming from. I think they might have changed their code regarding how they encode/decode email addresses. As soon as I changed my email address the integration started working. For the record, it was the + character that threw them off. I've been using that email address for Home Connect for the past 3 years...

Eckart0 commented 1 year ago

Hello,

I have not been able to connect HA to the Home Connect server for a good week now. Therefore, I have initially switched to SingleID. The direct login via HC app works, but the HA login via the Developer page does not.

The log throws the following errors:

File "/usr/local/lib/python3.11/site-packages/home_connect_async/homeconnect.py", line 139, in async_load_data response = await self._api.async_get('/api/homeappliances') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/home_connect_async/api.py", line 118, in async_get return await self._async_request('GET', endpoint) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/home_connect_async/api.py", line 113, in _async_request raise HomeConnectError("Failed to get a valid response from Home Connect server", 902) home_connect_async.common.HomeConnectError: ('Failed to get a valid response from Home Connect server', 902, None, None, None) 2023-08-26 11:52:13.080 WARNING (MainThread) [home_connect_async.homeconnect] Failed to load data from Home Connect (('Failed to get a valid response from Home Connect server', 902, None, None, None)) Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/home_connect_async/homeconnect.py", line 139, in async_load_data response = await self._api.async_get('/api/homeappliances') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/home_connect_async/api.py", line 118, in async_get return await self._async_request('GET', endpoint) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/home_connect_async/api.py", line 113, in _async_request raise HomeConnectError("Failed to get a valid response from Home Connect server", 902) home_connect_async.common.HomeConnectError: ('Failed to get a valid response from Home Connect server', 902, None, None, None)

Any hints on how to fix this? Grüße, Eckart

hpo2342 commented 1 year ago

Finally got it to work again with @raducotescu's hints, thanks! I'll try to add what I would have found helpful.

I found that in the integration page in HA, pressing "add entry" (or similar, using the German translations) leads to the authentication process between the integration and the HC backend. When I entered my HC user account there, it stated it wasn't connected to the app.

So I went to the HC developer portal and logged into my developer account.

There, in my profile, I changed the "Default Home Connect User Account for Testing" to something else (saved!) and then back to my account. The form doesn't check if the account is a valid HC account.

I also added the account as the individual testing account to the app and removed it again.

Then I waited a few minutes, I think this was also necessary during the initial setup.

Then I went back to the integration page in HA and restarted the authentication, which then accepted my user account. Then the integration started working again in HA.

Not sure if all steps are really needed, but given the assumption that the email address might have been corrupted in the database, I figured I should make sure it is rewritten everywhere.

Eckart0 commented 1 year ago

Thank you. I added a new entry in HC developer, chanched the keys in secret.yaml and waited some time. But the integration page in HA throws an error: { "error": "unauthorized_client", "error_description": "client or redirection URI not authorized", "state": "xyxyxyxiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmbG93X2lkIjoiNzk2ZDU0MWM3YzI0NWQyMjNkZmM1ZmMyMWQyYmQxNzAiLCJyZWRpcmVjdF91cmkiOiJodHRwczovL215LmhvbWUtYXNzaXN0YW50LmlvL3JlZGlyZWN0L29hdXRoIn0.fJQRaLbfOn1OTdm99X8R2AYmz2bXpW_rAE0P3" } Do you have any idea? Regards, Eckart

Eckart0 commented 1 year ago

I was in too much of a hurry. After an hour I tried again with "Add entry" and: It worked! Thanks for the hint.

But now another question: I have now from the configuration page of Home Connect Alt two entries: the old not working "Home Connect Appliances" with loud entities with red exclamation mark, and the new one which is also called "Home Connect Appliances", with apparently the same named entities. Can I safely delete the old one or will they both be gone.

Regards, Eckart

raducotescu commented 1 year ago

It started happening again today. The refresh token fails in the same way, although I'm using the new email address like described in https://github.com/ekutner/home-connect-hass/issues/215#issuecomment-1693860578.

Now I'm completely lost as to what the issue could be, but it's definitely a backend problem...

hpo2342 commented 1 year ago

Same here, stopped working again after exactly 24hrs, almost to the second.

Eckart0 commented 1 year ago

Zu früh gefreut, hier geht auch nichts mehr. Too early to rejoice, nothing more works here either.

„LOADING_FAILED“

Regards, Eckart

Von: hpo2342 @.> Gesendet: Sonntag, 27. August 2023 14:34 An: ekutner/home-connect-hass @.> Cc: Eckart0 @.>; Comment @.> Betreff: Re: [ekutner/home-connect-hass] Status : LOADING_FAILED (Issue #215)

Same here, stopped working again after exactly 24hrs, almost to the second.

— Reply to this email directly, view it on GitHub https://github.com/ekutner/home-connect-hass/issues/215#issuecomment-1694656737 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AHCXC4J3OEYMVWQVG76ZIUTXXM5CVANCNFSM6AAAAAAXUSAM5I . You are receiving this because you commented. https://github.com/notifications/beacon/AHCXC4NPVITTOJO7MAFHVYDXXM5CVA5CNFSM6AAAAAAXUSAM5KWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTFAJUOC.gif Message ID: @. @.> >

CV8R commented 1 year ago

Same issue, following.

ekutner commented 12 months ago

This clearly looks like a server side issue but it doesn't happen to me so it's difficult to analyze. Please try adding this to your configuration.yaml or just the last row if you already have the section:

logger:
  default: info
  logs:
    homeassistant.helpers.config_entry_oauth2_flow: debug

Then upload a full log, not only the exception itself.

ekutner commented 11 months ago

So I now had this issue with my test app and was able to see if for my self. The reported error is that there is a problem with the test user associated with the Home Connect developer app (not related to the mobile app). There is obviously no problem with the user and the same user works fine for me in another app. To resolve this issue I went to the app itself and removed the associated test user. This causes the app to use the default user. I then went to my profile page and defined the default test user in there. Those steps have resolved the problem, at least for now.

hpo2342 commented 11 months ago

@ekutner Thanks for checking! Is it still working on your test account? If I read this right those steps fixed it for me as well but only for 24hrs exactly, after which it stopped working again. Those 24hrs have passed now for your attempt, so I imagine it might have stopped working by now.

ekutner commented 11 months ago

Still working, and in fact I waited a couple of days before posting, to make sure it was refreshing the token, so in total it's been working for something like 5 days now. I would also try setting the test user to something bogus, saving everything, wait an hour for the change to propagate through their system then change it back to the real user.

capandcamera commented 11 months ago

I had this issue, i looked into it based on @ekutner's suggestion of the Test Account, and managed to resolve it. My particular issue was that my SingleKey ID email address did not match that of my home-connect API / Test User.

Eckart0 commented 10 months ago

Hello,

I have to come back to this because it still doesn't work for me and I seem to be making mistakes with ekutner's instructions on how to fix it.

My configuration is:

As a test, I tried to use "HomeAssistantAlt" mail1@xxx.de as the test user for the application, i.e. my HC account. But that doesn't work either. Is it nessesarry to have the same user in the SingleKeyID and the Developer app?

What do I have to do differently?

(By the way: I tried to activeate the HA-Core installation "Home Connect". It works fine.)

Many greetings, Eckart Severing

ekutner commented 10 months ago

@Eckart0 The test account should be the HC account that you have configured in the mobile app. You should go into the mobile app and make sure the email address is written in all lowercase characters. If the core integration works then this one would work too, there is no difference in how they authenticate. If you are sure it worked then use the same app credentials.