Skip to content

Register service actions in async_setup for Bronze tier compliance#1403

Open
ademuri wants to merge 8 commits into
basnijholt:mainfrom
ademuri:bronze-action-setup
Open

Register service actions in async_setup for Bronze tier compliance#1403
ademuri wants to merge 8 commits into
basnijholt:mainfrom
ademuri:bronze-action-setup

Conversation

@ademuri
Copy link
Copy Markdown
Contributor

@ademuri ademuri commented Jan 17, 2026

  • Move 'apply' and 'set_manual_control' service registration from async_setup_entry to async_setup.
  • Move service handlers to module-level functions in switch.py.
  • Update apply_service_schema to support dynamic defaults for transition duration.
  • Clean up related unused imports and fix Python 3.10 syntax compatibility.

Addresses a point from #1195.

@ademuri ademuri marked this pull request as ready for review January 19, 2026 04:40
@ademuri ademuri requested a review from basnijholt as a code owner January 19, 2026 04:40
@basnijholt
Copy link
Copy Markdown
Owner

Awesome! Thanks for all the PRs. There seems to be one failing job still (pre-commit).

@ademuri ademuri marked this pull request as draft January 20, 2026 06:28
@ademuri ademuri force-pushed the bronze-action-setup branch 3 times, most recently from 999fda6 to 0020cdd Compare January 20, 2026 06:43
@ademuri ademuri marked this pull request as ready for review January 20, 2026 06:52
@basnijholt
Copy link
Copy Markdown
Owner

@all-contributors please add @ademuri for code

@allcontributors
Copy link
Copy Markdown
Contributor

@basnijholt

I've put up a pull request to add @ademuri! 🎉

@basnijholt
Copy link
Copy Markdown
Owner

basnijholt commented Jan 20, 2026

Thanks for working on this!

Python 3.12 type syntax

The change from type AdaptiveSwitches = ... to AdaptiveSwitches = ... isn't needed - our earliest supported HA version (2024.12.5) requires Python 3.12, and the type statement was introduced in Python 3.12 (PEP 695). Why did you make this change?

Comment on lines -1684 to -1685
type AdaptiveSwitches = list[AdaptiveSwitch]
type AdaptiveSwitchMap = dict[AdaptiveSwitch, list[str]]
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was a result of running ruff check . --fix. Looks like the Ruff target Python version is currently set to 3.10.

I ran Ruff because Home Assistant core requires it, but I don't see it in either of the READMEs. Should it be used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I reverted this change.

Comment thread README.md Outdated
| `entity_id` | The `entity_id` of the switch with the settings to apply. 📝 | ✅ | list of `entity_id`s |
| `lights` | A light (or list of lights) to apply the settings to. 💡 | ❌ | list of `entity_id`s |
| `transition` | Duration of transition when lights change, in seconds. 🕑 | | `float` 0-6553 |
| `transition` | Duration of transition when lights change, in seconds. 🕑 | | `float` 0-6553 |
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why did you make it a required attribute?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was unintentional, I think related to initial_transition not being present for apply_service_schema. The default is now None in the schema - will that cause any issues?

ademuri and others added 7 commits January 20, 2026 22:07
- Move 'apply' and 'set_manual_control' service registration from async_setup_entry to async_setup.
- Move service handlers to module-level functions in switch.py.
- Update apply_service_schema to support dynamic defaults for transition duration.
- Clean up related unused imports and fix Python 3.10 syntax compatibility.
@ademuri ademuri force-pushed the bronze-action-setup branch from 0020cdd to d3190be Compare January 21, 2026 05:07
@basnijholt
Copy link
Copy Markdown
Owner

Sorry it took me so long to get to this. I've been a bit overwhelmed by the number of AI-assisted PRs opened here recently, and I've also been spending nearly every spare hour on my biggest project so far, MindRoom.

I'm very supportive of using AI for coding, but many of these PRs still need careful human review because even plausible-looking changes can introduce subtle breakage. That backlog made me postpone reviewing them for a while.

I've now done a batch review with Codex / GPT-5.5 (xhigh). This comment is AI-assisted, but I've reviewed it before posting.

The Bronze-tier service-action direction is useful, but this branch is conflict-heavy against current main and touches setup, service registration, docs, and tests.

I do not want to merge or deeply review this version as-is because the integration setup path has changed since this branch was opened. Please rebase onto current main, keep the service-registration change as small as possible, and make sure the service/action tests pass on the current HA matrix.

@basnijholt
Copy link
Copy Markdown
Owner

Follow-up from a deeper Codex / GPT-5.5 (xhigh) pass.

The move toward global service-action registration makes sense for Bronze compliance, but the new change_switch_settings service schema still treats entity_id as optional even though the handler cannot do anything without either entity_id or lights:

vol.Optional(CONF_ENTITY_ID): cv.entity_ids

For change_switch_settings, lights is deliberately skipped because CONF_LIGHTS is not changeable after init, so a call without entity_id only fails later inside _switches_from_service_call() with a ServiceValidationError. For a service/action UI, it would be cleaner and safer to make entity_id required in the schema for this service, so invalid calls are rejected at validation time and the UI communicates the requirement.

Please make the target requirement explicit in change_switch_settings_schema() and add a test that the service schema rejects missing targets before handler logic runs.

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.

2 participants