bimmer_connected icon indicating copy to clipboard operation
bimmer_connected copied to clipboard

0.8.0: No support for `china`

Open rikroe opened this issue 5 years ago • 23 comments

Describe the issue

Starting with 0.8.0, support for region china had to be dropped.

We are currently unable to figure out the login mechanism used. If you want to jump in and help us fixing it, we can provide full network traffic.

Workaround: Use bimmer_connected<0.8.0 or the Home Assistant custom component BMW ConnectedDrive China (to be released soon).

Expected behavior

Login to china possible, reuse of existing vehicle endpoints.

Which Home Assistant version are you using?

none

What was the last working version of Home Assistant Core?

No response

What is your region?

China

ConnectedDrive website

  • [X] I can still successfully login to the BMW ConnectedDrive website and the car status is available there.
  • [ ] I have ConnectedDrive enabled for my vehicle.

Number of cars

  • [X] I have 2 or more cars linked to the ConnectedDrive account.
  • [ ] I have a Mini vehicle linked to my account.

Output of bimmer_connected fingerprint

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

rikroe avatar Nov 18 '21 08:11 rikroe

Hi, I am a bimmer and HA user from China. I have figured out the login mechanism in MyBMW. However, I am not a programmer and know nothing about python. You can find the login mechanism in the Siri Shortcuts I wrote for BMW:

All Shortcuts download link MyBMW login Shortcuts

Hope this helps.

muxiachuixue avatar Nov 19 '21 02:11 muxiachuixue

Hello,BMW ConnectedDrive China How long is it expected to be released

zhaozengxiao avatar Nov 22 '21 08:11 zhaozengxiao

@muxiachuixue thanks! Unfortunately I am not able to translate what you have written. @zhaozengxiao no idea :( If the login issue is understood, will be very quick.

rikroe avatar Nov 22 '21 19:11 rikroe

"command_url_prefix":"https://myprofile.bmw.com.cn/eadrax-vrccs/v2/presentation/remote-commands/", "climate_on_url_postfix":"/climate-now?action=START", "climate_off_url_postfix":"/climate-now?action=STOP", "lock_url_postfix":"/door-lock", "unlock_url_postfix":"/door-unlock", "light_url_postfix":"/light-flash", "horn_url_postfix":"/horn-blow", "event_url_postfix":"eventStatus?eventId=", "status_url":"https://myprofile.bmw.com.cn/eadrax-vcs/v1/vehicles?apptimezone=480&appDateTime=", "status_vin_url_prefix":"https://myprofile.bmw.com.cn/eadrax-vcs/v1/vehicles/", "status_vin_url_postfix":"/state?apptimezone=480&appDateTime=", "token_url":"https://myprofile.bmw.com.cn/eadrax-coas/v1/oauth/token", "login_url":"https://myprofile.bmw.com.cn/eadrax-coas/v1/login/pwd", "publickey_url":"https://myprofile.bmw.com.cn/eadrax-coas/v1/cop/publickey", "jsencrypt_url":"https://gitee.com/ichuixue/bmw_shortcuts/raw/master/BMW_JSEncrypt.js", "check_in_url":"https://myprofile.bmw.com.cn/cis/eadrax-community/private-api/v1/mine/check-in", "joy_list_url":"https://myprofile.bmw.com.cn/cis/eadrax-membership/api/v2/joy-list", "article_list_url":"https://myprofile.bmw.com.cn/cis/eadrax-ocommunity/public-api/v1/article-list", "share_article_url":"https://myprofile.bmw.com.cn/cis/eadrax-oarticle/open/article/api/v2/share-article", "joy_info_url":"https://myprofile.bmw.com.cn/cis/eadrax-membership/api/v1/joy-info",

Excuse me, is this useful?

zhaozengxiao avatar Nov 23 '21 02:11 zhaozengxiao

@muxiachuixue thanks! Unfortunately I am not able to translate what you have written. @zhaozengxiao no idea :( If the login issue is understood, will be very quick.

I will make a clear one for you.

muxiachuixue avatar Nov 23 '21 02:11 muxiachuixue

@rikroe Now the Shortcuts for MyBMW in China will be more easier to read and understand: MyBMW login Lock MyBMW Status of MyBMW

Anything I can help, please let me know.

muxiachuixue avatar Nov 23 '21 04:11 muxiachuixue

When I click on one of the shortcuts, it says "not found". Do I need an iPhone for this? Also on MacOS I get a "not found".

Just saw your link to BMW_JSEncrypt.js. This is the only thing missing on is how to encrypt the password for login/pwd. From what you posted I understand the password is send using RSA public key encryption.

However I am not able to (re-)create valid passwort hashes that I have seen. Do you only need to encrypt the password? Or More?

EDIT: Nevermind, I figured it out! Will try to implement it before it gets merged into Home Assistant.

EDIT2: got a first implementation working. Will create some tests and then give it to you for testing.

rikroe avatar Nov 23 '21 21:11 rikroe

@rikroe I'm just a porter, All his credit @muxiachuixue ,I really want to take the test, thank you

zhaozengxiao avatar Nov 23 '21 23:11 zhaozengxiao

When I click on one of the shortcuts, it says "not found". Do I need an iPhone for this? Also on MacOS I get a "not found".

Just saw your link to BMW_JSEncrypt.js. This is the only thing missing on is how to encrypt the password for login/pwd. From what you posted I understand the password is send using RSA public key encryption.

However I am not able to (re-)create valid passwort hashes that I have seen. Do you only need to encrypt the password? Or More?

EDIT: Nevermind, I figured it out! Will try to implement it before it gets merged into Home Assistant.

EDIT2: got a first implementation working. Will create some tests and then give it to you for testing.

The IOS Shortcuts need the App "Scriptable" to run the JavaScript codes. If you have not installed the App, a "not found" error will come out. If you need a Chinese BMW account for testing, please let me and @zhaozengxiao know. Thanks again for the efforts.

muxiachuixue avatar Nov 24 '21 00:11 muxiachuixue

@rikroe After installing the bimmer-connected-0.8.1.dev1 version on my raspberry pi 4B, I executed the following command: bimmerconnected status 8615201231234 password1234 china

And got the error outputs:

`DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myprofile.bmw.com.cn:443 DEBUG:urllib3.connectionpool:https://myprofile.bmw.com.cn:443 "GET /eadrax-coas/v1/cop/publickey HTTP/1.1" 200 356 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myprofile.bmw.com.cn:443 DEBUG:urllib3.connectionpool:https://myprofile.bmw.com.cn:443 "POST /eadrax-coas/v1/login/pwd HTTP/1.1" 200 731 DEBUG:bimmer_connected.account:got new token eyJhbGciOiJIUzI1NiIsInR5xxxxxxxxImV4cCI6MTYzNzc1OTY0NywiaWF0Ijxxxxxxxr5V62o5yw9urSL2IvMG9IzyF7s with expiration date 2021-11-24 13:14:07 DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Request to: https://myprofile.bmw.com.cn/eadrax-vcs/v1/vehicles DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myprofile.bmw.com.cn:443 DEBUG:urllib3.connectionpool:https://myprofile.bmw.com.cn:443 "GET /eadrax-vcs/v1/vehicles?apptimezone=480.0&appDateTime=1637727547.929913&tireGuardMode=ENABLED HTTP/1.1" 200 7517 DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Request to: https://myprofile.bmw.com.cn/eadrax-vcs/v1/vehicles DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myprofile.bmw.com.cn:443 DEBUG:urllib3.connectionpool:https://myprofile.bmw.com.cn:443 "GET /eadrax-vcs/v1/vehicles?apptimezone=480.0&appDateTime=1637727549.340775&tireGuardMode=ENABLED HTTP/1.1" 200 2 DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Request to: https://myprofile.bmw.com.cn/eadrax-vcs/v1/vehicles DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myprofile.bmw.com.cn:443 DEBUG:urllib3.connectionpool:https://myprofile.bmw.com.cn:443 "GET /eadrax-vcs/v1/vehicles?apptimezone=480.0&appDateTime=1637727550.503834&tireGuardMode=ENABLED HTTP/1.1" 200 7517 DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Request to: https://myprofile.bmw.com.cn/eadrax-vcs/v1/vehicles DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myprofile.bmw.com.cn:443 DEBUG:urllib3.connectionpool:https://myprofile.bmw.com.cn:443 "GET /eadrax-vcs/v1/vehicles?apptimezone=480.0&appDateTime=1637727551.604555&tireGuardMode=ENABLED HTTP/1.1" 200 2 Found 1 vehicles: 325i VIN: LBV5F340ABCD01234 Mileage: (13547, 'km') Vehicle data: DEBUG:bimmer_connected.vehicle_status:No data available for attribute <function VehicleStatus.charging_level_hv at 0xb56f18e8>! ValueError: '已上锁' is not a valid LockState

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/pi/.local/bin/bimmerconnected", line 10, in sys.exit(main()) File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/cli.py", line 279, in main args.func(args) File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/cli.py", line 117, in get_status print(to_json(vehicle, indent=4)) File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/utils.py", line 41, in to_json return json.dumps(obj, default=serialize, *args, **kwargs) File "/usr/lib/python3.7/json/init.py", line 238, in dumps **kw).encode(obj) File "/usr/lib/python3.7/json/encoder.py", line 201, in encode chunks = list(chunks) File "/usr/lib/python3.7/json/encoder.py", line 439, in _iterencode yield from _iterencode(o, _current_indent_level) File "/usr/lib/python3.7/json/encoder.py", line 431, in _iterencode yield from _iterencode_dict(o, _current_indent_level) File "/usr/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict yield from chunks File "/usr/lib/python3.7/json/encoder.py", line 438, in _iterencode o = _default(o) File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/utils.py", line 40, in serialize return getattr(obj, 'to_json', getattr(obj, 'dict') if hasattr(obj, 'dict') else str(obj)) File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/utils.py", line 64, in to_json return serialize_for_json(self) File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/utils.py", line 25, in serialize_for_json **{a: getattr(obj, a) for a in get_class_property_names(obj) if a not in excluded + ["to_json"]} File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/utils.py", line 25, in **{a: getattr(obj, a) for a in get_class_property_names(obj) if a not in excluded + ["to_json"]} File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/vehicle_status.py", line 140, in _func_wrapper return func(self, *args, **kwargs) File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/vehicle_status.py", line 306, in door_lock_state return LockState(self.status['doorsGeneralState'].upper()) File "/usr/lib/python3.7/enum.py", line 310, in call return cls.new(cls, value) File "/usr/lib/python3.7/enum.py", line 564, in new raise exc File "/usr/lib/python3.7/enum.py", line 548, in new result = cls.missing(value) File "/usr/lib/python3.7/enum.py", line 577, in missing raise ValueError("%r is not a valid %s" % (value, cls.name)) ValueError: '已上锁' is not a valid LockState `

muxiachuixue avatar Nov 24 '21 12:11 muxiachuixue

@rikroe Thank you for your efforts!I want to know how to use the new version in Home Assistant?Thank you!!!

zhaozengxiao avatar Nov 24 '21 12:11 zhaozengxiao

@muxiachuixue ouch, seems the API is returning chinese instead of english...

Could you please try one thing for me and and edit /home/pi/.local/lib/python3.7/site-packages/bimmer_connected/account.py L272-L276 so it looks like this (added accept-language):

        headers = {
            "accept": "application/json",
            "x-user-agent": X_USER_AGENT.format(brand.value),
            "Authorization": "Bearer {}".format(self._oauth_token),
            "accept-language": "en",
        }

Let me know if that works for you!

@zhaozengxiao it just got merged into Home Assistant, so it should be included in the next major version.

rikroe avatar Nov 24 '21 22:11 rikroe

@muxiachuixue ouch, seems the API is returning chinese instead of english...

Could you please try one thing for me and and edit /home/pi/.local/lib/python3.7/site-packages/bimmer_connected/account.py L272-L276 so it looks like this (added accept-language):

        headers = {
            "accept": "application/json",
            "x-user-agent": X_USER_AGENT.format(brand.value),
            "Authorization": "Bearer {}".format(self._oauth_token),
            "accept-language": "en",
        }

Let me know if that works for you!

@zhaozengxiao it just got merged into Home Assistant, so it should be included in the next major version.

After adding the "accept-language" line as you told, I can get the correct outputs of the car status json data. However, before the json data, you can see the following lines. Is it OK?

DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myprofile.bmw.com.cn:443 DEBUG:urllib3.connectionpool:https://myprofile.bmw.com.cn:443 "GET /eadrax-coas/v1/cop/publickey HTTP/1.1" 200 356 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myprofile.bmw.com.cn:443 DEBUG:urllib3.connectionpool:https://myprofile.bmw.com.cn:443 "POST /eadrax-coas/v1/login/pwd HTTP/1.1" 200 731 DEBUG:bimmer_connected.account:got new token eyJhbGciOiJIUzI1NiIsIxxxxxBJDE2Mzc4MTAyMjUwNTMiLCJuYmYiOjE2Mxxxxxx3ODEwMjI1fQ._F33fIjXbh5Sn0srxxxxxpcQWTqdVBY with expiration date 2021-11-25 04:12:05 DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Request to: https://myprofile.bmw.com.cn/eadrax-vcs/v1/vehicles DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myprofile.bmw.com.cn:443 DEBUG:urllib3.connectionpool:https://myprofile.bmw.com.cn:443 "GET /eadrax-vcs/v1/vehicles?apptimezone=480.0&appDateTime=1637781425.01832&tireGuardMode=ENABLED HTTP/1.1" 200 7410 DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Request to: https://myprofile.bmw.com.cn/eadrax-vcs/v1/vehicles DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myprofile.bmw.com.cn:443 DEBUG:urllib3.connectionpool:https://myprofile.bmw.com.cn:443 "GET /eadrax-vcs/v1/vehicles?apptimezone=480.0&appDateTime=1637781426.85447&tireGuardMode=ENABLED HTTP/1.1" 200 2 DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Request to: https://myprofile.bmw.com.cn/eadrax-vcs/v1/vehicles DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myprofile.bmw.com.cn:443 DEBUG:urllib3.connectionpool:https://myprofile.bmw.com.cn:443 "GET /eadrax-vcs/v1/vehicles?apptimezone=480.0&appDateTime=1637781429.366527&tireGuardMode=ENABLED HTTP/1.1" 200 7410 DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Request to: https://myprofile.bmw.com.cn/eadrax-vcs/v1/vehicles DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myprofile.bmw.com.cn:443 DEBUG:urllib3.connectionpool:https://myprofile.bmw.com.cn:443 "GET /eadrax-vcs/v1/vehicles?apptimezone=480.0&appDateTime=1637781430.841364&tireGuardMode=ENABLED HTTP/1.1" 200 2 Found 1 vehicles: 325i VIN: LBV5xxxxABCD12345 Mileage: (13569, 'km') Vehicle data: DEBUG:bimmer_connected.vehicle_status:No data available for attribute <function VehicleStatus.charging_level_hv at 0xb56c1858>!

{
"attributes": { "vin": "LBV5xxxxABCD12345", "vehicleType": "connected", "licensePlate": "XXXXXX", "cdActiveStatus": "ACTIVATED", ... }

muxiachuixue avatar Nov 25 '21 03:11 muxiachuixue

It is quite strange that, the car status json data from the IOS shortcut shows less information than the data from your bimmerconnected program in linux. For example, the "last_update_reason" does not show in the shortcut result. The POST request is like this in IOS shortcut:

GET 'https://myprofile.bmw.com.cn/eadrax-vcs/v1/vehicles?apptimezone=480.0&appDateTime=1637781426.85447&tireGuardMode=ENABLED'

Header: { "accept":"application/json" "Authorization":"Bearer $access_token", "x-user-agent":"ios(14.8);bmw;1.4.0(7743)" "accept-language":"en" }

Same in postman as IOS shortcut. What did I miss?

Edit: I got it. The information I missed is defined in your codes. As for the "inMotion" attribute, when I start the engine for several minutes (not move), the "inMotion" value is still false. Haven't try to check it when the car is moving.

muxiachuixue avatar Nov 25 '21 04:11 muxiachuixue

Thanks, this is looking good then!

rikroe avatar Nov 25 '21 06:11 rikroe

@rikroe Hello, I am a beginner in python. After I pull the package, what command should I use to test? ? ?

'bimmerconnected fingerprint <8618860629999> <123456789> '

Enter this in the console?

zhaozengxiao avatar Nov 25 '21 08:11 zhaozengxiao

It is not a implemented in the official package yet, I will do that after work and let you know.

Also I'll give you the command you need to use.

rikroe avatar Nov 25 '21 11:11 rikroe

It is not a implemented in the official package yet, I will do that after work and let you know.

Also I'll give you the command you need to use.

Thanks @rikroe

zhaozengxiao avatar Nov 25 '21 11:11 zhaozengxiao

It is not a implemented in the official package yet, I will do that after work and let you know.

Also I'll give you the command you need to use.

bimmerconnected status 8615201231234 password1234 china

muxiachuixue avatar Nov 25 '21 11:11 muxiachuixue

It is not a implemented in the official package yet, I will do that after work and let you know. Also I'll give you the command you need to use.

bimmerconnected status 8615201231234 password1234 china

Thanks @muxiachuixue

zhaozengxiao avatar Nov 26 '21 01:11 zhaozengxiao