Parameterize SmartTub tests (#47189)
* Parameterize SmartTub tests * parameterize light service calls * remove stray print() * add comment
This commit is contained in:
parent
a2b13785c2
commit
947f6ea51e
4 changed files with 81 additions and 86 deletions
|
@ -1,30 +1,30 @@
|
|||
"""Test the SmartTub switch platform."""
|
||||
|
||||
from smarttub import SpaPump
|
||||
import pytest
|
||||
|
||||
|
||||
async def test_pumps(spa, setup_entry, hass):
|
||||
@pytest.mark.parametrize(
|
||||
"pump_id,entity_suffix,pump_state",
|
||||
[
|
||||
("CP", "circulation_pump", "off"),
|
||||
("P1", "jet_p1", "off"),
|
||||
("P2", "jet_p2", "on"),
|
||||
],
|
||||
)
|
||||
async def test_pumps(spa, setup_entry, hass, pump_id, pump_state, entity_suffix):
|
||||
"""Test pump entities."""
|
||||
|
||||
for pump in spa.get_pumps.return_value:
|
||||
if pump.type == SpaPump.PumpType.CIRCULATION:
|
||||
entity_id = f"switch.{spa.brand}_{spa.model}_circulation_pump"
|
||||
elif pump.type == SpaPump.PumpType.JET:
|
||||
entity_id = f"switch.{spa.brand}_{spa.model}_jet_{pump.id.lower()}"
|
||||
else:
|
||||
raise NotImplementedError("Unknown pump type")
|
||||
pump = next(pump for pump in await spa.get_pumps() if pump.id == pump_id)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state is not None
|
||||
if pump.state == SpaPump.PumpState.OFF:
|
||||
assert state.state == "off"
|
||||
else:
|
||||
assert state.state == "on"
|
||||
entity_id = f"switch.{spa.brand}_{spa.model}_{entity_suffix}"
|
||||
state = hass.states.get(entity_id)
|
||||
assert state is not None
|
||||
assert state.state == pump_state
|
||||
|
||||
await hass.services.async_call(
|
||||
"switch",
|
||||
"toggle",
|
||||
{"entity_id": entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
pump.toggle.assert_called()
|
||||
await hass.services.async_call(
|
||||
"switch",
|
||||
"toggle",
|
||||
{"entity_id": entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
pump.toggle.assert_called()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue