Respect ESPHome ClimateTrait supports_current_temperature (#132149)

This commit is contained in:
Omni Flux 2024-12-23 05:35:59 -05:00 committed by GitHub
parent 939365887f
commit cf3d4eb26a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 0 deletions

View File

@ -230,6 +230,8 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
@esphome_float_state_property @esphome_float_state_property
def current_temperature(self) -> float | None: def current_temperature(self) -> float | None:
"""Return the current temperature.""" """Return the current temperature."""
if not self._static_info.supports_current_temperature:
return None
return self._state.current_temperature return self._state.current_temperature
@property @property

View File

@ -484,3 +484,36 @@ async def test_climate_entity_attributes(
assert state is not None assert state is not None
assert state.state == HVACMode.COOL assert state.state == HVACMode.COOL
assert state.attributes == snapshot(name="climate-entity-attributes") 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