CJNE / ha-porscheconnect

Porsche Connect custom component for Home Assistant
MIT License
29 stars 12 forks source link

Integration not functional: TypeError: 'HassLogger' object is not callable #187

Closed browetd closed 1 year ago

browetd commented 1 year ago

Version of the custom_component

0.0.15

Configuration

Using the integration... no yaml

Describe the bug

Integration loaded at boot but after some time, I am getting an error and no way to have the integration up and running...

Debug log

2023-06-15 22:23:23.503 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry <email_removed> for porscheconnect
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/porscheconnect/__init__.py", line 94, in async_setup_entry
    access_tokens = await controller.getAllTokens()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/client.py", line 32, in getAllTokens
    return await self._connection.getAllTokens()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/connection.py", line 195, in getAllTokens
    token = await self._requestToken(application)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/connection.py", line 202, in _requestToken
    await self._login()
  File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/connection.py", line 118, in _login
    _LOGGER("We already have a code in session, skip login")
TypeError: 'HassLogger' object is not callable
steffenhoelle commented 1 year ago

Same issue here with 0.0.15

qazqazie commented 1 year ago

same issue for me.

Home Assistant Core Error setting up email@email.com for porscheconnect 07:56:20 – (ERROR) Porsche Connect (custom integration) Unexpected error fetching porscheconnect data: 'HassLogger' object is not callable 07:51:20 – (ERROR) Porsche Connect (custom integration) - message first occurred at 15 June 2023 at 23:08:13 and shows up 98 times Error requesting porscheconnect data: Cannot connect to host api.porsche.com:443 ssl:default [Try again] 15 June 2023 at 22:48:06 – (ERROR) Porsche Connect (custom integration) - message first occurred at 15 June 2023 at 22:27:47 and shows up 2 times Waiting on integrations to complete setup: onvif, device_tracker.porscheconnect 15 June 2023 at 22:07:32 – (WARNING) bootstrap.py

browetd commented 1 year ago

I restarted HA this evening on one instance out of two and everything went fine for the integration... I can even reload the integration without error... but on the other hand, the same integration for the same account/car on the other instance (same HA version, OS and so on) is still giving me an error... no way to reload it... So I decided to restart this instance as well, and the integration went up also without problem... So it seems that something is happening to have this error message and no way to reload the integration without restarting HA... I will keep one of my instance in debug mode for this integration to hopefully trap the root cause of this issue...

browetd commented 1 year ago

Here is the result of the debug.... Seems to work ok and then for any reason the hasslogger issue is appearing every 5 minutes...

2023-06-17 00:04:47.882 DEBUG (MainThread) [custom_components.porscheconnect] Finished fetching porscheconnect data in 1.740 seconds (success: True) 2023-06-17 00:09:48.890 DEBUG (MainThread) [custom_components.porscheconnect] Finished fetching porscheconnect data in 1.748 seconds (success: True) 2023-06-17 00:14:50.022 DEBUG (MainThread) [custom_components.porscheconnect] Finished fetching porscheconnect data in 1.879 seconds (success: True) 2023-06-17 00:19:52.032 DEBUG (MainThread) [custom_components.porscheconnect] Finished fetching porscheconnect data in 1.890 seconds (success: True) 2023-06-17 00:24:53.944 DEBUG (MainThread) [custom_components.porscheconnect] Finished fetching porscheconnect data in 1.802 seconds (success: True) 2023-06-17 00:29:53.455 ERROR (MainThread) [custom_components.porscheconnect] Unexpected error fetching porscheconnect data: 'HassLogger' object is not callable Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 283, in _async_refresh self.data = await self._async_update_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/porscheconnect/init.py", line 256, in _async_update_data vdata = await self._update_data_for_vehicle(vehicle) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/porscheconnect/init.py", line 146, in _update_data_for_vehicle services = await self.controller.getServices(vin) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/client.py", line 484, in getServices data = await self._connection.get( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/connection.py", line 233, in get headers = await self._createhead(application) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/connection.py", line 287, in _createhead token = await self._requestToken( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/connection.py", line 202, in _requestToken await self._login() File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/connection.py", line 118, in _login _LOGGER("We already have a code in session, skip login") TypeError: 'HassLogger' object is not callable 2023-06-17 00:29:53.463 DEBUG (MainThread) [custom_components.porscheconnect] Finished fetching porscheconnect data in 0.321 seconds (success: False) 2023-06-17 00:34:53.406 ERROR (MainThread) [custom_components.porscheconnect] Unexpected error fetching porscheconnect data: 'HassLogger' object is not callable Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 283, in _async_refresh self.data = await self._async_update_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/porscheconnect/init.py", line 256, in _async_update_data vdata = await self._update_data_for_vehicle(vehicle) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/porscheconnect/init.py", line 146, in _update_data_for_vehicle services = await self.controller.getServices(vin) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/client.py", line 484, in getServices data = await self._connection.get( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/connection.py", line 233, in get headers = await self._createhead(application) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/connection.py", line 287, in _createhead token = await self._requestToken( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/connection.py", line 202, in _requestToken await self._login() File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/connection.py", line 118, in _login _LOGGER("We already have a code in session, skip login") TypeError: 'HassLogger' object is not callable

CJNE commented 1 year ago

The root cause for this is that the auth backend sometimes presents a captcha, we are trying to figure out how to get around that, might be problematic though.

tonycoupland commented 1 year ago

This error - when happens during inital setup - looks to block the creation of the devices (at least I assume why no devices have been created). Should I just keep reloading the integration to try to get it to succeed? I wonder if there is a way to route the HTML provided for CAPTCHA to the HA UI for the user to interact with?

danielpervan commented 1 year ago

It seems like a full restart of HA temporarily fixes the problem. Then after about an hour, this error occurs and the integration becomes unavailable.

Is it possible to get a status update whether a fix might be coming or did Porsche's changes kill the project? @CJNE

It's a very convenient integration so it would be a real shame to lose it.

barto64 commented 1 year ago

Thinking loudly .....

@CJNE & HA Porsche fans,

Not sure if you or someone have reached out to Porsche directly asking them to make some sort of change on their endpoint to allow our HA to connect on a more IoT fashion way rather than on a normal end user one.

Rationale would be that HA is a community (according to HA analytics) of more than 250k people around the globe, with many of them being Porsche's clients. Unfortunately we cannot see how many of us have the custom component installed.

Additionally we could (each of us) email Porsche to a given centralized email address asking for that IoT style connectivity feature to be enabled. At the end of the day, more and more brands are enabling this type of IoT oriented type of connections.

As I said, thinking loudly

Thanks 👍

tonycoupland commented 1 year ago

I pulled the code down for this client to see if I could help diagnose the issue and although I've not got a solution, I might have made a change that has made my integration work at least a little better (its been connected for an hour which it hadn't done before).

I modified locally the custom_components/porscheconnect/__init__.py file and changed the country and locale to gb in case the reason it was kicking out to capcha because the country didn't match the query location... oddly after changing these, I've managed to connect.

Like I say, not a solution, but maybe interesting... will update if it remains connected or if it disconnects and gets into the failure state again

[update] clearly spoke too soon... within about 6 hours it had started failing again 😢

jamesahendry commented 1 year ago

I just tried the same thing then tried AU for Australia which is where I reside on the off chance that Porsche geo block the account or something. No dice - can't even get the integration to load still

tonycoupland commented 1 year ago

I wonder if its the same underlying issue as described here - https://github.com/evcc-io/evcc/issues/9274

No solution in sight, but could be related to refreshing the access token and their API perhaps changing recently

tonycoupland commented 1 year ago

Between bits of work I’ve been looking at this issue and couldn’t make sense of why it would run reliably all day from a terminal but not when inside HASS… today, while looking around through the packages this component is built from I worked it out… and was the 2nd person to do so!

This library builds on top of @CJNE s other library https://github.com/CJNE/pyporscheconnectapi which has recently (2 versions ago) had a fix for a typo in the line of code that is crashing here, there is currently an MR waiting to bump this version up but until that happens you can manually fix your instance by upping the version of that library to be 0.1.5 on this line https://github.com/CJNE/ha-porscheconnect/blob/main/custom_components/porscheconnect/manifest.json#L10

I’ve been getting updates for over two hours now… but hopefully this is now as stable as the local terminal-running version.

browetd commented 1 year ago

@tonycoupland Thank you for your fix... I implemented it yesterday night and 9 hours later, the integration is still up and running... This seems to have fixed the issue... Thanks !

jem commented 1 year ago

@tonycoupland thank you very much for writing that! I have implemented also, and will report back

barto64 commented 1 year ago

@tonycoupland , thanks also for the proposal, I made the change and is working fine now for more than 24h

CJNE commented 1 year ago

Sorry for the lack of updates, the PR has been merged and a new release is out.