Add optional speed parameter to cover movement actions - #176231
Conversation
|
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
There was a problem hiding this comment.
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. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
CLA is clean |
There was a problem hiding this comment.
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 assupported_speeds(capability attribute). As written, the UI will look up a non-existent attribute. Update the selector to referencesupported_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_POSITIONbut still uses the literal key\"position\"in a couple of service calls. UsingATTR_POSITIONconsistently 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_POSITIONbut still uses the literal key\"position\"in a couple of service calls. UsingATTR_POSITIONconsistently 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
speedultimately comes from user/service input (and demo code normalizes via.upper()for Enum lookup), consider normalizing (e.g.,speed = speed.lower().strip()and storingsupportednormalized 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)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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 raiseKeyErrorif an invalid/unexpectedspeedreaches 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 toDEFAULTor raising aServiceValidationErrorwith 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 raiseKeyErrorif an invalid/unexpectedspeedreaches 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 toDEFAULTor raising aServiceValidationErrorwith 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 raiseKeyErrorif an invalid/unexpectedspeedreaches 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 toDEFAULTor raising aServiceValidationErrorwith 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 importedATTR_POSITIONconstant. UsingATTR_POSITIONconsistently 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 importedATTR_POSITIONconstant. UsingATTR_POSITIONconsistently avoids typos and keeps tests aligned with the domain API surface.
{ATTR_ENTITY_ID: ent2.entity_id, "position": 49, ATTR_SPEED: "ignore"},
|
In general this looks good. The selector config comment above needs to be addressed. |
This comment was marked as resolved.
This comment was marked as resolved.
Done.
Agreed, it feels weird but I couldn't find anywhere where it causes an actual problem/weirdness. |
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
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: