diff --git a/homeassistant/components/water_heater/condition.py b/homeassistant/components/water_heater/condition.py index da9b8a383d96..6f2bb2d972e2 100644 --- a/homeassistant/components/water_heater/condition.py +++ b/homeassistant/components/water_heater/condition.py @@ -76,6 +76,13 @@ class WaterHeaterTargetTemperatureCondition(EntityNumericalConditionWithUnitBase _domain_specs = {DOMAIN: DomainSpec(value_source=ATTR_TEMPERATURE)} _unit_converter = TemperatureConverter + def _should_include(self, state: State) -> bool: + """Skip water heater entities that do not expose a target temperature.""" + return ( + super()._should_include(state) + and state.attributes.get(ATTR_TEMPERATURE) is not None + ) + def _get_entity_unit(self, entity_state: State) -> str | None: """Get the temperature unit of a water heater entity from its state.""" # Water heater entities convert temperatures to the system unit via show_temp diff --git a/homeassistant/components/water_heater/trigger.py b/homeassistant/components/water_heater/trigger.py index 0a434b498b5d..72b5efb741b5 100644 --- a/homeassistant/components/water_heater/trigger.py +++ b/homeassistant/components/water_heater/trigger.py @@ -60,6 +60,13 @@ class _WaterHeaterTargetTemperatureTriggerMixin( _domain_specs = {DOMAIN: DomainSpec(value_source=ATTR_TEMPERATURE)} _unit_converter = TemperatureConverter + def _should_include(self, state: State) -> bool: + """Skip water heater entities that do not expose a target temperature.""" + return ( + super()._should_include(state) + and state.attributes.get(ATTR_TEMPERATURE) is not None + ) + def _get_entity_unit(self, state: State) -> str | None: """Get the temperature unit of a water heater entity from its state.""" # Water heater entities convert temperatures to the system unit via show_temp diff --git a/tests/components/water_heater/test_condition.py b/tests/components/water_heater/test_condition.py index 10736d1bd464..79bce1e431d4 100644 --- a/tests/components/water_heater/test_condition.py +++ b/tests/components/water_heater/test_condition.py @@ -228,6 +228,7 @@ async def test_water_heater_state_condition_behavior_all( "eco", ATTR_TEMPERATURE, threshold_unit=UnitOfTemperature.CELSIUS, + attribute_required=True, ), ], ) @@ -267,6 +268,7 @@ async def test_water_heater_numerical_condition_behavior_any( "eco", ATTR_TEMPERATURE, threshold_unit=UnitOfTemperature.CELSIUS, + attribute_required=True, ), ], ) diff --git a/tests/components/water_heater/test_trigger.py b/tests/components/water_heater/test_trigger.py index 9bf4356658e2..f0a28bbeed94 100644 --- a/tests/components/water_heater/test_trigger.py +++ b/tests/components/water_heater/test_trigger.py @@ -164,12 +164,14 @@ async def test_water_heater_state_trigger_behavior_any( STATE_ECO, ATTR_TEMPERATURE, threshold_unit=UnitOfTemperature.CELSIUS, + attribute_required=True, ), *parametrize_numerical_attribute_crossed_threshold_trigger_states( "water_heater.target_temperature_crossed_threshold", STATE_ECO, ATTR_TEMPERATURE, threshold_unit=UnitOfTemperature.CELSIUS, + attribute_required=True, ), ], ) @@ -270,6 +272,7 @@ async def test_water_heater_state_trigger_behavior_first( STATE_ECO, ATTR_TEMPERATURE, threshold_unit=UnitOfTemperature.CELSIUS, + attribute_required=True, ), ], ) @@ -370,6 +373,7 @@ async def test_water_heater_state_trigger_behavior_last( STATE_ECO, ATTR_TEMPERATURE, threshold_unit=UnitOfTemperature.CELSIUS, + attribute_required=True, ), ], )