Thomas55555 / husqvarna_automower

Custom component for Home Assistant to monitor and control your Husqvarna Automower
https://github.com/Thomas55555/husqvarna_automower
MIT License
105 stars 28 forks source link

No entity created, IndexError: list index out of range #554

Closed CreateYourAccount-username closed 10 months ago

CreateYourAccount-username commented 10 months ago

Prerequirements [✅] I have connected my mower(s) to the Automower Connect App [✅] I have connected my Husqvanra developers account to the Authentication API [✅] I have connected my Husqvarna developers account to the Automower Connect API

Describe the bug On installing the integration I have no errors. Then when the install completes I have the Husqvarna Automower integration, but it does not create a device/entity.

When I click on CONFIGURE I get ERROR: Config flow could not be loaded: 500 Internal Server Error Server got itself in trouble

Expected behavior I expected the device to be created.

Screenshots

image image

Additional context I have had this integration up and running in the past. But when I got the reauthenticate error months ago I could not fix it and deleted it. So currently I am trying to reinstall. I cannot find any entities left over from the previous install. I have removed the integration and rebooted a few times to no avail. Also when the integration was removed I made sure the credentials were deleted. Also made sure all files were deleted from custom_components dir. With the current install I also tried to remove the credentials and configure again to no avail. Curl check as described on Husqvarna Developer Portal works correctly.

Enabled debug logging with following result:

Logger: aiohttp.server
Source: /usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py:403
First occurred: 21:01:04 (1 occurrences)
Last logged: 21:01:04

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/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 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 213, in post
    return await super().post(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 71, in post
    result = await self._flow_mgr.async_init(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 255, in async_init
    flow = await self.async_create_flow(handler, context=context, data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1868, in async_create_flow
    return handler.async_get_options_flow(entry)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/husqvarna_automower/config_flow.py", line 114, in async_get_options_flow
    return OptionsFlowHandler(config_entry)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/husqvarna_automower/config_flow.py", line 177, in __init__
    self.sel_mower_id = self.mower_idx[0]["id"]
                        ~~~~~~~~~~~~~~^^^
IndexError: list index out of range
lachu2 commented 10 months ago

I have the same problem with my integration - it was working fine, 2 days ago entities become unavailable and I get the same error (500).

Thomas55555 commented 10 months ago

I've tried to reproduce this. But I don't get this error. It looks for me like a server-side problem. Maybe you can try again. And if it still doesn't work ask Husqvarna, if they have an idea?

CreateYourAccount-username commented 10 months ago

I've tried to reproduce this. But I don't get this error. It looks for me like a server-side problem. Maybe you can try again. And if it still doesn't work ask Husqvarna, if they have an idea?

Before I contact Husqvarna, can I just check something with you (or someone else if anyone else is reading)? My knowledge of APIs is extremely limited and have very basic knowledge of Python etc. But with help of the API section on the Husqvarna Developer website I managed to authenticate myself and get a token. With this token I can request a list of all my mowers --> GET /mowers. I do get a valid 200 response, but it is an empty list:

{ "data": [] }

I'm assuming this is where the fault comes from as it cannot select index 0 from an empty list. Could you show me what your (or another) valid GET /mowers result looks like?

(edit: Apologies I marked it as 'not planned' and then reopened. Not sure how to remove that. n00b on GitHub...)

Thomas55555 commented 10 months ago

Something like this: https://github.com/Thomas55555/husqvarna_automower/blob/8c72c1a7960c5e1f984d983f2229fa1128a6d70b/custom_components/husqvarna_automower/tests/const.py#L48

What is the automower connect app showing?

CreateYourAccount-username commented 10 months ago

Something like this:

https://github.com/Thomas55555/husqvarna_automower/blob/8c72c1a7960c5e1f984d983f2229fa1128a6d70b/custom_components/husqvarna_automower/tests/const.py#L48

What is the automower connect app showing?

Thanks for that.

Connect app is working perfectly. I'll see if I can get an answer out of Husqvarna...

CreateYourAccount-username commented 10 months ago

Got a reply from Husqvarna that put me on the right track. I had made a developer account with a different email address in the past. So I had 2 accounts. When I logged in recently, the browser these newer credentials were used so the email for Developer Account and Automower App did not match. Hence the empty list as the Developer Account had no mowers.

In summary, user error!