diff --git a/homeassistant/components/nest/climate_sdm.py b/homeassistant/components/nest/climate_sdm.py index 6413b2e0dfe..b0c64329ffd 100644 --- a/homeassistant/components/nest/climate_sdm.py +++ b/homeassistant/components/nest/climate_sdm.py @@ -75,6 +75,8 @@ FAN_MODE_MAP = { } FAN_INV_MODE_MAP = {v: k for k, v in FAN_MODE_MAP.items()} +MAX_FAN_DURATION = 43200 # 15 hours is the max in the SDM API + async def async_setup_sdm_entry( hass: HomeAssistantType, entry: ConfigEntry, async_add_entities @@ -322,4 +324,7 @@ class ThermostatEntity(ClimateEntity): if fan_mode not in self.fan_modes: raise ValueError(f"Unsupported fan_mode '{fan_mode}'") trait = self._device.traits[FanTrait.NAME] - await trait.set_timer(FAN_INV_MODE_MAP[fan_mode]) + duration = None + if fan_mode != FAN_OFF: + duration = MAX_FAN_DURATION + await trait.set_timer(FAN_INV_MODE_MAP[fan_mode], duration=duration) diff --git a/tests/components/nest/climate_sdm_test.py b/tests/components/nest/climate_sdm_test.py index ef332d0e848..888227b9cde 100644 --- a/tests/components/nest/climate_sdm_test.py +++ b/tests/components/nest/climate_sdm_test.py @@ -819,6 +819,20 @@ async def test_thermostat_set_fan(hass, auth): "params": {"timerMode": "OFF"}, } + # Turn on fan mode + await common.async_set_fan_mode(hass, FAN_ON) + await hass.async_block_till_done() + + assert auth.method == "post" + assert auth.url == "some-device-id:executeCommand" + assert auth.json == { + "command": "sdm.devices.commands.Fan.SetTimer", + "params": { + "duration": "43200s", + "timerMode": "ON", + }, + } + async def test_thermostat_fan_empty(hass): """Test a fan trait with an empty response.""" @@ -938,7 +952,7 @@ async def test_thermostat_set_hvac_fan_only(hass, auth): assert url == "some-device-id:executeCommand" assert json == { "command": "sdm.devices.commands.Fan.SetTimer", - "params": {"timerMode": "ON"}, + "params": {"duration": "43200s", "timerMode": "ON"}, } (method, url, json, headers) = auth.captured_requests.pop(0) assert method == "post"