Parameterize SmartTub tests (#47189)

* Parameterize SmartTub tests

* parameterize light service calls

* remove stray print()

* add comment
This commit is contained in:
Matt Zimmerman 2021-03-01 04:53:57 -08:00 committed by GitHub
parent a2b13785c2
commit 947f6ea51e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 86 deletions

View file

@ -1,38 +1,45 @@
"""Test the SmartTub light platform."""
import pytest
from smarttub import SpaLight
async def test_light(spa, setup_entry, hass):
# the light in light_zone should have initial state light_state. we will call
# service_name with service_params, and expect the resultant call to
# SpaLight.set_mode to have set_mode_args parameters
@pytest.mark.parametrize(
"light_zone,light_state,service_name,service_params,set_mode_args",
[
(1, "off", "turn_on", {}, (SpaLight.LightMode.PURPLE, 50)),
(1, "off", "turn_on", {"brightness": 255}, (SpaLight.LightMode.PURPLE, 100)),
(2, "on", "turn_off", {}, (SpaLight.LightMode.OFF, 0)),
],
)
async def test_light(
spa,
setup_entry,
hass,
light_zone,
light_state,
service_name,
service_params,
set_mode_args,
):
"""Test light entity."""
for light in spa.get_lights.return_value:
entity_id = f"light.{spa.brand}_{spa.model}_light_{light.zone}"
state = hass.states.get(entity_id)
assert state is not None
if light.mode == SpaLight.LightMode.OFF:
assert state.state == "off"
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": entity_id},
blocking=True,
)
light.set_mode.assert_called()
entity_id = f"light.{spa.brand}_{spa.model}_light_{light_zone}"
state = hass.states.get(entity_id)
assert state is not None
assert state.state == light_state
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": entity_id, "brightness": 255},
blocking=True,
)
light.set_mode.assert_called_with(SpaLight.LightMode.PURPLE, 100)
light: SpaLight = next(
light for light in await spa.get_lights() if light.zone == light_zone
)
else:
assert state.state == "on"
await hass.services.async_call(
"light",
"turn_off",
{"entity_id": entity_id},
blocking=True,
)
await hass.services.async_call(
"light",
service_name,
{"entity_id": entity_id, **service_params},
blocking=True,
)
light.set_mode.assert_called_with(*set_mode_args)