From 3ddef561672eacb069f053f8ff8f86281a32c0f3 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Wed, 23 Oct 2024 08:13:42 +0200 Subject: [PATCH] Fix step in presets for generic thermostat (#128922) --- .../generic_thermostat/config_flow.py | 2 +- .../snapshots/test_config_flow.ambr | 19 ++++++++ .../generic_thermostat/test_config_flow.py | 48 +++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/generic_thermostat/config_flow.py b/homeassistant/components/generic_thermostat/config_flow.py index e9079a9f41a..5b0eae8ff66 100644 --- a/homeassistant/components/generic_thermostat/config_flow.py +++ b/homeassistant/components/generic_thermostat/config_flow.py @@ -62,7 +62,7 @@ OPTIONS_SCHEMA = { PRESETS_SCHEMA = { vol.Optional(v): selector.NumberSelector( selector.NumberSelectorConfig( - mode=selector.NumberSelectorMode.BOX, unit_of_measurement=DEGREE + mode=selector.NumberSelectorMode.BOX, unit_of_measurement=DEGREE, step=0.1 ) ) for v in CONF_PRESETS.values() diff --git a/tests/components/generic_thermostat/snapshots/test_config_flow.ambr b/tests/components/generic_thermostat/snapshots/test_config_flow.ambr index d515d52a81b..ed757d1c2ae 100644 --- a/tests/components/generic_thermostat/snapshots/test_config_flow.ambr +++ b/tests/components/generic_thermostat/snapshots/test_config_flow.ambr @@ -18,6 +18,25 @@ 'type': , }) # --- +# name: test_config_flow_preset_accepts_float[create_entry] + FlowResultSnapshot({ + 'result': ConfigEntrySnapshot({ + 'title': 'My thermostat', + }), + 'title': 'My thermostat', + 'type': , + }) +# --- +# name: test_config_flow_preset_accepts_float[init] + FlowResultSnapshot({ + 'type': , + }) +# --- +# name: test_config_flow_preset_accepts_float[presets] + FlowResultSnapshot({ + 'type': , + }) +# --- # name: test_options[create_entry] FlowResultSnapshot({ 'result': True, diff --git a/tests/components/generic_thermostat/test_config_flow.py b/tests/components/generic_thermostat/test_config_flow.py index 7a7fdabc6e6..561870ad3d4 100644 --- a/tests/components/generic_thermostat/test_config_flow.py +++ b/tests/components/generic_thermostat/test_config_flow.py @@ -132,3 +132,51 @@ async def test_options(hass: HomeAssistant, snapshot: SnapshotAssertion) -> None # Check config entry is reloaded with new options await hass.async_block_till_done() assert hass.states.get("climate.my_thermostat") == snapshot(name="without_away") + + +async def test_config_flow_preset_accepts_float( + hass: HomeAssistant, snapshot: SnapshotAssertion +) -> None: + """Test the config flow with preset is a float.""" + with patch( + "homeassistant.components.generic_thermostat.async_setup_entry", + return_value=True, + ) as mock_setup_entry: + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_USER} + ) + assert result == snapshot(name="init", include=SNAPSHOT_FLOW_PROPS) + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_NAME: "My thermostat", + CONF_HEATER: "switch.run", + CONF_SENSOR: "sensor.temperature", + CONF_AC_MODE: False, + CONF_COLD_TOLERANCE: 0.3, + CONF_HOT_TOLERANCE: 0.3, + }, + ) + assert result == snapshot(name="presets", include=SNAPSHOT_FLOW_PROPS) + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input={ + CONF_PRESETS[PRESET_AWAY]: 10.4, + }, + ) + assert result == snapshot(name="create_entry", include=SNAPSHOT_FLOW_PROPS) + + await hass.async_block_till_done() + + assert len(mock_setup_entry.mock_calls) == 1 + assert result["options"] == { + "ac_mode": False, + "away_temp": 10.4, + "cold_tolerance": 0.3, + "heater": "switch.run", + "hot_tolerance": 0.3, + "name": "My thermostat", + "target_sensor": "sensor.temperature", + }