Skip to content

Commit ccfa4fe

Browse files
committed
Let tinker-functions return result
1 parent c275e46 commit ccfa4fe

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

tests/test_smile.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -458,48 +458,53 @@ async def tinker_switch(
458458
"""Turn a Switch on and off to test functionality."""
459459
_LOGGER.info("Asserting modifying settings for switch devices:")
460460
_LOGGER.info("- Devices (%s):", dev_id)
461-
switch_change = False
461+
tinker_switch_passed = False
462462
for new_state in [False, True, False]:
463463
_LOGGER.info("- Switching %s", new_state)
464464
try:
465465
await smile.set_switch_state(dev_id, members, model, new_state)
466-
switch_change = True
466+
tinker_switch_passed = True
467467
except pw_exceptions.PlugwiseError:
468468
_LOGGER.info(" + locked, not switched as expected")
469469
except (
470470
pw_exceptions.ErrorSendingCommandError,
471471
pw_exceptions.ResponseError,
472472
):
473-
switch_change = False
473+
tinker_switch_passed = False
474474
if unhappy:
475475
_LOGGER.info(" + failed as expected")
476476
else: # pragma: no cover
477477
_LOGGER.info(" - failed unexpectedly")
478478
raise self.UnexpectedError
479-
return switch_change
479+
return tinker_switch_passed
480480

481481
@pytest.mark.asyncio
482482
async def tinker_thermostat_temp(self, smile, loc_id, unhappy=False):
483483
"""Toggle temperature to test functionality."""
484484
_LOGGER.info("Asserting modifying settings in location (%s):", loc_id)
485+
tinker_temp_passed = False
485486
for new_temp in [20.0, 22.9]:
486487
_LOGGER.info("- Adjusting temperature to %s", new_temp)
487488
try:
488489
await smile.set_temperature(loc_id, new_temp)
490+
tinker_temp_passed = True
489491
_LOGGER.info(" + worked as intended")
490492
except (
491493
pw_exceptions.ErrorSendingCommandError,
492494
pw_exceptions.ResponseError,
493495
):
496+
tinker_temp_passed = False
494497
if unhappy:
495498
_LOGGER.info(" + failed as expected")
496499
else: # pragma: no cover
497500
_LOGGER.info(" - failed unexpectedly")
498501
raise self.UnexpectedError
502+
return tinker_temp_passed
499503

500504
@pytest.mark.asyncio
501505
async def tinker_thermostat_preset(self, smile, loc_id, unhappy=False):
502506
"""Toggle preset to test functionality."""
507+
tinker_preset_passed = False
503508
for new_preset in ["asleep", "home", "!bogus"]:
504509
warning = ""
505510
if new_preset[0] == "!":
@@ -508,24 +513,27 @@ async def tinker_thermostat_preset(self, smile, loc_id, unhappy=False):
508513
_LOGGER.info("%s", f"- Adjusting preset to {new_preset}{warning}")
509514
try:
510515
await smile.set_preset(loc_id, new_preset)
516+
tinker_preset_passed = True
511517
_LOGGER.info(" + worked as intended")
512518
except pw_exceptions.PlugwiseError:
513519
_LOGGER.info(" + found invalid preset, as expected")
514520
except (
515521
pw_exceptions.ErrorSendingCommandError,
516522
pw_exceptions.ResponseError,
517523
):
524+
tinker_preset_passed = False
518525
if unhappy:
519526
_LOGGER.info(" + failed as expected")
520527
else: # pragma: no cover
521528
_LOGGER.info(" - failed unexpectedly")
522529
raise self.UnexpectedError
530+
return tinker_preset_passed
523531

524532
@pytest.mark.asyncio
525533
async def tinker_thermostat_schedule(
526534
self, smile, loc_id, state, good_schedules=None, unhappy=False
527535
):
528-
_LOGGER.debug("HOI %s", good_schedules)
536+
tinker_schedule_passed = False
529537
if good_schedules != []:
530538
if good_schedules != [None]:
531539
good_schedules.append(
@@ -539,18 +547,21 @@ async def tinker_thermostat_schedule(
539547
_LOGGER.info("- Adjusting schedule to %s", f"{new_schedule}{warning}")
540548
try:
541549
await smile.set_schedule_state(loc_id, new_schedule, state)
550+
tinker_schedule_passed = True
542551
_LOGGER.info(" + found invalid schedule, as intended")
543552
except pw_exceptions.PlugwiseError:
544553
_LOGGER.info(" + failed as expected")
545554
except (
546555
pw_exceptions.ErrorSendingCommandError,
547556
pw_exceptions.ResponseError,
548557
):
558+
tinker_schedule_passed = False
549559
if unhappy:
550560
_LOGGER.info(" + failed as expected before intended failure")
551561
else: # pragma: no cover
552562
_LOGGER.info(" - succeeded unexpectedly for some reason")
553563
raise self.UnexpectedError
564+
return tinker_schedule_passed
554565
else: # pragma: no cover
555566
_LOGGER.info("- Skipping schedule adjustments")
556567

@@ -562,18 +573,20 @@ async def tinker_thermostat(
562573
if good_schedules is None: # pragma: no cover
563574
good_schedules = ["Weekschema"]
564575

565-
await self.tinker_thermostat_temp(smile, loc_id, unhappy)
566-
await self.tinker_thermostat_preset(smile, loc_id, unhappy)
567-
await self.tinker_thermostat_schedule(
576+
result_1 = await self.tinker_thermostat_temp(smile, loc_id, unhappy)
577+
result_2 = await self.tinker_thermostat_preset(smile, loc_id, unhappy)
578+
result_3 = await self.tinker_thermostat_schedule(
568579
smile, loc_id, "on", good_schedules, unhappy
569580
)
570581
if schedule_on:
571-
await self.tinker_thermostat_schedule(
582+
result_4 = await self.tinker_thermostat_schedule(
572583
smile, loc_id, "off", good_schedules, unhappy
573584
)
574-
await self.tinker_thermostat_schedule(
585+
result_5 = await self.tinker_thermostat_schedule(
575586
smile, loc_id, "on", good_schedules, unhappy
576587
)
588+
return result_1 and result_2 and result_3 and result_4 and result_5
589+
return result_1 and result_2 and result_3
577590

578591
@staticmethod
579592
async def tinker_regulation_mode(smile):

0 commit comments

Comments
 (0)