Fix stale prayer times from `islamic-prayer-times`
Proposed change
There was a report of stale prayer times with this integration.
Looking at the logic that controls the recomputation, it appears somewhat fragile:
- It expects the presence of a bug no longer present in the cloud API (see 1 and 2), and never present in the offline computation. This issue saw times returned with correct times but incorrect dates, and was previously worked around by the +1 day timedeltas applied to the "Midnight" time (note the old Midnight timestamp's date in the test files). Without the upstream bug, this would result in the update being scheduled an extra day into the future, meaning a day of stale times. The first of the two API fixes occurred about a month ago, corresponding with the filing date of the issue.
- It assumes that recalculation only occurs on the intended schedule, even though a user might reload/reconfigure the integration (or restart HA) at any time
- It does not correctly account for prayers which occur after 00:00/midnight (or before the prior midnight), which can lead to prayer times that are perpetually in the past or future and are never actually reached
This PR removes the expectation of the API dating bug, changes the recalculation logic to ensure that the displayed prayer times are always those for the current day (no matter what triggered the recalculation), and simplifies the scheduling logic as a result of these changes.
Type of change
- [ ] Dependency upgrade
- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
Additional information
- This PR fixes or closes issue: fixes #113203, fixes #115831
- This PR is related to issue:
- Link to documentation pull request:
Checklist
- [x] The code change is tested and works locally.
- [x] Local tests pass. Your PR cannot be merged unless tests pass
- [x] There is no commented out code in this PR.
- [x] I have followed the development checklist
- [x] I have followed the perfect PR recommendations
- [x] The code has been formatted using Ruff (
ruff format homeassistant tests) - [x] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for www.home-assistant.io
If the code communicates with devices, web services, or third-party tools:
- [ ] The manifest file has all fields filled out correctly.
Updated and included derived files by running:python3 -m script.hassfest. - [ ] New or updated dependencies have been added to
requirements_all.txt.
Updated by runningpython3 -m script.gen_requirements_all. - [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to
.coveragerc.
To help with the load of incoming pull requests:
- [x] I have reviewed two other open pull requests in this repository.
Hey there @engrbm87, mind taking a look at this pull request as it has been labeled with an integration (islamic_prayer_times) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of islamic_prayer_times can trigger bot actions by commenting:
@home-assistant closeCloses the pull request.@home-assistant rename Awesome new titleRenames the pull request.@home-assistant reopenReopen the pull request.@home-assistant unassign islamic_prayer_timesRemoves the current integration label and assignees on the pull request, add the integration domain after the command.@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.@home-assistant remove-label needs-more-informationRemove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.