basilfx / homeassistant-biketrax

Custom component for the PowUnity BikeTrax integration for Home Assistant.
MIT License
6 stars 2 forks source link

Unexpected Error - Login not working (first time setup) #149

Closed napfkuchen1 closed 2 months ago

napfkuchen1 commented 2 months ago

Hi,

i installed the addon through HACS which went flawless. Restarted HA several times since then. Unfortunately i cannot login to Biketrax and get the "Unexpected Error" Any Ideas?

Here's the log file

Logger: custom_components.biketrax.config_flow
Quelle: custom_components/biketrax/config_flow.py:78
Integration: PowUnity BikeTrax (Dokumentation, Probleme)
Erstmals aufgetreten: 16:10:03 (1 Vorkommnisse)
Zuletzt protokolliert: 16:10:03

Unexpected exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/api.py", line 49, in wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/api.py", line 220, in get_devices
    return [models.device_from_dict(device) for device in response]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/models.py", line 874, in device_from_dict
    return Device.from_dict(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/models.py", line 631, in from_dict
    attributes = DeviceAttributes.from_dict(obj.get("attributes"))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/models.py", line 555, in from_dict
    passport = from_union([Passport.from_dict, from_none], obj.get("passport"))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/models.py", line 30, in from_union
    assert False
           ^^^^^
AssertionError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/biketrax/config_flow.py", line 78, in async_step_user
    info = await validate_input(self.hass, user_input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/biketrax/config_flow.py", line 42, in validate_input
    await account.update_devices()
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/client.py", line 61, in update_devices
    device.id: device for device in await self.traccar_api.get_devices()
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/api.py", line 51, in wrapper
    raise ApiError("Unable to parse API response.") from e
aiobiketrax.exceptions.ApiError: Unable to parse API response.

Many Thanks!

basilfx commented 2 months ago

Can you enable debug logging? See https://github.com/basilfx/homeassistant-biketrax?tab=readme-ov-file#debug-logging and https://github.com/basilfx/aiobiketrax?tab=readme-ov-file#debugging for more information.

napfkuchen1 commented 2 months ago

As the integration is not visible without logging in I think this is all I got

basilfx commented 2 months ago

You might be more successful using the regular logging configuration: https://www.home-assistant.io/integrations/logger/

napfkuchen1 commented 2 months ago

I think I cant get the output you are needing. This is what is able to be seen in the logs, still

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: custom_components.biketrax.config_flow
Quelle: custom_components/biketrax/config_flow.py:78
Integration: PowUnity BikeTrax (Dokumentation, Probleme)
Erstmals aufgetreten: 10:50:32 (4 Vorkommnisse)
Zuletzt protokolliert: 11:07:42

Unexpected exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/api.py", line 49, in wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/api.py", line 220, in get_devices
    return [models.device_from_dict(device) for device in response]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/models.py", line 874, in device_from_dict
    return Device.from_dict(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/models.py", line 631, in from_dict
    attributes = DeviceAttributes.from_dict(obj.get("attributes"))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/models.py", line 555, in from_dict
    passport = from_union([Passport.from_dict, from_none], obj.get("passport"))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/models.py", line 30, in from_union
    assert False
           ^^^^^
AssertionError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/biketrax/config_flow.py", line 78, in async_step_user
    info = await validate_input(self.hass, user_input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/biketrax/config_flow.py", line 42, in validate_input
    await account.update_devices()
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/client.py", line 61, in update_devices
    device.id: device for device in await self.traccar_api.get_devices()
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiobiketrax/api.py", line 51, in wrapper
    raise ApiError("Unable to parse API response.") from e
aiobiketrax.exceptions.ApiError: Unable to parse API response.

This is what my Logger is configured to:


logger:
  default: debug
  logs:
    custom_components.biketrax: debug
    custom_components.aiobiketrax.api: debug
    custom_components.aiobiketrax.api.responses: debug
    custom_components.aiobiketrax.api.client: debug
basilfx commented 2 months ago

I see. It fails because the response data is not what is expected for the passport details. It should be an object, and look like this.

Try to go into the PowUnity app, and change some of the passport details of your bicycle. I presume that will fix it. If not, than I would need the raw responses to know exactly what is in there.

napfkuchen1 commented 2 months ago

This solved the issue! Thank you :)

basilfx commented 2 months ago

Good to hear!

PowUnity's API is not so strict and returns all kinds of (unexpected) responses if not properly initialized. It becomes difficult when reverse engineering, sometime ;-)