-
-
Notifications
You must be signed in to change notification settings - Fork 36.4k
Modernise condition checker in helper #159159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modernise condition checker in helper #159159
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
|
|
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
|
|
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
|
|
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
|
1b14190 to
536f1bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR modernizes the condition checker interface in Home Assistant's helper module, making it more consistent, extensible, and type-safe. The changes rename ConditionCheckerType to ConditionChecker, remove the hass parameter from the new interface (conditions now use self._hass), switch to kwargs-based parameters for future extensibility, and automatically apply tracing through a wrapper function.
Key changes:
- New
ConditionCheckerProtocol with typed kwargs usingConditionCheckParamsTypedDict for extensibility - Backward compatibility maintained via
ConditionCheckerTypeandConditionCheckerTypeOptionalfor legacy code - Integration conditions (zone, sun, light, device_automation) updated to use new interface pattern with
**kwargs: Unpack[ConditionCheckParams]
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/helpers/condition.py |
Introduces new ConditionChecker Protocol with TypedDict params, adds wrapper function _async_get_checker to automatically apply tracing, maintains backward compatibility types |
homeassistant/helpers/script.py |
Updates type annotations to use ConditionCheckerTypeOptional for backward compatibility with existing script code |
homeassistant/components/zone/condition.py |
Migrates to new interface: removes hass parameter, uses **kwargs: Unpack[ConditionCheckParams], accesses self._hass instead, removes manual trace_condition_function call |
homeassistant/components/sun/condition.py |
Migrates to new interface: removes hass parameter, uses **kwargs: Unpack[ConditionCheckParams], accesses self._hass instead, removes manual trace_condition_function call |
homeassistant/components/light/condition.py |
Migrates to new interface: removes hass parameter, uses **kwargs: Unpack[ConditionCheckParams], accesses self._hass instead, removes manual trace_condition_function call |
homeassistant/components/device_automation/condition.py |
Updates to bridge old platform API (returns ConditionCheckerType) with new interface, implements wrapper to handle backward compatibility |
tests/helpers/test_condition.py |
Updates test mocks to use new ConditionChecker type and **kwargs parameter pattern |
536f1bb to
3af6a70
Compare
MartinHjelmare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
|
Do we need to update any dev docs? |
|
Dev docs for conditions are not merged yet: home-assistant/developers.home-assistant#2885 I'll make a comment there about the required changes. |
Proposed change
Modernise condition checker in condition helper.
This PR cleans up and improves the new condition interface. In this it is a little similar to #152772, that adjusted the triggers.
The new condition interface is documented as experimental and not yet used by custom components, so we can still make these changes without problems.
It does the following improvements:
ConditionCheckerType->ConditionCheckertrace_condition_functionConditionCheckerhassargumentbool, as integrations should never returnNonefrom the checkType 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: