Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions homeassistant/components/google_assistant/trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,17 @@ class TemperatureSettingTrait(_Trait):
preset_to_google = {climate.PRESET_ECO: "eco"}
google_to_preset = {value: key for key, value in preset_to_google.items()}

action_to_google = {
climate.HVACAction.OFF: "off",
climate.HVACAction.HEATING: "heat",
Comment thread
lucsansag marked this conversation as resolved.
climate.HVACAction.DEFROSTING: "heat",
climate.HVACAction.PREHEATING: "heat",
climate.HVACAction.COOLING: "cool",
climate.HVACAction.DRYING: "dry",
climate.HVACAction.FAN: "fan-only",
climate.HVACAction.IDLE: "none",
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Map all Home Assistant HVACAction values to avoid dropping activeThermostatMode for valid actions like DEFROSTING and PREHEATING (currently unmapped, so the key is omitted when those actions occur).

Suggested change
climate.HVACAction.IDLE: "none",
climate.HVACAction.IDLE: "none",
climate.HVACAction.PREHEATING: "heat",
climate.HVACAction.DEFROSTING: "heat",

Copilot uses AI. Check for mistakes.
}

@staticmethod
def supported(domain, features, device_class, _):
"""Test if state is supported."""
Expand Down Expand Up @@ -1282,6 +1293,11 @@ def query_attributes(self) -> dict[str, Any]:
else:
response["thermostatMode"] = self.hvac_to_google.get(operation, "none")

if (
action := self.action_to_google.get(attrs.get(climate.ATTR_HVAC_ACTION))
) is not None:
response["activeThermostatMode"] = action

current_temp = attrs.get(climate.ATTR_CURRENT_TEMPERATURE)
if current_temp is not None:
response["thermostatTemperatureAmbient"] = round(
Expand Down
4 changes: 4 additions & 0 deletions tests/components/google_assistant/test_google_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ async def test_query_climate_request(
devices = body["payload"]["devices"]
assert len(devices) == 3
assert devices["climate.heatpump"] == {
"activeThermostatMode": "heat",
"online": True,
"on": True,
"thermostatTemperatureSetpoint": 20.0,
Expand All @@ -247,6 +248,7 @@ async def test_query_climate_request(
"currentFanSpeedSetting": "auto_low",
}
assert devices["climate.hvac"] == {
"activeThermostatMode": "cool",
"online": True,
"on": True,
"thermostatTemperatureSetpoint": 21,
Expand Down Expand Up @@ -295,6 +297,7 @@ async def test_query_climate_request_f(
devices = body["payload"]["devices"]
assert len(devices) == 3
assert devices["climate.heatpump"] == {
"activeThermostatMode": "heat",
"online": True,
"on": True,
"thermostatTemperatureSetpoint": -6.7,
Expand All @@ -311,6 +314,7 @@ async def test_query_climate_request_f(
"currentFanSpeedSetting": "auto_low",
}
assert devices["climate.hvac"] == {
"activeThermostatMode": "cool",
"online": True,
"on": True,
"thermostatTemperatureSetpoint": -6.1,
Expand Down
38 changes: 38 additions & 0 deletions tests/components/google_assistant/test_trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,44 @@ async def test_temperature_setting_climate_setpoint_auto(hass: HomeAssistant) ->
assert calls[0].data == {ATTR_ENTITY_ID: "climate.bla", ATTR_TEMPERATURE: 19}


async def test_temperature_setting_action_change(hass: HomeAssistant) -> None:
"""Test that activeThermostatMode contains the current HVAC action."""
trt_idle = trait.TemperatureSettingTrait(
hass,
State(
Comment on lines +1628 to +1632
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand the test coverage to assert activeThermostatMode for the other mapped actions (e.g., HEATING, DRYING, FAN, OFF) and any additional actions you add support for (like DEFROSTING/PREHEATING), so regressions in the mapping are caught.

Copilot uses AI. Check for mistakes.
"climate.bla",
climate.HVACMode.COOL,
{
climate.ATTR_HVAC_MODES: [climate.HVACMode.OFF, climate.HVACMode.COOL],
climate.ATTR_HVAC_ACTION: climate.HVACAction.IDLE,
climate.ATTR_CURRENT_TEMPERATURE: 18,
climate.ATTR_MIN_TEMP: 10,
climate.ATTR_MAX_TEMP: 30,
ATTR_TEMPERATURE: 18,
},
),
BASIC_CONFIG,
)
assert trt_idle.query_attributes().get("activeThermostatMode") == "none"
trt_cool = trait.TemperatureSettingTrait(
hass,
State(
"climate.bla",
climate.HVACMode.COOL,
{
climate.ATTR_HVAC_MODES: [climate.HVACMode.OFF, climate.HVACMode.COOL],
climate.ATTR_HVAC_ACTION: climate.HVACAction.COOLING,
climate.ATTR_CURRENT_TEMPERATURE: 23,
climate.ATTR_MIN_TEMP: 10,
climate.ATTR_MAX_TEMP: 30,
ATTR_TEMPERATURE: 18,
},
),
BASIC_CONFIG,
)
assert trt_cool.query_attributes().get("activeThermostatMode") == "cool"


async def test_temperature_control(hass: HomeAssistant) -> None:
"""Test TemperatureControl trait support for sensor domain."""
trt = trait.TemperatureControlTrait(
Expand Down
Loading