bimmerconnected / bimmer_connected

🚘 Library to query the status of your BMW or Mini from the ConnectedDrive portal
Apache License 2.0
373 stars 81 forks source link

parse_datetime reports error on missing lastFetched field #610

Closed rleidner closed 6 months ago

rleidner commented 6 months ago

Describe the issue

I get this error:

unable to parse 'None' using ['%Y-%m-%dT%H:%M:%S.%f%z', '%Y-%m-%dT%H:%M:%S%z', '%Y-%m-%dT%H:%M:%S.%fZ', '%Y-%m-%dT%H:%M:%SZ']

For the car there is no "lastFetched" in attributes.

I think this code in bimmer_connected/utils.py: def parse_datetime(date_str: str) -> Optional[datetime.datetime]: """Convert a time string into datetime.""" if not date_str: return None date_formats = ["%Y-%m-%dT%H:%M:%S.%f%z", "%Y-%m-%dT%H:%M:%S%z", "%Y-%m-%dT%H:%M:%S.%fZ", "%Y-%m-%dT%H:%M:%SZ"] should rather be: def parse_datetime(date_str: str) -> Optional[datetime.datetime]: """Convert a time string into datetime.""" if not date_str or date_str = "None": return None date_formats = ["%Y-%m-%dT%H:%M:%S.%f%z", "%Y-%m-%dT%H:%M:%S%z", "%Y-%m-%dT%H:%M:%S.%fZ", "%Y-%m-%dT%H:%M:%SZ"]

The calling vehicle/vehicle.py converts None to "None"...

Expected behavior

avoid the error message

Which Home Assistant version are you using?

bimmerconnected cli

What was the last working version of Home Assistant Core?

n/a

What is your region?

Rest of world

MyBMW website

Number of cars

Output of bimmer_connected fingerprint

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

rikroe commented 6 months ago

Thanks, hope the PR solves it.

rleidner commented 6 months ago

Thanks, that was fast. Is solved!