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

Python bug with strptime #692

Closed
5 tasks
FilipDem opened this issue Nov 29, 2024 · 5 comments · Fixed by #697
Closed
5 tasks

Python bug with strptime #692

FilipDem opened this issue Nov 29, 2024 · 5 comments · Fixed by #697
Labels
bug 🐛 Something isn't working

Comments

@FilipDem
Copy link

Describe the issue

As described in https://bugs.python.org/issue27400, there is a bug in python when using it in embedded python. Calling datetime.datetime.strptime, could result in TypeError: 'NoneType' object is not callable.
Currently I am running into that case with my integration in Domoticz on https://github.com/bimmerconnected/bimmer_connected/blob/master/bimmer_connected/utils.py#L32, because of trying to get the timestamp of the data through https://github.com/bimmerconnected/bimmer_connected/blob/master/bimmer_connected/vehicle/vehicle.py#L224.

A workaround is described in the bug report and sample code can be found below.
Currently I implemented the workaround by not using the vehicle timestamp property, but rather getting the timestamp by parsing the vehicle data myself from the https://github.com/bimmerconnected/bimmer_connected/blob/master/bimmer_connected/vehicle/vehicle.py#L86.

def DateStringtoDateTime(DateStr, DateFrm='%Y-%m-%d %H:%M:%S'):
    Datim = None
    if DateStr:
        try:
            Datim = datetime.strptime(DateStr, DateFrm)
        except TypeError:
            try:
                import time
                Datim = datetime(*(time.strptime(DateStr, DateFrm)[0:6]))
            except:
                pass
    return Datim

Expected behavior

Would it be possible to implement this workaround in the https://github.com/bimmerconnected/bimmer_connected/blob/master/bimmer_connected/utils.py#L32?

Which Home Assistant version are you using?

(using Domoticz)

What was the last working version of Home Assistant Core?

No response

What is your region?

Rest of world

MyBMW website

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

Number of cars

  • I have 2 or more cars linked to the MyBMW account.
  • I have a Mini vehicle linked to my account.
  • I have a Toyota Supra 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

@FilipDem FilipDem added the bug 🐛 Something isn't working label Nov 29, 2024
@rikroe
Copy link
Member

rikroe commented Nov 29, 2024

I thought this error was only applicable to embedded Pythons <= 3.7 (which we don't support anymore)?

What version are you running?

@rikroe
Copy link
Member

rikroe commented Nov 29, 2024

Nevermind, it seems to have continued - see the discussion moved to Github python/cpython#71587.

It is fixed for Python 3.12 and 3.13 since June, again the question of what Domoticz uses as Python version.

As you have a workaround, I would first like to understand a little when/if this upstream bugfix could be in your system.

@FilipDem
Copy link
Author

Bullseye... So python 3.9... Far from the 3.12 :-(.
It would help me, but understand your reasoning as I have a workaround. I just hope that the structure of the data won't change then. I will respect whatever decision you make.
Filip

@rikroe
Copy link
Member

rikroe commented Nov 30, 2024

Hi @FilipDem, can you check if #697 fixes your issue?

@FilipDem
Copy link
Author

Hey! Thanks a lot!
This works now (and also the location works again following the discussion #694).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants