From cf3d4eb26af9429216e972d37d829845fca6a6ee Mon Sep 17 00:00:00 2001 From: Omni Flux Date: Mon, 23 Dec 2024 05:35:59 -0500 Subject: [PATCH] Respect ESPHome ClimateTrait supports_current_temperature (#132149) --- homeassistant/components/esphome/climate.py | 2 ++ tests/components/esphome/test_climate.py | 33 +++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/homeassistant/components/esphome/climate.py b/homeassistant/components/esphome/climate.py index 8089fc4712a18..478ce9bae2c4a 100644 --- a/homeassistant/components/esphome/climate.py +++ b/homeassistant/components/esphome/climate.py @@ -230,6 +230,8 @@ def swing_mode(self) -> str | None: @esphome_float_state_property def current_temperature(self) -> float | None: """Return the current temperature.""" + if not self._static_info.supports_current_temperature: + return None return self._state.current_temperature @property diff --git a/tests/components/esphome/test_climate.py b/tests/components/esphome/test_climate.py index 189b86fc5fddd..2a5013444dd7e 100644 --- a/tests/components/esphome/test_climate.py +++ b/tests/components/esphome/test_climate.py @@ -484,3 +484,36 @@ async def test_climate_entity_attributes( assert state is not None assert state.state == HVACMode.COOL assert state.attributes == snapshot(name="climate-entity-attributes") + + +async def test_climate_entity_attribute_current_temperature_unsupported( + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry, +) -> None: + """Test a climate entity with current temperature unsupported.""" + entity_info = [ + ClimateInfo( + object_id="myclimate", + key=1, + name="my climate", + unique_id="my_climate", + supports_current_temperature=False, + ) + ] + states = [ + ClimateState( + key=1, + current_temperature=30, + ) + ] + user_service = [] + await mock_generic_device_entry( + mock_client=mock_client, + entity_info=entity_info, + user_service=user_service, + states=states, + ) + state = hass.states.get("climate.test_myclimate") + assert state is not None + assert state.attributes[ATTR_CURRENT_TEMPERATURE] is None