DurgNomis-drol / ha_toyota

Toyota Connected Services integration for Home Assistant.
MIT License
148 stars 32 forks source link

No entities loaded: vin none is not an allowed value #294

Closed Szeryff closed 2 months ago

Szeryff commented 2 months ago

Describe the bug Since yesterday I'm getting an error message

1 validation error for NotificationResponseModel payload -> 0 -> notifications -> 17 -> vin none is not an allowed value (type=type_error.none.not_allowed)

and after that 3 additional errors follows:

Error while setting up toyota platform for binary_sensor

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 364, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/toyota/binary_sensor.py", line 232, in async_setupentry for index, in enumerate(coordinator.data): ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'NoneType' object is not iterable

and

Error while setting up toyota platform for device_tracker

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 364, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/toyota/device_tracker.py", line 39, in async_setup_entry for index, vehicle in enumerate(coordinator.data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'NoneType' object is not iterable

and

Error while setting up toyota platform for sensor

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 364, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/toyota/sensor.py", line 209, in async_setupentry for index, in enumerate(coordinator.data): ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'NoneType' object is not iterable

To Reproduce When loading integration with my credentials no entities are added and those errors can be found in logs. From working integration all entities became unavailable. When re-added the whole integration, no entities are loaded after successful giving the credentials.

Additional context 2 days ago it was working with version 2.0.4 and HA 2024.8.2.

CM000n commented 2 months ago

Yesterday I received an e-mail from Toyota Germany that there have been general problems with Toyota Connected Services since August 17th. Your problem may also be related to this?

Szeryff commented 2 months ago

I think there were problems with Toyota servers on August 16th-17th, and indeed MyToyota app didn't work but since then application works like a charm. I'm afraid it's something else. Just updated to 2.0.5 version and issue is still the same.

CM000n commented 2 months ago

OK, then they must have changed something in the API again. 🙄 Thanks for the notification.

Szeryff commented 2 months ago

Today I also saw this error message before 3 error messages above:

3 validation errors for NotificationResponseModel statusCode field required (type=value_error.missing) headers field required (type=value_error.missing) body field required (type=value_error.missing)

Szeryff commented 2 months ago

Here is what I can currently find in log file. No entities are loaded. Any chance on fixing that?

2024-08-27 20:57:45.002 ERROR (MainThread) [custom_components.toyota] 1 validation error for NotificationResponseModel payload -> 0 -> notifications -> 20 -> vin none is not an allowed value (type=type_error.none.not_allowed) 2024-08-27 20:57:45.003 DEBUG (MainThread) [custom_components.toyota] Finished fetching toyota data in 0.665 seconds (success: True) 2024-08-27 20:57:45.003 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up toyota platform for binary_sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 364, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/toyota/binary_sensor.py", line 232, in async_setupentry for index, in enumerate(coordinator.data): ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'NoneType' object is not iterable 2024-08-27 20:57:45.004 ERROR (MainThread) [homeassistant.components.device_tracker] Error while setting up toyota platform for device_tracker Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 364, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/toyota/device_tracker.py", line 39, in async_setup_entry for index, vehicle in enumerate(coordinator.data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'NoneType' object is not iterable 2024-08-27 20:57:45.005 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up toyota platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 364, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/toyota/sensor.py", line 209, in async_setupentry for index, in enumerate(coordinator.data): ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'NoneType' object is not iterable

ajain-93 commented 2 months ago

@Szeryff I am unable to replicate this one for my notification history. Based on your history this notification has now moved from position 17 to 20, so hopefully, leaving your car unlocked should clear this from the history soon.

But, if we would like to troubleshoot. Can you check your app for what are the oldest notifications you have?

If you are comfertable enough with python to help troubleshoot, I'd greatly appriciate if you could help with the payload (in the underlying mytoyota lib). Add this to https://github.com/DurgNomis-drol/mytoyota/blob/master/mytoyota/controller.py#L303

        if "notification" in endpoint:
            print(json.dumps({"request": {"method": method, "endpoint":endpoint, "vin": vin, "body": body, "params": params, "headers": headers,}, "response": response.json()}, indent=4))

Make sure to anonymise any personal details.

Szeryff commented 2 months ago

@ajain-93 thank you for advising that. I have used the mytoyota lib adding additional line from you and found the notification that was messing up wit the code. It looks like this one doesn't have VIN specified:

                {
                    "title": null,
                   "message": "Wykryto usterk\u0119 w\u00a0uk\u0142adzie hamulca postojowego. Skontaktuj\u00a0si\u0119 z\u00a0autoryzowan\u0105 stacj\u0105 obs\u0142ugi w\u00a0celu niezw\u0142ocznego sprawdzenia samochodu.",
                   "messageKey": "vhr_warning_push_notification_epbw",
                   "isRead": true,
                   "notificationGroupId": "3c214d56-c786-4f1e-afa6-3a74521ffa62",
                   "notificationDate": "2024-08-19T09:49:58.995Z",
                   "readTimestamp": "2024-08-19T09:55:39.276Z",
                   "displayCategory": "General",
                   "messageId": "66c315460e2f4139b16b7e4d",
                   "vin": null,
                  "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/general.png",
                  "type": "alert",
                  "category": "WarningLights",
                  "status": null
              },

Hopefully allowing null value for VIN could be added in future release because it looks like Toyota is not pushing all the information everytime,

Szeryff commented 2 months ago

@ajain-93 I have also followed your advise that there is a limited number of notifications stored by the API and generated multiple new ones that have cleared out the "null-vin" one from history. All entities are loaded correctly now. Thank you!

However I think it would be good to have ha_toyota handle such case anyway.

CM000n commented 2 months ago

@ajain-93 I have also followed your advise that there is a limited number of notifications stored by the API and generated multiple new ones that have cleared out the "null-vin" one from history. All entities are loaded correctly now. Thank you!

However I think it would be good to have ha_toyota handle such case anyway.

The ha_toyota integration can Not handle this by itself. The error ist raised by the mytoyota python lib, before the ha_toyota integration can do anything with it.

There is a new version 2.2.0 of the mytoyota lib available since yesterday. This version allows None values for all fields. Can you please check the behaviour with this new version.

Szeryff commented 2 months ago

Good. I thought error is coming from ha_toyota integration. In that case we can close this bug.

Unfortunately I have already pushed out this notification from my car history so cannot test it again.