Skip to content

Commit 10646ef

Browse files
authored
Merge pull request #347 from plugwise/fix-#425
Enhancement based on #425
2 parents 8c63dee + 7df1480 commit 10646ef

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Repair coverage/fix testing - #294
66
- Correct non-unique device names in adam_jip userdata
77
- Add domestic_hot_water_setpoint data to anna_heatpump_heating userdata, update relevant test-cases
8+
- Add raising an error when providing the wrong type of temperature input to set_temperature() with cooling active
89

910
## V0.31.6: Fix domestic_hot_water_setpoint-related bug for Anna + Elga
1011

plugwise/__init__.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ async def connect(self) -> bool:
354354
dsmrmain = result.find("./module/protocols/dsmrmain")
355355
if "Plugwise" not in names and dsmrmain is None: # pragma: no cover
356356
LOGGER.error(
357-
"Connected but expected text not returned, we got %s. Please create \
358-
an issue on http://github.com/plugwise/python-plugwise",
357+
"Connected but expected text not returned, we got %s. Please create"
358+
" an issue on http://github.com/plugwise/python-plugwise",
359359
result,
360360
)
361361
raise ResponseError
@@ -416,8 +416,8 @@ async def _smile_detect_legacy(
416416
else: # pragma: no cover
417417
# No cornercase, just end of the line
418418
LOGGER.error(
419-
"Connected but no gateway device information found, please create \
420-
an issue on http://github.com/plugwise/python-plugwise"
419+
"Connected but no gateway device information found, please create"
420+
" an issue on http://github.com/plugwise/python-plugwise"
421421
)
422422
raise ResponseError
423423

@@ -442,8 +442,8 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
442442
if model == "Unknown" or self.smile_fw_version is None: # pragma: no cover
443443
# Corner case check
444444
LOGGER.error(
445-
"Unable to find model or version information, please create \
446-
an issue on http://github.com/plugwise/python-plugwise"
445+
"Unable to find model or version information, please create"
446+
" an issue on http://github.com/plugwise/python-plugwise"
447447
)
448448
raise UnsupportedDeviceError
449449

@@ -452,8 +452,8 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
452452
LOGGER.debug("Plugwise identified as %s", target_smile)
453453
if target_smile not in SMILES:
454454
LOGGER.error(
455-
'Your version Smile identified as "%s" seems unsupported by our plugin, please \
456-
create an issue on http://github.com/plugwise/python-plugwise',
455+
"Your version Smile identified as %s seems unsupported by our plugin, please"
456+
" create an issue on http://github.com/plugwise/python-plugwise",
457457
target_smile,
458458
)
459459
raise UnsupportedDeviceError
@@ -682,20 +682,23 @@ async def set_temperature(self, loc_id: str, items: dict[str, float]) -> None:
682682
setpoint = items["setpoint"]
683683

684684
if self._cooling_present:
685-
if "setpoint_high" in items:
686-
tmp_setpoint_high = items["setpoint_high"]
687-
tmp_setpoint_low = items["setpoint_low"]
685+
if "setpoint_high" not in items:
686+
raise PlugwiseError(
687+
"Plugwise: failed setting temperature: no valid input provided"
688+
)
689+
tmp_setpoint_high = items["setpoint_high"]
690+
tmp_setpoint_low = items["setpoint_low"]
688691
if self._cooling_enabled: # in cooling mode
689692
setpoint = tmp_setpoint_high
690693
if tmp_setpoint_low != MIN_SETPOINT:
691694
raise PlugwiseError(
692-
"Plugwise: heating setpoint cannot be changed when in cooling mode!"
695+
"Plugwise: heating setpoint cannot be changed when in cooling mode"
693696
)
694697
else: # in heating mode
695698
setpoint = tmp_setpoint_low
696699
if tmp_setpoint_high != MAX_SETPOINT:
697700
raise PlugwiseError(
698-
"Plugwise: cooling setpoint cannot be changed when in heating mode!"
701+
"Plugwise: cooling setpoint cannot be changed when in heating mode"
699702
)
700703

701704
if setpoint is None:

tests/test_smile.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,13 @@ async def tinker_switch(
486486
return tinker_switch_passed
487487

488488
@pytest.mark.asyncio
489-
async def tinker_thermostat_temp(self, smile, loc_id, unhappy=False):
489+
async def tinker_thermostat_temp(
490+
self, smile, loc_id, block_cooling=False, unhappy=False
491+
):
490492
"""Toggle temperature to test functionality."""
491493
_LOGGER.info("Asserting modifying settings in location (%s):", loc_id)
492494
test_temp = {"setpoint": 22.9}
493-
if smile._cooling_present:
495+
if smile._cooling_present and not block_cooling:
494496
test_temp = {"setpoint_low": 19.5, "setpoint_high": 23.5}
495497
_LOGGER.info("- Adjusting temperature to %s", test_temp)
496498
try:
@@ -584,13 +586,16 @@ async def tinker_thermostat(
584586
schedule_on=True,
585587
good_schedules=None,
586588
single=False,
589+
block_cooling=False,
587590
unhappy=False,
588591
):
589592
"""Toggle various climate settings to test functionality."""
590593
if good_schedules is None: # pragma: no cover
591594
good_schedules = ["Weekschema"]
592595

593-
result_1 = await self.tinker_thermostat_temp(smile, loc_id, unhappy)
596+
result_1 = await self.tinker_thermostat_temp(
597+
smile, loc_id, block_cooling, unhappy
598+
)
594599
result_2 = await self.tinker_thermostat_preset(smile, loc_id, unhappy)
595600
if smile._schedule_old_states != {}:
596601
for item in smile._schedule_old_states[loc_id]:
@@ -3928,14 +3933,15 @@ async def test_connect_anna_heatpump_cooling(self):
39283933
assert smile._cooling_enabled
39293934
assert smile._cooling_active
39303935

3931-
with pytest.raises(pw_exceptions.PlugwiseError):
3936+
with pytest.raises(pw_exceptions.PlugwiseError) as exc:
39323937
await self.tinker_thermostat(
39333938
smile,
39343939
"c784ee9fdab44e1395b8dee7d7a497d5",
39353940
good_schedules=[
39363941
"standaard",
39373942
],
39383943
)
3944+
_LOGGER.debug("ERROR raised: %s", exc.value)
39393945

39403946
await smile.close_connection()
39413947
await self.disconnect(server, client)
@@ -4376,14 +4382,23 @@ async def test_connect_anna_loria_heating_idle(self):
43764382
)
43774383
assert switch_change
43784384

4379-
with pytest.raises(pw_exceptions.PlugwiseError):
4385+
with pytest.raises(pw_exceptions.PlugwiseError) as exc:
43804386
await self.tinker_thermostat(
43814387
smile,
43824388
"15da035090b847e7a21f93e08c015ebc",
43834389
good_schedules=[
43844390
"Winter",
43854391
],
43864392
)
4393+
_LOGGER.debug("ERROR raised: %s", exc.value)
4394+
4395+
with pytest.raises(pw_exceptions.PlugwiseError) as exc:
4396+
await self.tinker_thermostat_temp(
4397+
smile,
4398+
"15da035090b847e7a21f93e08c015ebc",
4399+
block_cooling=True,
4400+
)
4401+
_LOGGER.debug("ERROR raised: %s", exc.value)
43874402

43884403
await self.tinker_dhw_mode(smile)
43894404

0 commit comments

Comments
 (0)