tchellomello / python-ring-doorbell

Python Ring Door Bell is a library written in Python 3 that exposes the Ring.com devices as Python objects.
GNU Lesser General Public License v3.0
537 stars 171 forks source link

time data does not match format #381

Open jubishop opened 1 month ago

jubishop commented 1 month ago

from running the listen command, on every event i get on the command line:

Ring CLI
INFO:firebase_messaging.fcmpushclient:Registered with FCM
INFO:firebase_messaging.fcmpushclient:Succesfully logged in to MCS endpoint
Listening, press enter to cancel
 ERROR:firebase_messaging.fcmpushclient:Unexpected exception calling notification callback
Traceback (most recent call last):
  File "/Users/jubi/Library/Python/3.9/lib/python/site-packages/firebase_messaging/fcmpushclient.py", line 425, in _handle_data_message
    callback(ret_val, msg.persistent_id, obj)
  File "/Users/jubi/Library/Python/3.9/lib/python/site-packages/ring_doorbell/listen/eventlistener.py", line 250, in _on_notification
    re = self._get_ding_event(gcm_data)
  File "/Users/jubi/Library/Python/3.9/lib/python/site-packages/ring_doorbell/listen/eventlistener.py", line 207, in _get_ding_event
    datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%S.%f%z")
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '2024-05-14T19:29:28Z' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'
jubishop commented 1 month ago

so at least on my machine, line 207 of eventlistener.py needs to become:

datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%SZ")
jubishop commented 1 month ago

sorry i'm too much of a python noob to know how to run your tests to make a proper git commit here. i just know changing that line makes it work for me. my guess is, looking at the format that was failing, that for whatever reason my device is not providing milliseconds (thus no .%f at the end of the strptime format). You could check for that using a regex and then run the right one, or put this first one in a try and then run the second in a catch (or whatever the equivalent is in python). in any case, thanks for this library! once i fixed that line, it's working great for me to listen for events and then trigger a recording with a different security camera via ZoneMinder.