Skip to content

Fix get_astral_location deprecation warning#859

Merged
craigbarratt merged 1 commit into
custom-components:masterfrom
dmamelin:fix-astral-location
Jul 3, 2026
Merged

Fix get_astral_location deprecation warning#859
craigbarratt merged 1 commit into
custom-components:masterfrom
dmamelin:fix-astral-location

Conversation

@dmamelin

@dmamelin dmamelin commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

sunrise/sunset triggers used sun.get_astral_location(), which HA deprecated (removal in 2027.7) and warned on every use. Switched to the higher-level sun.get_astral_event_date(), which avoids the deprecated API entirely and needs no version fallback.

This also restores elevation support, which was inadvertently dropped in 300a633 when a local get_astral_event_date copy omitted the observer_elevation argument. No behavior change at the default elevation of 0; existing tests pass.

On dropping async_add_executor_job: the executor wrapping was added in 884c428 (PR #610) to move the blocking location.sunrise()/sunset() calls (timezone data loaded from disk) off the event loop. That's no longer needed here: get_astral_event_date() is a HA @callback (loop-safe by contract, and called synchronously by HA itself), and it computes in UTC - the local conversion uses the timezone already cached at startup via dt_util.as_local(). So the call runs directly on the loop without reintroducing the blocking I/O.

Fixes #858.

@craigbarratt craigbarratt merged commit 9448578 into custom-components:master Jul 3, 2026
6 checks passed
@craigbarratt

Copy link
Copy Markdown
Member

Thanks for the PR; much cleaner now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The deprecated function get_astral_location was called from pyscript

2 participants