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

Example code not working #6

Closed
mschlenstedt opened this issue Feb 10, 2021 · 13 comments
Closed

Example code not working #6

mschlenstedt opened this issue Feb 10, 2021 · 13 comments
Assignees

Comments

@mschlenstedt
Copy link

mschlenstedt commented Feb 10, 2021

Hey!

You made a pull request to my repo some time ago, but I still stuck with my own implementation. Since your implementation seems to be much more detailed, I would like to use your library for my project. Unfortunately, the example code does not work (and I also could not find any other documentation:

$ ./example.py
Traceback (most recent call last):
  File "./example.py", line 81, in <module>
    - window_heater
NameError: name 'charging_cable_connected' is not defined
$

Could you please help?

@Farfar
Copy link
Collaborator

Farfar commented Feb 10, 2021

Yes, the example code has unfortunately not been worked on for a while.
I will see if I can make it work and update with some comments.

I am working on a project in parallel to migrate all code into a more generalized "VW-Group Connect" library that might be used for all VAG brands since most seems to be using the same API (at least VW, Skoda and Seat this far).

@Farfar Farfar self-assigned this Feb 10, 2021
@mschlenstedt
Copy link
Author

No problem - may be you can just explain how I can grep the data in a simple way. I would like to use the library to send all data to a MQTT broker.

@Farfar
Copy link
Collaborator

Farfar commented Feb 10, 2021

No problem - may be you can just explain how I can grep the data in a simple way. I would like to use the library to send all data to a MQTT broker.

See the example/examply.py in latest commit. There you should be able to figure out what you can use and how.

If you have the Vehicle class object then you can access the data directly from the object properties, vehicle.charging_cable_connected for instance will then return True/False.

You should implement a update method that periodically calls the Connection update() method to fetch newest data from servers. If not done periodically, or too long between updates, then the tokens might expire and might be non-refreshable. Then a new login is required which will re-init everything.

@mschlenstedt
Copy link
Author

Great - thanks a lot!

@mschlenstedt
Copy link
Author

mschlenstedt commented Feb 11, 2021

Sorry, have to reopen this again... When trying the new example code I got an error regarding missing cryptography module (RSAalgorith is missing). So I used pip to install cryptography (seems that this must be added to requirements.txt).

I installed cryptography-3.4.4 via pip.

Now I get the following error:

DEBUG:skodaconnect.connection:Parse auth code...
DEBUG:skodaconnect.connection:Get tokens...
DEBUG:skodaconnect.connection:User identity token verified OK.
DEBUG:skodaconnect.connection:VW-Group API token verified OK.
DEBUG:skodaconnect.connection:Fetching vehicles associated with account
DEBUG:skodaconnect.connection:HTTP GET "https://msg.volkswagen.de/fs-car/usermanagement/users/v1/skoda/CZ/vehicles"
DEBUG:skodaconnect.connection:Request for "https://msg.volkswagen.de/fs-car/usermanagement/users/v1/skoda/CZ/vehicles" returned with status code [200]
DEBUG:skodaconnect.connection:Found vehicle(s) associated with account.
ERROR:skodaconnect.connection:Failed to login to Skoda Connect, It is required that you pass in a value for the "algorithms" argument when calling decode().

Some discussions on the web shows, that this error seems to be related to pyJWT module, but I have installed latest version via pip:

# pip install pyJWT
Collecting pyJWT
  Downloading PyJWT-2.0.1-py3-none-any.whl (15 kB)
Installing collected packages: pyJWT
Successfully installed pyJWT-2.0.1

Maybe this one? https://github.com/jpadilla/pyjwt/blob/master/CHANGELOG.rst#dropped-deprecated-verify-param-in-jwtdecode

Sorry for all that trouble.... :-)

@mschlenstedt mschlenstedt reopened this Feb 11, 2021
@mschlenstedt
Copy link
Author

Just checked with an older version from the debian repo: python3-jwt (1.7.0-2). This version gave the same error.

@Farfar
Copy link
Collaborator

Farfar commented Feb 11, 2021

Sorry, have to reopen this again... When trying the new example code I got an error regarding missing cryptography module (RSAalgorith is missing). So I used pip to install cryptography (seems that this must be added to requirements.txt).

I installed cryptography-3.4.4 via pip.

Now I get the following error:

DEBUG:skodaconnect.connection:Parse auth code...
DEBUG:skodaconnect.connection:Get tokens...
DEBUG:skodaconnect.connection:User identity token verified OK.
DEBUG:skodaconnect.connection:VW-Group API token verified OK.
DEBUG:skodaconnect.connection:Fetching vehicles associated with account
DEBUG:skodaconnect.connection:HTTP GET "https://msg.volkswagen.de/fs-car/usermanagement/users/v1/skoda/CZ/vehicles"
DEBUG:skodaconnect.connection:Request for "https://msg.volkswagen.de/fs-car/usermanagement/users/v1/skoda/CZ/vehicles" returned with status code [200]
DEBUG:skodaconnect.connection:Found vehicle(s) associated with account.
ERROR:skodaconnect.connection:Failed to login to Skoda Connect, It is required that you pass in a value for the "algorithms" argument when calling decode().

Some discussions on the web shows, that this error seems to be related to pyJWT module, but I have installed latest version via pip:

# pip install pyJWT
Collecting pyJWT
  Downloading PyJWT-2.0.1-py3-none-any.whl (15 kB)
Installing collected packages: pyJWT
Successfully installed pyJWT-2.0.1

Maybe this one? https://github.com/jpadilla/pyjwt/blob/master/CHANGELOG.rst#dropped-deprecated-verify-param-in-jwtdecode

Sorry for all that trouble.... :-)

No worries.
I think it's a bug in pyjwt 2.0.1, just noticed yesterday myself.
Install pyjwt==1.7.1 and it should work fine.

@Farfar
Copy link
Collaborator

Farfar commented Feb 11, 2021

Just checked with an older version from the debian repo: python3-jwt (1.7.0-2). This version gave the same error.

Can you try install older version via pip instead? And verify which one in use with pip show.

@mschlenstedt
Copy link
Author

Great - works with 1.7.1 from pip!

Thanks! I am looking forward if the new lib for all other VW brands is available. I will now include at first the skoda lib in my project.

https://github.com/mschlenstedt/LoxBerry-Plugin-SkodaConnect

This is still based on https://github.com/DBa2016/sc2mqtt, but functionality is quite limited...

@mschlenstedt
Copy link
Author

mschlenstedt commented Feb 11, 2021

Played a little bit with the example today. It greps the data for the first time very well, but then if it tries to update the data after 20 sec I got the following error:

...
XXXXXXXPXM702XXXX Fuel level - (fuel_level)
        str_state: 79 % - state: 79
        attributes: {}

Sleeping for 20 seconds
Updating ALL values from Skoda Connect...
DEBUG:skodaconnect.connection:Going to call vehicle updates
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/climatisation/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/climater"
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/tripstatistics/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/tripdata/shortTerm?newest"
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/cf/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/position"
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/vsr/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/status"
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/batterycharge/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/charger"
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/tripstatistics/v1/skoda/CZ/vehicles/TXXXXXXXPXM702XXXX/tripdata/shortTerm?newest" returned with status code [200]
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/batterycharge/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/charger" returned with status code [200]
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/cf/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/position" returned with status code [200]
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/climatisation/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/climater" returned with status code [200]
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/vsr/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/status" returned with status code [200]
Success!
Updating INDIVIDUAL values for XXXXXXXPXM702XXXX...
Updating carportdata...
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/promoter/portfolio/v1/skoda/CZ/vehicle/XXXXXXXPXM702XXXX/carportdata"
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/promoter/portfolio/v1/skoda/CZ/vehicle/TXXXXXXXPXM702XXXX/carportdata" returned with status code [200]
Updating charger data...
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/batterycharge/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/charger"
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/batterycharge/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/charger" returned with status code [200]
Traceback (most recent call last):
  File "./example.py", line 204, in <module>
    loop.run_until_complete(main())
  File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "./example.py", line 166, in main
    await vehicle.get_charger()
  File "/opt/loxberry/.local/lib/python3.7/site-packages/skodaconnect/vehicle.py", line 193, in get_charger
    await self._states.update(data)
TypeError: object NoneType can't be used in 'await' expression

@mschlenstedt mschlenstedt reopened this Feb 11, 2021
@Farfar
Copy link
Collaborator

Farfar commented Feb 11, 2021

Played a little bit with the example today. It greps the data for the first time very well, but then if it tries to update the data after 20 sec I got the following error:

...
XXXXXXXPXM702XXXX Fuel level - (fuel_level)
        str_state: 79 % - state: 79
        attributes: {}

Sleeping for 20 seconds
Updating ALL values from Skoda Connect...
DEBUG:skodaconnect.connection:Going to call vehicle updates
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/climatisation/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/climater"
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/tripstatistics/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/tripdata/shortTerm?newest"
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/cf/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/position"
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/vsr/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/status"
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/batterycharge/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/charger"
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/tripstatistics/v1/skoda/CZ/vehicles/TXXXXXXXPXM702XXXX/tripdata/shortTerm?newest" returned with status code [200]
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/batterycharge/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/charger" returned with status code [200]
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/cf/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/position" returned with status code [200]
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/climatisation/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/climater" returned with status code [200]
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/vsr/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/status" returned with status code [200]
Success!
Updating INDIVIDUAL values for XXXXXXXPXM702XXXX...
Updating carportdata...
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/promoter/portfolio/v1/skoda/CZ/vehicle/XXXXXXXPXM702XXXX/carportdata"
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/promoter/portfolio/v1/skoda/CZ/vehicle/TXXXXXXXPXM702XXXX/carportdata" returned with status code [200]
Updating charger data...
DEBUG:skodaconnect.connection:HTTP GET "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/batterycharge/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/charger"
DEBUG:skodaconnect.connection:Request for "https://fal-3a.prd.eu.dp.vwg-connect.com/fs-car/bs/batterycharge/v1/skoda/CZ/vehicles/XXXXXXXPXM702XXXX/charger" returned with status code [200]
Traceback (most recent call last):
  File "./example.py", line 204, in <module>
    loop.run_until_complete(main())
  File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "./example.py", line 166, in main
    await vehicle.get_charger()
  File "/opt/loxberry/.local/lib/python3.7/site-packages/skodaconnect/vehicle.py", line 193, in get_charger
    await self._states.update(data)
TypeError: object NoneType can't be used in 'await' expression

Check the latest commit. And you don't need to update the data like in the example, it's only there to show you different ways to do it.

@Farfar
Copy link
Collaborator

Farfar commented Feb 14, 2021

@mschlenstedt did you resolve this?

@mschlenstedt
Copy link
Author

Yes, sorry. Works like a charme now :-)

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

No branches or pull requests

2 participants