Skip to content

Commit 4b9c1e8

Browse files
committed
test: cover STATE_UNKNOWN branches, multi-param calls, and the API seam
Adds the untested branches and failure modes flagged in review: as_list() and _optional_float() receiving STATE_UNKNOWN directly, two optional parameters passed to async_set_low_voltage_state() in one call, and a test that exercises async_set_low_voltage_state() down through the real set_attributes() with only the API mocked -- the join between the two, which was previously untested even though each half was covered in isolation.
1 parent bb85312 commit 4b9c1e8

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/test_climate.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def test_comma_separated_string_is_split(self):
5454
def test_empty_list_stays_empty(self):
5555
assert as_list([]) == []
5656

57+
def test_unknown_state_is_empty(self):
58+
assert as_list(STATE_UNKNOWN) == []
59+
5760

5861
class TestLowVoltageDetection:
5962
def test_baseboard_is_not_low_voltage(self):
@@ -96,6 +99,10 @@ def test_missing_values_are_none(self):
9699
assert device.min_cool_setpoint is None
97100
assert device.current_humidity is None
98101

102+
def test_unknown_state_numeric_value_is_none(self):
103+
device = _climate(Thermostat24VMode="HEAT", CoolTemperatureSet=STATE_UNKNOWN)
104+
assert device.cool_setpoint is None
105+
99106
def test_humidity_is_an_int(self):
100107
device = _climate(Thermostat24VMode="COOL", Humidity=57)
101108
assert device.current_humidity == 57
@@ -194,3 +201,38 @@ async def test_unreported_mode_without_explicit_mode_raises(self):
194201
with pytest.raises(ValueError):
195202
await device.async_set_low_voltage_state(cool_setpoint=22)
196203
device.set_attributes.assert_not_awaited()
204+
205+
async def test_two_optional_values_in_one_call(self):
206+
device = self._device()
207+
await device.async_set_low_voltage_state(mode="HEAT", cool_setpoint=18)
208+
device.set_attributes.assert_awaited_once_with(
209+
{
210+
"Thermostat24VMode": "HEAT",
211+
"TargetTemperature": 19.0,
212+
"CoolTemperatureSet": 18,
213+
}
214+
)
215+
216+
217+
class TestSetLowVoltageStateReachesTheApi:
218+
"""async_set_low_voltage_state() and set_attributes() are each tested in
219+
isolation elsewhere; this covers the join between them, with only the
220+
API mocked, so a regression in either seam shows up here."""
221+
222+
async def test_payload_reaches_the_api_hilo_cased(self):
223+
device = _climate(
224+
Thermostat24VMode="COOL",
225+
TargetTemperature=19,
226+
CoolTemperatureSet=24,
227+
)
228+
device._api._set_device_attributes = AsyncMock()
229+
await device.async_set_low_voltage_state(cool_setpoint=22, fan_mode="AUTO")
230+
device._api._set_device_attributes.assert_awaited_once_with(
231+
device,
232+
{
233+
"Thermostat24VMode": "COOL",
234+
"TargetTemperature": 19.0,
235+
"CoolTemperatureSet": 22,
236+
"FanMode": "AUTO",
237+
},
238+
)

0 commit comments

Comments
 (0)