Skip to content

Commit

Permalink
Handle updated timestamp format in condition.json
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Two committed Nov 10, 2023
1 parent f37a877 commit 85535df
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion subarulink/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
For more details about this api, please refer to the documentation at
https://github.com/G-Two/subarulink
"""
__version__ = "0.7.8"
__version__ = "0.7.9"
5 changes: 3 additions & 2 deletions subarulink/_subaru_api/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@
API_WINDOW_SUNROOF_STATUS = "windowSunroofStatus"

# Timestamp formats
API_TIMESTAMP_FMT = "%Y-%m-%dT%H:%M:%S%z" # "2020-04-25T23:35:55+0000"
API_TIMESTAMP_FMT = "%Y-%m-%dT%H:%M:%S.%f%z" # "2020-04-25T23:35:55.000+0000"
API_TIMESTAMP_FMT_OLD = "%Y-%m-%dT%H:%M:%S%z" # "2020-04-25T23:35:55+0000"
API_VS_TIMESTAMP_FMT = "%Y-%m-%dT%H:%M%z" # "2020-04-25T23:35+0000"
API_POSITION_TIMESTAMP_FMT = "%Y-%m-%dT%H:%M:%SZ" # "2020-04-25T23:35:55Z"
API_POSITION_TIMESTAMP_FMT = "%Y-%m-%dT%H:%M:%S%fZ" # "2020-04-25T23:35:55Z"

# selectVehicle.json keys
API_VEHICLE_ATTRIBUTES = "attributes"
Expand Down
5 changes: 4 additions & 1 deletion subarulink/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,10 @@ async def _parse_condition(
sc.DOOR_REAR_RIGHT_POSITION: data[api.API_DOOR_REAR_RIGHT_POSITION],
sc.LAST_UPDATED_DATE: data[api.API_LAST_UPDATED_DATE],
}
keep_data[sc.TIMESTAMP] = datetime.strptime(data[api.API_LAST_UPDATED_DATE], api.API_TIMESTAMP_FMT)
try:
keep_data[sc.TIMESTAMP] = datetime.strptime(data[api.API_LAST_UPDATED_DATE], api.API_TIMESTAMP_FMT)
except ValueError:
keep_data[sc.TIMESTAMP] = datetime.strptime(data[api.API_LAST_UPDATED_DATE], api.API_TIMESTAMP_FMT_OLD)

# Only some (probably G3) vehicles properly report fuel remaining
if data[api.API_REMAINING_FUEL_PERCENT]:
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/condition.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"tirePressureRearLeftUnit": "PSI",
"tirePressureRearRight": null,
"tirePressureRearRightUnit": "PSI",
"lastUpdatedTime": "2022-09-27T11:22:15+0000",
"lastUpdatedTime": "2022-09-27T11:22:15.000+0000",
"windowFrontLeftStatus": "VENTED",
"windowFrontRightStatus": "VENTED",
"windowRearLeftStatus": "UNKNOWN",
Expand Down

0 comments on commit 85535df

Please sign in to comment.