Skip to content

Commit

Permalink
fix handling for timestrings without date
Browse files Browse the repository at this point in the history
  • Loading branch information
FaserF committed Feb 26, 2025
1 parent b56c8ca commit 3468994
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions custom_components/db_infoscreen/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ def format_departure_time(self, departure_time):
departure_time = datetime.fromtimestamp(departure_time)
_LOGGER.debug("Converted departure time from timestamp: %s", departure_time)

elif isinstance(departure_time, str): # Falls der Zeitstempel als String geliefert wird
elif isinstance(departure_time, str):
try:
departure_time = datetime.strptime(departure_time, "%Y-%m-%d %H:%M:%S")
_LOGGER.debug("Converted departure time from string: %s", departure_time)
except ValueError:
_LOGGER.warning("Unable to parse departure time from string: %s", departure_time)
return None
try:
departure_time = datetime.strptime(f"{datetime.now().date()} {departure_time}", "%Y-%m-%d %H:%M")
_LOGGER.debug("Converted departure time from time string: %s", departure_time)
except ValueError:
_LOGGER.warning("Unable to parse departure time from string: %s", departure_time)
return None

if isinstance(departure_time, datetime):
_LOGGER.debug("Checking departure time date: %s", departure_time.date())
Expand Down

0 comments on commit 3468994

Please sign in to comment.