mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Fix typing for dt_util as_timestamp (#50886)
* Fix typing for dt_util::as_timestamp * Apply suggestions from code review
This commit is contained in:
parent
92d1871de5
commit
15e2c6d7dc
@ -79,10 +79,11 @@ def as_utc(dattim: dt.datetime) -> dt.datetime:
|
||||
return dattim.astimezone(UTC)
|
||||
|
||||
|
||||
def as_timestamp(dt_value: dt.datetime) -> float:
|
||||
def as_timestamp(dt_value: dt.datetime | str) -> float:
|
||||
"""Convert a date/time into a unix time (seconds since 1970)."""
|
||||
if hasattr(dt_value, "timestamp"):
|
||||
parsed_dt: dt.datetime | None = dt_value
|
||||
parsed_dt: dt.datetime | None
|
||||
if isinstance(dt_value, dt.datetime):
|
||||
parsed_dt = dt_value
|
||||
else:
|
||||
parsed_dt = parse_datetime(str(dt_value))
|
||||
if parsed_dt is None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user