Skip to content

Add school_day.check_date service to query school-day flags for a given date#2

Open
thenoid wants to merge 2 commits into
mainfrom
codex/add-service-call-to-check-date-0ta6cf
Open

Add school_day.check_date service to query school-day flags for a given date#2
thenoid wants to merge 2 commits into
mainfrom
codex/add-service-call-to-check-date-0ta6cf

Conversation

@thenoid
Copy link
Copy Markdown
Owner

@thenoid thenoid commented May 7, 2026

Motivation

  • Provide an on-demand service to compute school-day flags for an arbitrary date in MM-DD-YYYY format.
  • Allow selecting a specific integration instance when multiple School Day config entries exist.
  • Document the new service and make the integration expose the same metadata used by sensors for debugging and automation.

Description

  • Add a school_day.check_date service implemented in custom_components/school_day/__init__.py with schema validation (SERVICE_SCHEMA_CHECK_DATE), a date parser (_parse_mmddyyyy), and a handler (_async_handle_check_date) that returns date, school_day, no_school, and summer_vacation attributes.
  • Store parsed calendar events on the SchoolDayCoordinator (self.events) and refresh coordinator data before computing the state for the requested date.
  • Register and unregister the service on setup/unload and use SupportsResponse.ONLY for the service response pattern.
  • Add new constants in custom_components/school_day/const.py for SERVICE_CHECK_DATE and the returned attribute names, add services.yaml metadata, update README.md with usage and examples, and bump the integration version in manifest.json.

Testing

  • No automated tests were run for these changes.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant