ekutner / home-connect-hass

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

Setup of integration failing during oauth #207

Closed MittaAxt closed 1 year ago

MittaAxt commented 1 year ago

Describe the bug

New setup with latest HA 2023.4 failing at the end of the integration setup with a 400 bad request I tried to setup the integration for the first time today and created a developer account, created a new application, added https://my.home-assistant.io/redirect/oauth as redirect URL and used the same mail address as user as I'm using in the home connect app. My dryer is configured in the app already and has also access to the internet, checked while using 4G and the home connect app is able to talk to the dryer. At the end of the integration setup, while getting back from the "Link account to home assistant" page (which shows my public URL and port as instance URL), the integration setup just shows "Error"

I assume it has sth to do with the oauth overall and maybe not specific with this integration, but as this is the only integration that I'm using, which uses oauth, I can't say if there is sth missing or maybe wrong with 2023.4

I've restarted HA several times already, deleted and recreated the app in the developer portal and updated the id and secret accordingly in the configuration.yaml, but it always behaves the same.

Version of the custom_component

0.6.1

Configuration

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

http: 
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem

# Text to speech
tts:
  - platform: google_translate

automation: !include_dir_merge_list automations
binary_sensor: !include_dir_list binary_sensors
device_tracker:  !include_dir_list devices
group: !include_dir_named groups
input_boolean: !include input/boolean.yaml
input_select: !include input/select.yaml
input_number: !include input/number.yaml
media_player: !include_dir_list media_players
notify: !include_dir_list notify
scene: !include_dir_list scenes
script: !include_dir_named scripts
sensor: !include_dir_merge_list sensors
shell_command: !include shell_commands.yaml
switch: !include_dir_list switches
template:  
  - binary_sensor: !include_dir_merge_list templates/binary_sensor/
  - sensor: !include_dir_merge_list  templates/sensors/
  - trigger: !include_dir_merge_list templates/trigger/ 
timer: !include_dir_named timers
zone: !include_dir_list zones

home_connect_alt:
  client_id: xxxxxxxxxxxxxxxx
  client_secret: xxxxxxxxxxxxxxxxxx

logger:
  default: info
  logs:
    homeassistant.helpers.config_entry_oauth2_flow: debug
    home_connect_async: debug
    home_connect_alt: debug
    custom_components.home_connect_alt: debug

Debug log

Logger: aiohttp.server
Source: helpers/config_entry_oauth2_flow.py:209
First occurred: 7:34:11 PM (1 occurrences)
Last logged: 7:34:11 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 235, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 171, in get
    return await super().get(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 96, in get
    result = await self._flow_mgr.async_configure(flow_id)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 271, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 315, in async_step_creation
    token = await self.flow_impl.async_resolve_external_data(
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 172, in async_resolve_external_data
    return 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.10/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 commented 1 year ago

Try using your internal address in my.home-assistant.io and make sure you follow the instructions to the letter. Also look for previous issues reporting the same problems. This kind of problem is always the result of a configuration error.

MittaAxt commented 1 year ago

I tried it already, with just using the IP, same result (even if I would expect a different error message, due to a certificate error). I've googled several hours before posting and none of the found "solutions" helped.

Just to be on the safe side, I do not need to have a HA Cloud (Nabu Casa) subscription, correct?

ekutner commented 1 year ago

You don not need a nabu casa subscription. Read this issue #103 Make sure you use you HA internal address both for adding the integration and for setting the HA instance address in my.home-assistant.io

If this doesn't help then please post a screenshot of your HC app config, a screenshot of the my.home-assistant.io page you landed on after completing the authentication process and the full URL of that page (copy from the browser).

MittaAxt commented 1 year ago

looks like it had sth to do with the mail, even if I read that before registering, seems that some autocorrect might have upped the first letter of the mail. I've deleted all accounts and re-registered with the same mail but different +aliases and also used a different developer portal account "name". Got it registered.

Asdrubale1234 commented 1 year ago

I solved it by changing the registration email on home connect and on developers, in short, your email MUST be ALL lowercase

Asdrubale1234 commented 1 year ago

Now i have this error:

Logger: custom_components.home_connect_alt Source: /config/custom_components/home_connect_alt/init.py:132 Integration: Home Connect Alt (documentation, issues) First occurred: 18:43:46 (1 occurrences) Last logged: 18:43:46

Failed to load data for the HomeConnect object Traceback (most recent call last): File "/usr/local/lib/python3.10/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.10/site-packages/home_connect_async/api.py", line 118, in async_get return await self._async_request('GET', endpoint) File "/usr/local/lib/python3.10/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)