Merge pull request #1231 from paddatrapper/fix/python-valueerror

Allow schedule times without microseconds in api_client
This commit is contained in:
Kyle Robbertze 2021-06-17 21:03:37 +02:00 committed by GitHub
commit d5781d198c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -198,5 +198,8 @@ def fromisoformat(time_string):
only added in Python 3.7. Until LibreTime drops Python 3.6 support, this only added in Python 3.7. Until LibreTime drops Python 3.6 support, this
wrapper uses the old way of doing it. wrapper uses the old way of doing it.
""" """
datetime_obj = datetime.datetime.strptime(time_string, "%H:%M:%S.%f") try:
datetime_obj = datetime.datetime.strptime(time_string, "%H:%M:%S.%f")
except ValueError:
datetime_obj = datetime.datetime.strptime(time_string, "%H:%M:%S")
return datetime_obj.time() return datetime_obj.time()

View File

@ -51,6 +51,7 @@ def test_get_protocol_force_https(payload, use_config, values, expected):
[ [
("00:00:00.500000", datetime.time(microsecond=500000)), ("00:00:00.500000", datetime.time(microsecond=500000)),
("00:04:30.092540", datetime.time(minute=4, second=30, microsecond=92540)), ("00:04:30.092540", datetime.time(minute=4, second=30, microsecond=92540)),
("00:04:30", datetime.time(minute=4, second=30)),
], ],
) )
def test_fromisoformat(payload, expected): def test_fromisoformat(payload, expected):