Skip to content

Commit

Permalink
Respect ESPHome ClimateTrait supports_current_temperature (home-assis…
Browse files Browse the repository at this point in the history
  • Loading branch information
Omniflux authored Dec 23, 2024
1 parent 9393658 commit cf3d4eb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions homeassistant/components/esphome/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions tests/components/esphome/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cf3d4eb

Please sign in to comment.