DurgNomis-drol / mytoyota

Python client for Toyota Connected Services API
MIT License
81 stars 33 forks source link

mytoyota module no longer works #363

Closed gthbcrvs closed 3 months ago

gthbcrvs commented 3 months ago

Describe the bug It appears there has been a change on Toyota's side that breaks this module since some day's after August 4th.

To Reproduce Steps to reproduce the behavior:

  1. Run simple_client_example.py
  2. Error: C:\Users\xxx\simple_client_example.py:77: DeprecationWarning: There is no current event loop loop = asyncio.get_event_loop() Logging in... Retrieving cars... Traceback (most recent call last): File "C:\Users\xxx\simple_client_example.py", line 78, in <module> loop.run_until_complete(get_information()) File "C:\Users\xxx\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "C:\Users\xxx\simple_client_example.py", line 49, in get_information await car.update() File "C:\Users\xxx\AppData\Local\Programs\Python\Python312\Lib\site-packages\mytoyota\models\vehicle.py", line 106, in update for name, data in await responses: ^^^^^^^^^^^^^^^ File "C:\Users\xxx\AppData\Local\Programs\Python\Python312\Lib\site-packages\mytoyota\models\vehicle.py", line 100, in parallel_wrapper r = await function() ^^^^^^^^^^^^^^^^ File "C:\Users\xxx\AppData\Local\Programs\Python\Python312\Lib\site-packages\mytoyota\api.py", line 199, in get_notification_endpoint parsed_response = await self._request_and_parse( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\xxx\AppData\Local\Programs\Python\Python312\Lib\site-packages\mytoyota\api.py", line 55, in _request_and_parse return model(**response) ^^^^^^^^^^^^^^^^^ File "pydantic\main.py", line 341, in pydantic.main.BaseModel.__init__ pydantic.error_wrappers.ValidationError: 1 validation error for NotificationResponseModel guid field required (type=value_error.missing)

Expected behavior The expected data.

Additional context Also added as an issue in the ha_toyota repository: https://github.com/DurgNomis-drol/ha_toyota/issues/286

rhuijben commented 3 months ago

Same issue here. Looks like a server side change caused the scripting to fail.

Noted some issues uploading trip details around the same time, but these resolved over the last few days.

GitOldGrumpy commented 3 months ago

Pushed a fix to branch Issue_363 which has it working for me, if someone else could validate.

Ishima commented 3 months ago

@GitOldGrumpy VIN is also missing in NotificationModel

briandelicata commented 3 months ago

Pushed a fix to branch Issue_363 which has it working for me, if someone else could validate.

Didn't work for me:

mytoyota-Issue_363/simple_client_example.py:85: DeprecationWarning: There is no current event loop loop = asyncio.get_event_loop() Logging in... Retrieving cars... Traceback (most recent call last): File "/Users//Downloads/mytoyota-Issue_363/simple_client_example.py", line 86, in loop.run_until_complete(get_information()) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 664, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/Users//Downloads/mytoyota-Issue_363/simple_client_example.py", line 50, in get_information await car.update() File "/Users//Downloads/mytoyota-Issue_363/mytoyota/models/vehicle.py", line 106, in update for name, data in await responses: ^^^^^^^^^^^^^^^ File "/Users//Downloads/mytoyota-Issue_363/mytoyota/models/vehicle.py", line 100, in parallel_wrapper r = await function() ^^^^^^^^^^^^^^^^ File "/Users//Downloads/mytoyota-Issue_363/mytoyota/api.py", line 199, in get_notification_endpoint parsed_response = await self._request_and_parse( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users//Downloads/mytoyota-Issue_363/mytoyota/api.py", line 55, in _request_and_parse return model(**response) ^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pydantic/main.py", line 341, in init raise validation_error pydantic.error_wrappers.ValidationError: 1 validation error for NotificationResponseModel payload -> 0 -> vin field required (type=value_error.missing)

ajain-93 commented 3 months ago

Pushed a fix to branch Issue_363 which has it working for me, if someone else could validate.

In the same file /mytoyota/models/endpoints/notifications.py, in addition to setting Line 64 to default to None, we need to do the same thing for _PayloadItemModel.vin on Line 46. Changing this makes it work for me.

My github knowledge is too lacking for me to be able to create a PR for this.

ajain-93 commented 3 months ago

Ok, I think I managed to create a PR for this.

briandelicata commented 3 months ago

Pushed a fix to branch Issue_363 which has it working for me, if someone else could validate.

In the same file /mytoyota/models/endpoints/notifications.py, in addition to setting Line 64 to default to None, we need to do the same thing for _PayloadItemModel.vin on Line 46. Changing this makes it work for me.

My github knowledge is too lacking for me to be able to create a PR for this.

If you remove the VIN only the main car is retrieved.

ajain-93 commented 3 months ago

I only have a single car, so I can't fully back this up with data. We are not removing the VIN for the request, only that the model validation for the response does not required a VIN at the payload level.

When performing a GET request to get the notifications from endpoint /v2/notification/history, one of the supplied parameters to Controller.request_json() is the VIN. The response I see today is in the following format (anonimysed and trunkated the payload array): As you can see the response payload for this specific vehicle does not include the VIN in the payload object.

{
    "request": {
        "method": "GET",
        "endpoint": "/v2/notification/history",
        "vin": "«VIN»",
        "body": null,
        "params": null,
        "headers": null
    },
    "response": {
        "statusCode": 200,
        "headers": {
            "Content-Type": "text/plain"
        },
        "body": "Success",
        "payload": [
            {
                "notifications": [
                    {
                        "title": null,
                        "message": "«Message»",
                        "isRead": false,
                        "notificationGroupId": null,
                        "notificationDate": "2024-08-11T18:15:51.246Z",
                        "displayCategory": "Vehicle Alerts",
                        "messageId": "«ID»",
                        "vin": "«VIN»",
                        "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
                        "type": "alert",
                        "category": "VehicleStatusAlert",
                        "status": "0"
                    },
                    {
                        "title": null,
                        "message": "«Message»",
                        "isRead": false,
                        "notificationGroupId": null,
                        "notificationDate": "2024-08-11T17:55:11.156Z",
                        "displayCategory": "Vehicle Alerts",
                        "messageId": "«ID»",
                        "vin": "«VIN»",
                        "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
                        "type": "alert",
                        "category": "VehicleStatusAlert",
                        "status": "0"
                    }
                ]
            }
        ]
    }
}
pbonato commented 3 months ago

I have still error:

Exception has occurred: ValidationError 1 validation error for NotificationResponseModel payload -> 0 -> vin field required (type=value_error.missing) File "Y:\Projects_Docker\mytoyota\mytoyota\api.py", line 55, in _request_and_parse return model(**response) ^^^^^^^^^^^^^^^^^ File "Y:\Projects_Docker\mytoyota\mytoyota\api.py", line 199, in get_notification_endpoint parsed_response = await self._request_and_parse( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "Y:\Projects_Docker\mytoyota\mytoyota\models\vehicle.py", line 100, in parallel_wrapper r = await function() ^^^^^^^^^^^^^^^^ File "Y:\Projects_Docker\mytoyota\mytoyota\models\vehicle.py", line 106, in update for name, data in await responses: ^^^^^^^^^^^^^^^ File "Y:\Projects_Docker\mytoyota\simple_client_example.py", line 50, in get_information await car.update() File "Y:\Projects_Docker\mytoyota\simple_client_example.py", line 86, in loop.run_until_complete(get_information()) pydantic.error_wrappers.ValidationError: 1 validation error for NotificationResponseModel payload -> 0 -> vin field required (type=value_error.missing)

GitOldGrumpy commented 3 months ago

Neither of my cars have any notifications which is why I missed this. Also having no notifications I cant check if the fix works correctly for people having multiple cars.

Changing the VIN as ajain has should work fine as nothing then uses the value, just need confirmation.

pbonato commented 3 months ago

Neither of my cars have any notifications which is why I missed this. Also having no notifications I cant check if the fix works correctly for people having multiple cars.

Changing the VIN as ajain has should work fine as nothing then uses the value, just need confirmation.

I have a single car with several notification and it doesn't work.

If can help to solve.... this is my Response, that generate error on this block:

async def _request_and_parse(self, model, method: str, endpoint: str, kwargs): """Parse requests and responses.""" response = await self.controller.request_json(method=method, endpoint=endpoint, kwargs) return model(**response)

Exception has occurred: ValidationError 1 validation error for NotificationResponseModel payload -> 0 -> vin field required (type=value_error.missing)

{ "statusCode": 200, "headers": { "Content-Type": "text/plain" }, "body": "Success", "payload": [ { "notifications": [ { "title": None, "message": "2023 bZ4X: Ricarica interrotta [Errore:4].", "isRead": false, "notificationGroupId": None, "notificationDate": "2024-08-12T10:41:32.516Z", "displayCategory": "General", "messageId": "66b9e6dc344c3ce244c3018d", "vin": "VIN", "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/general.png", "type": "alert", "category": "ChargingAlert", "status": "completed" }, { "title": None, "message": "2023 bZ4X: Ricarica interrotta [Errore:4].", "isRead": false, "notificationGroupId": None, "notificationDate": "2024-08-11T14:25:04.634Z", "displayCategory": "General", "messageId": "66b8c9c03139d591a694741b", "vin": "VIN", "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/general.png", "type": "alert", "category": "ChargingAlert", "status": "completed" },

GitOldGrumpy commented 3 months ago

I've pulled across @ajain-93 change if people want to test again.

pbonato commented 3 months ago

I've pulled across @ajain-93 change if people want to test again.

Now it works for me. Thanks

briandelicata commented 3 months ago

I've pulled across @ajain-93 change if people want to test again.

This worked!

ajain-93 commented 3 months ago

What would be the next step in solving this issue? We would need to update this module, as well as update the requirement in ha_toyota to solve issue https://github.com/DurgNomis-drol/ha_toyota/issues/286 to get the HA integration running again.

rhuijben commented 3 months ago

Fetching the car info works for me now. (Never seen notifications for my car yet)

GitOldGrumpy commented 3 months ago

Fixed here, needs someone to update the ha_toyota.

ajain-93 commented 3 months ago

@GitOldGrumpy @CM000n We also need to make a new release to enable fix of DurgNomis-drol/ha_toyota#286. Any ideas on how to proceed on that?

CM000n commented 3 months ago

@GitOldGrumpy @CM000n We also need to make a new release to enable fix of DurgNomis-drol/ha_toyota#286. Any ideas on how to proceed on that?

@DurgNomis-drol seems to have been difficult to reach for some time. Unfortunately, he is the only one who can publish new releases for ha_toyota. Because of this, and because I also have a lot going on in my private life, the development from my side has almost come to a standstill.

ajain-93 commented 3 months ago

@DurgNomis-drol seems to have been difficult to reach for some time. Unfortunately, he is the only one who can publish new releases for ha_toyota. Because of this, and because I also have a lot going on in my private life, the development from my side has almost come to a standstill.

@CM000n Thanks for creating a new release. We just need to wait for @DurgNomis-drol to approve https://github.com/DurgNomis-drol/ha_toyota/issues/287.