Add school_day.check_date service to query school-day flags for a given date#2
Add school_day.check_date service to query school-day flags for a given date#2thenoid wants to merge 2 commits into
school_day.check_date service to query school-day flags for a given date#2Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 91d3e0236d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| f"Invalid date '{target_date_raw}'. Use MM-DD-YYYY." | ||
| ) from err | ||
|
|
||
| config_entries = call.hass.config_entries.async_entries(DOMAIN) |
There was a problem hiding this comment.
Query only loaded config entries in check_date service
Use loaded entries instead of async_entries(DOMAIN) here, because this list includes entries that are configured but not loaded (for example setup failures or disabled entries). In those states entry.runtime_data may be missing, so the service can either incorrectly reject calls as "multiple entries" or crash when dereferencing config_entries[0].runtime_data, making school_day.check_date unreliable whenever any non-loaded School Day entry exists.
Useful? React with 👍 / 👎.
| """Unload a config entry.""" | ||
| return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
| unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
| if unload_ok and len(hass.config_entries.async_entries(DOMAIN)) == 1: |
There was a problem hiding this comment.
Remove service based on loaded entries, not total entries
This unload guard checks total configured entries, so the service is left registered when the last loaded entry is unloaded but another non-loaded entry still exists. In that state school_day.check_date remains callable without a valid coordinator and can fail at runtime; the cleanup should instead be keyed off remaining loaded entries.
Useful? React with 👍 / 👎.
Motivation
MM-DD-YYYYformat.Description
school_day.check_dateservice implemented incustom_components/school_day/__init__.pywith schema validation (SERVICE_SCHEMA_CHECK_DATE), a date parser (_parse_mmddyyyy), and a handler (_async_handle_check_date) that returnsdate,school_day,no_school, andsummer_vacationattributes.SchoolDayCoordinator(self.events) and refresh coordinator data before computing the state for the requested date.SupportsResponse.ONLYfor the service response pattern.custom_components/school_day/const.pyforSERVICE_CHECK_DATEand the returned attribute names, addservices.yamlmetadata, updateREADME.mdwith usage and examples, and bump the integrationversioninmanifest.json.Testing
Codex Task