From 73dcc2f5a837384af684dc54ee20d0f182fffe21 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 28 Apr 2026 10:30:11 +0200 Subject: [PATCH] Add missing call to ConditionChecker.async_setup in async_from_config (#169055) --- homeassistant/helpers/condition.py | 1 + tests/helpers/test_condition.py | 39 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/homeassistant/helpers/condition.py b/homeassistant/helpers/condition.py index e431875f229e..d8d62709f207 100644 --- a/homeassistant/helpers/condition.py +++ b/homeassistant/helpers/condition.py @@ -1111,6 +1111,7 @@ async def async_from_config( else: checker = factory(config) if isinstance(checker, ConditionChecker): + await checker.async_setup() return checker return LegacyConditionChecker(hass, cast(ConditionCheckerType, checker)) diff --git a/tests/helpers/test_condition.py b/tests/helpers/test_condition.py index dd05bbe51db5..593b22328f28 100644 --- a/tests/helpers/test_condition.py +++ b/tests/helpers/test_condition.py @@ -5068,3 +5068,42 @@ async def test_state_condition_attr_duration_unrelated_attr_update( # reset the timer. freezer.tick(timedelta(seconds=5)) assert test(hass) is True + + +async def test_async_from_config_calls_async_setup_on_checker( + hass: HomeAssistant, +) -> None: + """Test that async_from_config calls async_setup on ConditionChecker from factory path.""" + + class StubChecker(condition.ConditionChecker): + """Stub checker to track async_setup calls.""" + + def __init__(self, hass: HomeAssistant) -> None: + super().__init__(hass) + self.setup_called = False + + async def async_setup(self) -> None: + self.setup_called = True + + def _async_check(self, **kwargs: Any) -> bool: + return True + + stub = StubChecker(hass) + + async def fake_factory( + hass: HomeAssistant, config: ConfigType + ) -> condition.ConditionChecker: + return stub + + with ( + patch.object( + condition, "async_stub_checker_from_config", fake_factory, create=True + ), + patch.dict(condition._PLATFORM_ALIASES, {"stub_checker": None}), + ): + config = {"condition": "stub_checker"} + config = cv.CONDITION_SCHEMA(config) + result = await condition.async_from_config(hass, config) + + assert result is stub + assert stub.setup_called