Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR (MainThread) [custom_components.porscheconnect] Unexpected error fetching porscheconnect data #242

Open
barto64 opened this issue Jun 12, 2024 · 68 comments
Labels
breaking Breaking Changes

Comments

@barto64
Copy link

barto64 commented Jun 12, 2024

Version of the custom_component

0.0.18

Configuration

Add your logs here.
``2024-06-12 12:33:55.372 ERROR (MainThread) [custom_components.porscheconnect] Unexpected error fetching porscheconnect data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 312, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/porscheconnect/__init__.py", line 211, in _async_update_data
    summary = await self.controller.getSummary(vin)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyporscheconnectapi/client.py", line 484, in getSummary
    data = await self._connection.get(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyporscheconnectapi/connection.py", line 304, in get
    return await resp.json()
           ^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/aiohttp_client.py", line 79, in json
    return await super().json(*args, loads=loads, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1192, in json
    return loads(stripped.decode(encoding))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/json.py", line 48, in json_loads
    return orjson.loads(__obj)  # type:ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^
orjson.JSONDecodeError: unexpected character: line 1 column 1 (char 0)`

## Describe the bug

Integration does not work, device and entities not available.

## Debug log

<!-- To enable debug logs check this https://www.home-assistant.io/components/logger/ -->

```text

Add your logs here.
@augmentedtraffic
Copy link

same with me - looks like Porsche made a big change on their APIs that needs to be reflected

@fredriklj
Copy link
Collaborator

What HA versions are you on?

@barto64
Copy link
Author

barto64 commented Jun 12, 2024 via email

@augmentedtraffic
Copy link

i am using your latest python lib directly. I only stopped by here to see if others are seeing it. I will set up HA later to test as I use it also but just not with this integration. . The normal python lib stopped working Sunday morning early for me EST so I stopped my automatic (hourly) ping. I just realized it actually worked yesterday about 3:40pm EST (I was doing a test), but this morning it had the same error as above. On Sunday I was getting a valid response but effectively empty JSON values. When I log into the Connect web site I get an alert about changes coming (i.e. it looks like they will remove web access and work only via the mobile apps)

@fredriklj
Copy link
Collaborator

I just noticed they have scrapped all remote services from the web access, possibly they have retired all those APIs. In which case we might have some trouble.

@augmentedtraffic
Copy link

that's what I was afraid of. I suppose someone would need to work from the Android app side to see if the mobile APIs can be used. I won't be able to do this, but I would be willing to pay a bounty to someone

@fredriklj
Copy link
Collaborator

This is going to take a while.

@fredriklj
Copy link
Collaborator

I've had a first stab at the new APIs in this branch:

https://github.com/CJNE/pyporscheconnectapi/tree/new_api

It currently only supports authentication and retrieving capabilities and status. And will require significant changes of the HA integration as well.

@augmentedtraffic
Copy link

I can confirm it works thanks so much I will send you an email. Note the JSON is changed quite a bit. I found ChatGPT4o quite useful to rewriting my code and the key functionality is working like before. I still need to do tire pressure and lights control but that is not as key. Really appreciate your efforts on this!

@fredriklj
Copy link
Collaborator

For anyone whose life depend on a (somewhat) functional ha integration, and is prepared to file a pull request to fix any discovered issues, there is work in progress in the new_api branch.

@Jimnaldo
Copy link

@fredriklj is there something we can help with to get it up an running again?

@fredriklj
Copy link
Collaborator

I'd appreciate any help I can get, I have quite limited time to spend on this. I've started to clean up the integration to align it with best current (hass) practices, but could certainly use some help on that. Also, pyporscheconnectapi need an overhaul. So please feel free to dive in!

@fredriklj
Copy link
Collaborator

fredriklj commented Nov 1, 2024

FWIW, I have pushed some changes to the new_api branch which seem to work somewhat reliably, and give you a few more entities in hass.

Please note that you will have to manually make sure to install the development version of pyporscheconnectapi (from new_api branch) into your hass environment before you start hass. Hass will not pull this version of the library automatically.

@fredriklj
Copy link
Collaborator

Hmmmmm !!!! Not sure how I can update it. I mean what I do is to change the manifest file to ensure the "requiremets" section points to the new_api branch for the pyporscheconnectapi. So, supposedly my custom component should use the latest version there is the branch. I do not install it using pip.

I do not update the version numbers as i commit to the development branch, you have to manually wiggle the latestc oode into your hass environment every time you update the component. Its a pain, I know. But this is WIP.

@barto64
Copy link
Author

barto64 commented Nov 6, 2024

Noted and understood, that make sense. I will google how it can be done. Honestly, no idea how to do it. Maybe I can cheat HA by swapping the branch and force it to make updates on the api version.

Pretty conscious it is WIP and trying to help. Great thanks for your efforts.

@fredriklj
Copy link
Collaborator

fredriklj commented Nov 7, 2024

@barto64 Or just use pip to install directly from the directory where you have cloned the git repo.

git pull; pip install .

@a-teece
Copy link

a-teece commented Nov 7, 2024

Would pip uninstall first help to get rid of the old version?

@barto64
Copy link
Author

barto64 commented Nov 7, 2024

Hi @fredriklj and thanks again for your support. Will try to explain to the best of my knowledge given that my skills are not so wide as yours by any means in spite of being a tech person sadly much more involve in management at this stage of my career than in tech stuff which is what i would really like.

The point is that my install as the vast mayority of HA users is "Operating system" as opposed to "Container, Core or Supervised". It makes life super much easier but gives you far less degree of control on what you can do or not. So honestly, i have no idea on how i can manipulate internally the code and libraries of HA. I vaguely recall in the past i was able to do it as there are some tools that you can use for that (although they work only up to the time you reboot again the system). I need to refresh those skills to be able to install and unsintall libraries on my HA DEV instance.

I have pasted the below links to illustrate my comment:
https://analytics.home-assistant.io/#installations
https://www.home-assistant.io/blog/2020/05/26/installation-methods-and-community-guides-wiki/

@fredriklj
Copy link
Collaborator

@barto64 What you need to do, regardless of type of installation, is to manually install the pyporscheconnect package into the hass environment. You would typically do that by "entering" your environment, meaning launching a shell inside your OS, container or venv, clone or update the repo and then install it using pip. This will overwrite the files of the old version of the package and clean what needs to be cleaned.

Then you need to restart your hass (restarting, not rebooting if you are in a container or similar).

@barto64
Copy link
Author

barto64 commented Nov 9, 2024

I have gone into my env using Termius terminal, but any command I try says always command not found. Maybe I must do something else before I do not know.

@royalidea
Copy link

I have gone into my env using Termius terminal, but any command I try says always command not found. Maybe I must do something else before I do not know.

@barto64
You need to install the advanced ssh terminal: https://github.com/hassio-addons/addon-ssh
Then run command docker exec -it homeassistant /bin/bash
If you run pip list | grep pyporscheconnectapi, you should see which version is installed

@barto64
Copy link
Author

barto64 commented Nov 9, 2024

@royalidea , lesson learnt, thanks a lot, each day brings something new :)

I made the above, integration works fine now, i can see a few sensors being delivered. Besides, in DEBUG I can see also far more info about my char which are not yet delivered by the integration. WIP ;)

@fredriklj
Copy link
Collaborator

fredriklj commented Nov 9, 2024

Put your desires on the wish list :-)

@royalidea
Copy link

@barto64 or others, is the data being updated for you? For me it seems to only update when i manually reload the integration.

@Jimnaldo
Copy link

@barto64 or others, is the data being updated for you? For me it seems to only update when i manually reload the integration.

I notice the same behaviour

@barto64
Copy link
Author

barto64 commented Nov 10, 2024

@Jimnaldo , @royalidea I have been running the component on my DEV instance in DEBUG and i could see every 32 min and update being executed.

@fredriklj not sure what is he whish list you refer to. I like very much the sensors and switches the old component provided before Porsche made the changes. So, anything similiar to that would be great. For me personally it was great the ability to execute the Direct Charge as I used to combine different parameters from my solar pannels and home power consumption to force the car charge.

@royalidea
Copy link

@Jimnaldo , @royalidea I have been running the component on my DEV instance in DEBUG and i could see every 32 min and update being executed.

@fredriklj not sure what is he whish list you refer to. I like very much the sensors and switches the old component provided before Porsche made the changes. So, anything similiar to that would be great. For me personally it was great the ability to execute the Direct Charge as I used to combine different parameters from my solar pannels and home power consumption to force the car charge.

@barto64 but are the values also updated in the json you see in the logs? Because for me it's always the same until i reload the integration.

@barto64
Copy link
Author

barto64 commented Nov 10, 2024

@royalidea , honestly i am not able to say whether they are updated, i am not using the car so mileage or battery level which would be the easier one to change in my case will not do it. Enable the DEBUG and you will see the payload the integration receives from the Porsche Servers. If you see the value changing in the payload and not in the integration it would be for our friend @fredriklj to fix, but that would be really weird. You can also validate Payload values, integration values and mobile app value to identify potential differences. I see many times my App not updating the info either.

@fredriklj
Copy link
Collaborator

@barto64 or others, is the data being updated for you? For me it seems to only update when i manually reload the integration.

I see it too. Will have a look at it.

@fredriklj
Copy link
Collaborator

@fredriklj not sure what is he whish list you refer to. I like very much the sensors and switches the old component provided before Porsche made the changes. So, anything similiar to that would be great. For me personally it was great the ability to execute the Direct Charge as I used to combine different parameters from my solar pannels and home power consumption to force the car charge.

Switches for climatisation and direct charge, as well a control of the lock is on my to-do list. Maybe also honk & flash.

I am happy to receive feature requests for any other sensors or services.

@fredriklj
Copy link
Collaborator

@royalidea Obviously I had a brain fart. Please update and install pyporscheconnect again, updates should work now.

@Jimnaldo
Copy link

@fredriklj now i get this error, please advise?:

Log details (ERROR)
This error originated from a custom integration.
Logger: custom_components.porscheconnect
Source: helpers/update_coordinator.py:382
integration: Porsche Connect (documentation, issues)
First occurred: 4:03:05 PM (4 occurrences)
Last logged: 4:03:44 PM

Unexpected error fetching porscheconnect data
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 382, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/porscheconnect/init.py", line 132, in _async_update_data
self.vehicles = await self.controller.get_vehicles()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pyporscheconnectapi/account.py", line 58, in get_vehicles
await self._init_vehicles()
File "/usr/local/lib/python3.12/site-packages/pyporscheconnectapi/account.py", line 47, in _init_vehicles
await v._update_data_for_vehicle()
File "/usr/local/lib/python3.12/site-packages/pyporscheconnectapi/vehicle.py", line 127, in _update_data_for_vehicle
mdata["CHARGING_SUMMARY"]["chargingProfile"][
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
KeyError: 'chargingProfile'

@barto64
Copy link
Author

barto64 commented Nov 11, 2024

Yep, I have the same error, there seem to be a mistmatch in between the API and the component.

@fredriklj
Copy link
Collaborator

@Jimnaldo @barto64 What kind of cars do you have? ICE or BEV or Hybrid? Can you post me the data object of the vehicle? (Got measurement data for vehicle ..)

@barto64
Copy link
Author

barto64 commented Nov 11, 2024

Mine is Hybrid and cannot provide a fresh data object as my integration is now broken. I guess you mean the JSON Porsche server return with all data for the car. This is the latest i have
Porsche Payload 1.json

@fredriklj
Copy link
Collaborator

fredriklj commented Nov 11, 2024

Ok, got it! Fixed in last commit of pyporscheconnectapi. Please try and see if it resolves it.

@barto64
Copy link
Author

barto64 commented Nov 11, 2024

It went back to live. I uninstall the API and installed it again, deleted the pycache dir, reboot the HA and it worked.

FYI, I am about to leave mid day tomorrow for a couple of week and will not be able to assist during that time.

@fredriklj
Copy link
Collaborator

Folks, we are about to make a new release of the ha component any day now. But we need testers with different types of cars and also I know some of you have more than one, which would be of great value to know how/if that works.

So if you can, please check out the new_api branch and make sure to have the same branch of the pyporcheconnectapi installed and updated to the last commit. Bugs can be reported as new issues, not to clutter this thread even more.

Thanks!

@jfrigger
Copy link

I have latest (Build Date 07/2024) Cayenne hybrid. Will it help ?

@fredriklj
Copy link
Collaborator

@jfrigger All testing would help, absolutely! Any types of nits and grits that can be spotted. Bugs of course, but also unavailable sensors, missing information, awkward translations, etc.

@f1dgj
Copy link

f1dgj commented Nov 24, 2024 via email

@morningla
Copy link

User is not granted access to vehicle VIN xxx, reason
2024 Macan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking Changes
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.