-
Notifications
You must be signed in to change notification settings - Fork 11
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
APIs changed? #46
Comments
Indeed, the APIs we used to rely on are retired. So the current version if this library is completely defunct. 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. |
OK I can get some valid data - looks like some changes in the JSON but will explore and see what I can for my use cases - thanks and I will let you know if it works |
Can someone with am ICE-based drivetrain please post the output data from the 'overview' command (vin, location etc. redacted) using new_api branch? Would be most helpful, as I only have access to data from an EV. |
two ICEs - some parts redacted hope this helps - I think some things are slightly different even between the two cars. { { |
Hopefully you can help. How do i install this updated version? Do I need the original HACS integration and then install this over the top? Or do I just install this (then how do I access the date in HA?) sorry for being a bit simple cheers |
Thanks @augmentedtraffic . Helps a lot to know the units and attributes for oil, fuel, etc. @CTRDevelopments, if you want to test it out, check out the new_api branch and install using pip. But for know I got what is needed. No need to go through the hass integration at this point. |
@fredriklj - I'm unable to get your new_api branch working. I tried example2.py and am getting the following "401 Unathorized" on the vehicles endpoint DEBUG:pyporscheconnectapi.connection:TraceRequestEndParams(method='GET', url=URL('https://api.ppa.porsche.com/app/connect/v1/vehicles/WPXXXXXXXXXX'), headers=<CIMultiDict()>, response=<ClientResponse(https://api.ppa.porsche.com/app/connect/v1/vehicles/WPXXXXXXXXXXX?mf=BATTERY_LEVEL&mf=LOCK_STATE_VEHICLE) [401 Unauthorized]> It seems to be logging in because it is able to retrieve the VIN associated with my account. The pip install pyporscheconnectapi is installing 0.1.7 from November 2023 ... is this correct?? |
Nevermind, I overrode the python library package with the version in the new_api branch. All good. Works again, thanks! |
@fredriklj , super. I have installed via PIP but how do i get the data? Sorry if this seems like a noobie type question. Cheers |
if a new install this should work pip3 install git+https://github.com/CJNE/pyporscheconnectapi.git@new_api (or just pip ... if you only have python 3 installed) |
@augmentedtraffic - thanks. I then got the message below. Should this now appear in the integrations page on Home Assistant? Cheers ➜ ~ pip3 install git+https://github.com/CJNE/pyporscheconnectapi.git@new_api |
@CTRDevelopments No, you would need to clone the "new_api" branch from the ha-porscheconnect repo into custom_components of your config directory for hass as well, to override the current (non-functional) version of the integration from HACS. But beware, it is in very early stage of development and currently only have a few read-only entities. It will take some time before we (hopefully) can have a functional integration again. |
@fredriklj Thanks for the info. I have now installed the original integration, then run - pip3 install git+https://github.com/CJNE/pyporscheconnectapi.git@new_api Then copied the files from the github sub folder - pyporscheconnectapi to home assistant (init.py, cli.py, client.py, connection.py, const.py exceptions.py) - do i need any others? I replaced all original files with the new ones It is now giving me an error 'config flow could not be loaded, unknown error' not sure what I have missed. Cheers |
The repo you need to clone into custom_components is here: |
ahh so the original repo. Does installing this from HACS do this automatically? I am manually downloading files to my PC and then uploading through 'studio code viewer' in Home Assistant. Should this work? cheers |
@fredriklj just wanted to say that this works great at least for the "read-only" things together with |
@normanmaurer Thanks for letting me know. There are some issues with getting response code 429 (too many requests) after a while. I'm looking into that issue. |
@fredriklj thanks a lot! Maybe you could also help out the evcc project by providing some the traffic data that you used to reengineer the API: evcc-io/evcc#14371 (comment) |
Yeah, I too am definitely interested in figuring out the new API — I wrote https://github.com/wisq/porsche_conn_ex (largely based on this library), and https://github.com/wisq/tay_calendar to sync my Google Calendar events to car timers, and of course a few months later, they discontinue the API and break everything. 🤦 I've not got much experience reverse engineering APIs or MitMing apps, so I was sorta waiting to see what happened with this project, but I can give it a go myself when I get a bit of spare time. Glad to see we're back to at least basic authentication and read-only access, though! 🎉 |
I need to work out the basics first, and as I think I wrote, I have quite limited time to spend on this currently. Will try to do whatever I can, but any help would be much appreciated. |
Hi, I am still very keen, but unfortunately I cannot get this working, although I suspect this is me rather than any error! Is it possible to describe the install steps again? I thought I understood, but I guess not :) Cheers |
@CTRDevelopments this is what worked for me:
Restart homeassistant |
In case anyone has any good ideas, this is where I am currently stuck:
Closing the session entirely and starting all over will give you a new three-hour window, but that does not seem to be the proper way to do it. As we are trying our best to be nice and polite to the API. I just saw that we didn't set the User-Agent header properly, but that's a long-shot. Ideas welcome. |
Tried this, but does not work for me. HA System log:
Any idea what could be wrong? I used Advanced SSH & Web Terminal for installing the library. Using normal SSH & Termnal add-on did not allow me to use pip3. After install: I get warning:
Could that be the cause? |
I haven't gotten time to put together a PR but I'm pretty sure this is because you are just re-requesting the token with your grant code vs using the refresh token flow. Porsche is using Auth0 and their docs on the refresh token seem to be accurate. I did test this with my Postman collection and I was able to refresh a token with the refresh code 12+ hours later (which is actually somewhat interesting they are this loose but that's a digression). |
Thanks for the tip, @wingrunr21. I tried the refresh token flow, and it works fine. I can renew the access token that way, but still run into the 429 status code. I might have overlooked something, have not had time to dig deeper into the issue, but if you are having any success I'd be much interested in hearing about it! |
Did you push the updated flow to Github? |
No, since it didn't solve it.. I've been on vacation, so have had other priorities. But did some testing, and the problem seems related to the connection rather than to the requests themselves. Could be that we maintain the connections for what the gateway thinks is too long. I've been trying to force connections to close, but sometimes that doesn't work, for reasons I can't figure out. And when it does, hass gets really mad at me. It's also a struggle to debug what is happening behind the curtains of aiohttp. I'm contemplating switching it out for httpx, just to see if that works better. Shouldn't be much work, but have not had the time to do it. |
i have the same problem, please advise? |
Unfortunately I couldn't get this to work. Hoping the kind devs will get it into a more simple installation state when it's ready, something like HACS as the original version, so that I can use it. Sorry I cannot be more help |
@wingrunr21 Ok, so I tried out httpx as well, and got into the same rate limiting issue after 3 hrs. But at least a bit wiser. It seems they REALLY don't want anyone to poll the API with regular intervals. I will try some ridiculously long interval and to do on-demand refresh when needed. I'll push the refresh token flow to the repo, if you would like to have a look and see if it makes sense. |
@CTRDevelopments Once/if we get this working again, we'll do a proper release and update the hass component accordingly. Currently we're struggling to get some meaningful functionality from the APIs, due to very strict rate limiting. Just keep an eye on this issue. |
UPDATE --- not an API issue or even a Porsche issue but related to the car not being driven for a while and hence for some reason it's status update was stale (until I turned the car on again after a long period of time - i.e. > 1 week). I haven't seen this behavior. To confirm the APIs work OK now for both cars. Just some information - I have two cars one a 2024 911 and other 2023 Panamera - the responses are different. For the past 8 or so hours I am seeing different responses for the two cars (also on the mobile app it is "Stuck" trying to refresh the lock data etc only for the Pana). In the code, I see the following exception for the pana - to confirm the 911 is working OK. I suspect it is a Porsche issue as the mobile app seems to have similar behavior (i.e. 911 is refreshed but the Pana isn't) Just wanted you all to be aware (as I initially thought it wasn't working for both cars but I changed the logic to simply ignore for just the one car instead of quit entirely). I always now check the mobile app behavior to confirm any "issues" first. Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): |
Thanks @augmentedtraffic .. I've seen such timeouts myself when the car seem to have lost contact with the backend, for some time. We need to add better handling of such failures. What I think I have found out is that one has to keep the regular polling interval above 30 minutes, then you can also do on-demand polling in between those regular pollings without hitting the 429 (Too many requests). Hopefully I should be able to set aside some time to work on the API later this month, to add some more functionality and (as you have noted) better error handling. |
@fredriklj that's promising... thanks for all the efforts you put into this. |
@augmentedtraffic I have driven my car frequently but still get the error:
So I don't see how this isn't an issue with the Porsche API. |
The error in your post is indeed a different error that I have not seen with the newer APIs/library versions. I don't use HA as I use the python library directly. |
@augmentedtraffic I see. I was referred to this thread from the error I have which was reported at CJNE/ha-porscheconnect#245. Has anyone found a solution? |
@jwinston100 Please see the posts in this issue. The APIs have been retired, and work is on-going to explore the new API. |
On the web site there was a notice about upcoming changes and now when I issue a request I still get data but no useful values
vehicles = await client.getVehicles()
for vehicle in vehicles:
print(json.dumps(vehicle, indent=2))
vins = map(lambda v: v["vin"], vehicles)
for vin in vins:
data = await client.getCurrentOverview(vin)
print(json.dumps(data, indent=2))
Just wondering if anyone else is seeing this?
VIN: xxxxModel: None Year: None
datat is {'vin': 'xxx', 'oilLevel': None, 'fuelLevel': None, 'batteryLevel': None, 'remainingRanges': {'conventionalRange': None, 'electricalRange': None}, 'mileage': None, 'parkingLight': 'INVALID', 'parkingLightStatus': None, 'parkingBreak': 'INVALID', 'parkingBreakStatus': None, 'doors': {'frontLeft': 'INVALID', 'frontRight': 'INVALID', 'backLeft': 'INVALID', 'backRight': 'INVALID', 'frontTrunk': 'INVALID', 'backTrunk': 'INVALID', 'overallLockStatus': 'CLOSED_LOCKED'}, 'serviceIntervals': {'oilService': None, 'inspection': None}, 'tires': {'frontLeft': {'currentPressure': None, 'optimalPressure': None, 'differencePressure': None, 'tirePressureDifferenceStatus': 'UNKNOWN'}, 'frontRight': {'currentPressure': None, 'optimalPressure': None, 'differencePressure': None, 'tirePressureDifferenceStatus': 'UNKNOWN'}, 'backLeft': {'currentPressure': None, 'optimalPressure': None, 'differencePressure': None, 'tirePressureDifferenceStatus': 'UNKNOWN'}, 'backRight': {'currentPressure': None, 'optimalPressure': None, 'differencePressure': None, 'tirePressureDifferenceStatus': 'UNKNOWN'}}, 'windows': {'frontLeft': 'INVALID', 'frontRight': 'INVALID', 'backLeft': 'INVALID', 'backRight': 'INVALID', 'roof': 'INVALID', 'maintenanceHatch': 'INVALID', 'sunroof': {'status': 'INVALID', 'positionInPercent': None}}, 'parkingTime': None, 'overallOpenStatus': 'CLOSED', 'chargingStatus': None, 'carModel': None, 'engineType': None, 'chargingState': None}
IN: WP0CD2A9XRS257470 Model: None Year: None
{
"vin": "xxx",
"oilLevel": null,
"fuelLevel": null,
"batteryLevel": null,
"remainingRanges": {
"conventionalRange": null,
"electricalRange": null
},
"mileage": null,
"parkingLight": "INVALID",
"parkingLightStatus": null,
"parkingBreak": "INVALID",
"parkingBreakStatus": null,
"doors": {
"frontLeft": "INVALID",
"frontRight": "INVALID",
"backLeft": "INVALID",
"backRight": "INVALID",
"frontTrunk": "INVALID",
"backTrunk": "INVALID",
"overallLockStatus": "CLOSED_LOCKED"
},
"serviceIntervals": {
"oilService": null,
"inspection": null
},
"tires": {
"frontLeft": {
"currentPressure": null,
"optimalPressure": null,
"differencePressure": null,
"tirePressureDifferenceStatus": "UNKNOWN"
},
"frontRight": {
"currentPressure": null,
"optimalPressure": null,
"differencePressure": null,
"tirePressureDifferenceStatus": "UNKNOWN"
},
"backLeft": {
"currentPressure": null,
"optimalPressure": null,
"differencePressure": null,
"tirePressureDifferenceStatus": "UNKNOWN"
},
"backRight": {
"currentPressure": null,
"optimalPressure": null,
"differencePressure": null,
"tirePressureDifferenceStatus": "UNKNOWN"
}
},
"windows": {
"frontLeft": "INVALID",
"frontRight": "INVALID",
"backLeft": "INVALID",
"backRight": "INVALID",
"roof": "INVALID",
"maintenanceHatch": "INVALID",
"sunroof": {
"status": "INVALID",
"positionInPercent": null
}
},
"parkingTime": null,
"overallOpenStatus": "CLOSED",
"chargingStatus": null,
"carModel": null,
"engineType": null,
"chargingState": null
}
thanks
The text was updated successfully, but these errors were encountered: