Skip to content

Add optional speed parameter to cover movement actions - #176231

Open
wollew wants to merge 37 commits into
home-assistant:devfrom
wollew:cover_speed_simplified_proposal
Open

Add optional speed parameter to cover movement actions#176231
wollew wants to merge 37 commits into
home-assistant:devfrom
wollew:cover_speed_simplified_proposal

Conversation

@wollew

@wollew wollew commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Breaking change

Proposed change

This PR adds an optional speed parameter to cover open/close/set_position actions, as discussed in this architecture proposal. I've tested it with the velux integration to work as expected. This is my first PR for one of the base entities, so bear with me if this is maybe not quite up to standard, especially the tests. Happy to take hints and improve.

Type of change

  • Dependency upgrade
  • 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

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

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 running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant

Copy link
Copy Markdown
Contributor

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (cover) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of cover can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign cover Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

@wollew
wollew marked this pull request as ready for review July 10, 2026 19:26
@wollew
wollew requested a review from a team as a code owner July 10, 2026 19:26
Comment thread homeassistant/components/cover/services.yaml Outdated
Comment thread homeassistant/components/cover/strings.json Outdated
@home-assistant
home-assistant Bot marked this pull request as draft July 11, 2026 12:27
@home-assistant

Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

Copilot AI balanced review requested due to automatic review settings July 11, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds optional, entity-defined speed selection to cover movement actions.

Changes:

  • Adds speed capability metadata and validation.
  • Exposes speed fields in service definitions.
  • Adds service and validation tests.

Outstanding feedback: Translation-reference clarification remains unresolved in this review thread.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
cover/__init__.py Implements speed validation and dispatch.
cover/const.py Defines speed attributes.
cover/services.yaml Exposes speed service fields.
cover/strings.json Adds field and error translations.
cover/common.py Extends test cover behavior.
cover/conftest.py Adds a speed-capable fixture.
cover/test_init.py Tests speed services and validation.

Comment thread homeassistant/components/cover/__init__.py Outdated
Comment thread homeassistant/components/cover/__init__.py Outdated
Comment thread homeassistant/components/cover/__init__.py Outdated
Comment thread homeassistant/components/cover/services.yaml Outdated
Comment thread homeassistant/components/cover/strings.json Outdated
Copilot AI review requested due to automatic review settings July 11, 2026 20:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.

Comment thread homeassistant/components/cover/__init__.py Outdated
Comment thread homeassistant/components/cover/__init__.py Outdated
Comment thread homeassistant/components/cover/__init__.py Outdated
Comment thread homeassistant/components/cover/services.yaml Outdated
Comment thread tests/components/cover/test_init.py Outdated
Comment thread tests/components/cover/test_init.py Outdated
Comment thread tests/components/cover/test_init.py Outdated
Comment thread tests/components/cover/test_init.py Outdated
Comment thread tests/components/cover/test_init.py Outdated
Comment thread tests/components/cover/test_init.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 11, 2026 20:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Comment thread homeassistant/components/cover/__init__.py Outdated
Comment thread homeassistant/components/cover/__init__.py Outdated
Comment thread tests/components/cover/test_init.py Outdated
Comment thread tests/components/cover/test_init.py Outdated
Copilot AI review requested due to automatic review settings July 11, 2026 20:21
@karwosts

Copy link
Copy Markdown
Member

CLA is clean

Copilot AI review requested due to automatic review settings August 18, 2026 20:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Suppressed comments (4)

homeassistant/components/cover/services.yaml:17

  • The selector references attribute: speed, but the entity exposes the list as supported_speeds (capability attribute). As written, the UI will look up a non-existent attribute. Update the selector to reference supported_speeds (or adjust the selector type if the intent is to select from a list capability attribute).
  fields:
    speed:
      example: "fast"
      filter:
        supported_features:
          - cover.CoverEntityFeature.SPEED
      selector:
        state:
          attribute: speed

tests/components/cover/test_init.py:252

  • This test file imports ATTR_POSITION but still uses the literal key \"position\" in a couple of service calls. Using ATTR_POSITION consistently will avoid accidental typos and make future refactors (renames/aliases) safer.
        {ATTR_ENTITY_ID: speed_cover.entity_id, "position": 75, ATTR_SPEED: "default"},

tests/components/cover/test_init.py:315

  • This test file imports ATTR_POSITION but still uses the literal key \"position\" in a couple of service calls. Using ATTR_POSITION consistently will avoid accidental typos and make future refactors (renames/aliases) safer.
        {ATTR_ENTITY_ID: ent2.entity_id, "position": 49, ATTR_SPEED: "ignore"},

homeassistant/components/cover/init.py:357

  • Speed validation is currently case-sensitive. Since speed ultimately comes from user/service input (and demo code normalizes via .upper() for Enum lookup), consider normalizing (e.g., speed = speed.lower().strip() and storing supported normalized similarly) to make validation more robust and avoid surprising errors from casing/whitespace.
    def _valid_speed_or_raise(self, speed: str, supported: list[str]) -> None:
        """Raise ServiceValidationError if speed is not in the supported list."""
        if speed not in supported:
            supported_str = ", ".join(supported)

Comment thread homeassistant/components/cover/__init__.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

This comment was marked as duplicate.

This comment was marked as duplicate.

This comment was marked as duplicate.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Suppressed comments (5)

homeassistant/components/demo/cover.py:166

  • Indexing the enum via Speed[...] will raise KeyError if an invalid/unexpected speed reaches these methods (including case/format mismatches). Even though the new service handlers validate for normal service calls, these entity methods can still be invoked from other code paths/tests. Consider defensively handling unknown speeds (e.g., fallback to DEFAULT or raising a ServiceValidationError with the same translation key) to avoid uncaught exceptions.
        self._current_speed = Speed[kwargs.get(ATTR_SPEED, "DEFAULT").upper()]

homeassistant/components/demo/cover.py:192

  • Indexing the enum via Speed[...] will raise KeyError if an invalid/unexpected speed reaches these methods (including case/format mismatches). Even though the new service handlers validate for normal service calls, these entity methods can still be invoked from other code paths/tests. Consider defensively handling unknown speeds (e.g., fallback to DEFAULT or raising a ServiceValidationError with the same translation key) to avoid uncaught exceptions.
        self._current_speed = Speed[kwargs.get(ATTR_SPEED, "DEFAULT").upper()]

homeassistant/components/demo/cover.py:212

  • Indexing the enum via Speed[...] will raise KeyError if an invalid/unexpected speed reaches these methods (including case/format mismatches). Even though the new service handlers validate for normal service calls, these entity methods can still be invoked from other code paths/tests. Consider defensively handling unknown speeds (e.g., fallback to DEFAULT or raising a ServiceValidationError with the same translation key) to avoid uncaught exceptions.
        self._current_speed = Speed[kwargs.get(ATTR_SPEED, "DEFAULT").upper()]

tests/components/cover/test_init.py:252

  • These service payloads use the literal key \"position\" instead of the imported ATTR_POSITION constant. Using ATTR_POSITION consistently avoids typos and keeps tests aligned with the domain API surface.
        {ATTR_ENTITY_ID: speed_cover.entity_id, "position": 75, ATTR_SPEED: "default"},

tests/components/cover/test_init.py:318

  • These service payloads use the literal key \"position\" instead of the imported ATTR_POSITION constant. Using ATTR_POSITION consistently avoids typos and keeps tests aligned with the domain API surface.
        {ATTR_ENTITY_ID: ent2.entity_id, "position": 49, ATTR_SPEED: "ignore"},

Comment thread homeassistant/components/cover/services.yaml
@MartinHjelmare

Copy link
Copy Markdown
Member

In general this looks good. The selector config comment above needs to be addressed.

This comment was marked as duplicate.

@karwosts

This comment was marked as resolved.

@wollew

wollew commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Can you add translation strings to demo

Done.

I think you will have to add translations for the "speed" attribute, even though it doesn't actually exist as an attribute. I am not sure if that will cause any weirdness.

Agreed, it feels weird but I couldn't find anywhere where it causes an actual problem/weirdness.

This comment was marked as duplicate.

This comment was marked as duplicate.

This comment was marked as duplicate.

Comment thread homeassistant/components/demo/cover.py Outdated
Comment thread homeassistant/components/demo/cover.py Outdated
Comment thread homeassistant/components/demo/cover.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gjohansson-ST gjohansson-ST left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @wollew 👍🏼

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants