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

Wrong formatting in has_connected_services_enabled() #26

Closed
FerumFist opened this issue Jul 23, 2021 · 3 comments
Closed

Wrong formatting in has_connected_services_enabled() #26

FerumFist opened this issue Jul 23, 2021 · 3 comments
Labels

Comments

@FerumFist
Copy link

Describe the bug
Server returned data is different than expected causing a crash.

To Reproduce
Steps to reproduce the behavior:

  • locale is "sk-sk"
  • have one car with services enabled
  • have one car that has no functionality (I have a 2007 RAV4 just for the sake of it in the app)
    • probably unnecessary to buy a vehicle just for testing

Expected behavior
It should work but it don't

** Possible Fix **

I had to modify the vehicle.py - has_connected_services_enabled() fully knowing that a general try-catch is the bodgiest of bodges to be like so:

def has_connected_services_enabled(self, json_dict) -> bool:
    """Checks if the user has enabled connected services."""
    try:
        if (
            "connectedService" in json_dict
            and json_dict["connectedService"]["devices"][0]["state"] == "ACTIVE"
        ):
            return True

        _LOGGER.error(
            "Please setup Connected Services if you want live data from the car. (%s)",
            self.vin,
        )
        return False
    except:
        return False

Apart from the big try-catch notice the json_dict lookup change.
Probably needs testing to see if this happens in more countries or it's just a nieche for Slovakia.
Unsure if there could be ["devices"][1] or more? I don't have the touch2go nav, did not registrer my head unit nor do I have a hybrid.

@DurgNomis-drol
Copy link
Owner

DurgNomis-drol commented Jul 23, 2021

Can you please provide logs also, so I can understand what the error message is?

Edit:
I believe it is coursed by your car model (RAV 4 from 2007) and not country 😊

@FerumFist
Copy link
Author

Logs:

Traceback (most recent call last):
  File "C:/.../toy.py", line 34, in <module>
    loop.run_until_complete(get_information())
  File "C:\Users\...\AppData\Local\Continuum\anaconda3\envs\py36\lib\asyncio\base_events.py", line 488, in run_until_complete
    return future.result()
  File "C:/.../toy.py", line 19, in get_information
{'id': ###ID_REMOVED###, 'vin': '###VIN_REMOVED###', 'isNC': False, 'alias': 'RAV4', 'owner': False, 'vehicleAddedOn': '2021-07-07T10:18:22.286Z', 'isEntitled': False, 'hasAutomaticMMRegistration': False, 'ownerFlag': False, 'source': 'NMSC', 'connected': False, 'connectedService': {'devices': [], 'registrationPreReqs': [], 'registrationTerms': [], 'wifiBoxData': None}, 'fud': False}
    print(await client.gather_all_information_json())
  File "C:\Users\...\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\mytoyota\client.py", line 138, in gather_all_information_json
    vehicles = await self.gather_all_information()
  File "C:\Users\...\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\mytoyota\client.py", line 130, in gather_all_information
    vehicle = await self.get_vehicle_information(car)
  File "C:\Users\...\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\mytoyota\client.py", line 111, in get_vehicle_information
    status=info[3],
  File "C:\Users\...\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\mytoyota\vehicle.py", line 41, in __init__
    connected_services
  File "C:\Users\...\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\mytoyota\vehicle.py", line 91, in has_connected_services_enabled
    and json_dict["connectedService"]["status"] == "ACTIVE"
KeyError: 'status'

Nvm you were right, it is actually caused by the old car, just tested it, it confirms the new corolla, then hangs at the old RAV4.

@DurgNomis-drol
Copy link
Owner

Thanks for checking! I will add some code to make sure you can only add supported cars. 😁

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

No branches or pull requests

3 participants