-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't raise errors when using datetime objects in as_datetime
Jinja function/filter
#109062
Conversation
as_datetime
Jinja function/filteras_datetime
Jinja function/filter
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Still waiting for a review :) |
@MartinHjelmare The previous PR was #107229 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks @TheFes 👍
The PR can be merged when there's a PR updating the documentation, can you look into that @TheFes ? |
Docs added |
Failing tests are unrelated |
… function/filter (home-assistant#109062) * add support for datetime objects to as_datetime * change import of datetime.date --------- Co-authored-by: Erik Montnemery <erik@montnemery.com>
Proposed change
The
as_datetime
function/filter currently errors when a datetime object is used as value. This can be very annoying when it is unclear if a value is already a datetime object, or a string. Attribute values of entities can be native types, but in case of datetime objects they are shown as isoformat datetime strings in developer tools > states.Different (custom) integrations use this differently, eg some custom integration with energy price forecast attributes use datetime objects (Nordpool) and others use datetime isoformat string (ENTSO-E).
This PR adds support for datetime objects to
as_datetime
. In case a full datetime object is used as value, it will retrun the object without changes. In case a datetime.date is used as value it will add midnight (just like it would for a date string like"2024-01-29"
)Type of change
Additional information
as_datetime
in templating docs home-assistant.io#32424Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: