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
|
@ -137,5 +137,5 @@ class SmartTubLight(SmartTubEntity, LightEntity):
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs):
|
||||||
"""Turn the light off."""
|
"""Turn the light off."""
|
||||||
await self.light.set_mode(self.light.LightMode.OFF, 0)
|
await self.light.set_mode(SpaLight.LightMode.OFF, 0)
|
||||||
await self.coordinator.async_request_refresh()
|
await self.coordinator.async_request_refresh()
|
||||||
|
|
|
@ -1,38 +1,45 @@
|
||||||
"""Test the SmartTub light platform."""
|
"""Test the SmartTub light platform."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
from smarttub import SpaLight
|
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."""
|
"""Test light entity."""
|
||||||
|
|
||||||
for light in spa.get_lights.return_value:
|
entity_id = f"light.{spa.brand}_{spa.model}_light_{light_zone}"
|
||||||
entity_id = f"light.{spa.brand}_{spa.model}_light_{light.zone}"
|
state = hass.states.get(entity_id)
|
||||||
state = hass.states.get(entity_id)
|
assert state is not None
|
||||||
assert state is not None
|
assert state.state == light_state
|
||||||
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()
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
light: SpaLight = next(
|
||||||
"light",
|
light for light in await spa.get_lights() if light.zone == light_zone
|
||||||
"turn_on",
|
)
|
||||||
{"entity_id": entity_id, "brightness": 255},
|
|
||||||
blocking=True,
|
|
||||||
)
|
|
||||||
light.set_mode.assert_called_with(SpaLight.LightMode.PURPLE, 100)
|
|
||||||
|
|
||||||
else:
|
await hass.services.async_call(
|
||||||
assert state.state == "on"
|
"light",
|
||||||
await hass.services.async_call(
|
service_name,
|
||||||
"light",
|
{"entity_id": entity_id, **service_params},
|
||||||
"turn_off",
|
blocking=True,
|
||||||
{"entity_id": entity_id},
|
)
|
||||||
blocking=True,
|
light.set_mode.assert_called_with(*set_mode_args)
|
||||||
)
|
|
||||||
|
|
|
@ -1,46 +1,30 @@
|
||||||
"""Test the SmartTub sensor platform."""
|
"""Test the SmartTub sensor platform."""
|
||||||
|
|
||||||
from . import trigger_update
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors(spa, setup_entry, hass):
|
@pytest.mark.parametrize(
|
||||||
"""Test the sensors."""
|
"entity_suffix,expected_state",
|
||||||
|
[
|
||||||
|
("state", "normal"),
|
||||||
|
("flow_switch", "open"),
|
||||||
|
("ozone", "off"),
|
||||||
|
("uv", "off"),
|
||||||
|
("blowout_cycle", "inactive"),
|
||||||
|
("cleanup_cycle", "inactive"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_sensor(spa, setup_entry, hass, entity_suffix, expected_state):
|
||||||
|
"""Test simple sensors."""
|
||||||
|
|
||||||
entity_id = f"sensor.{spa.brand}_{spa.model}_state"
|
entity_id = f"sensor.{spa.brand}_{spa.model}_{entity_suffix}"
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == "normal"
|
assert state.state == expected_state
|
||||||
|
|
||||||
spa.get_status.return_value.state = "BAD"
|
|
||||||
await trigger_update(hass)
|
|
||||||
state = hass.states.get(entity_id)
|
|
||||||
assert state is not None
|
|
||||||
assert state.state == "bad"
|
|
||||||
|
|
||||||
entity_id = f"sensor.{spa.brand}_{spa.model}_flow_switch"
|
async def test_primary_filtration(spa, setup_entry, hass):
|
||||||
state = hass.states.get(entity_id)
|
"""Test the primary filtration cycle sensor."""
|
||||||
assert state is not None
|
|
||||||
assert state.state == "open"
|
|
||||||
|
|
||||||
entity_id = f"sensor.{spa.brand}_{spa.model}_ozone"
|
|
||||||
state = hass.states.get(entity_id)
|
|
||||||
assert state is not None
|
|
||||||
assert state.state == "off"
|
|
||||||
|
|
||||||
entity_id = f"sensor.{spa.brand}_{spa.model}_uv"
|
|
||||||
state = hass.states.get(entity_id)
|
|
||||||
assert state is not None
|
|
||||||
assert state.state == "off"
|
|
||||||
|
|
||||||
entity_id = f"sensor.{spa.brand}_{spa.model}_blowout_cycle"
|
|
||||||
state = hass.states.get(entity_id)
|
|
||||||
assert state is not None
|
|
||||||
assert state.state == "inactive"
|
|
||||||
|
|
||||||
entity_id = f"sensor.{spa.brand}_{spa.model}_cleanup_cycle"
|
|
||||||
state = hass.states.get(entity_id)
|
|
||||||
assert state is not None
|
|
||||||
assert state.state == "inactive"
|
|
||||||
|
|
||||||
entity_id = f"sensor.{spa.brand}_{spa.model}_primary_filtration_cycle"
|
entity_id = f"sensor.{spa.brand}_{spa.model}_primary_filtration_cycle"
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
|
@ -51,6 +35,10 @@ async def test_sensors(spa, setup_entry, hass):
|
||||||
assert state.attributes["mode"] == "normal"
|
assert state.attributes["mode"] == "normal"
|
||||||
assert state.attributes["start_hour"] == 2
|
assert state.attributes["start_hour"] == 2
|
||||||
|
|
||||||
|
|
||||||
|
async def test_secondary_filtration(spa, setup_entry, hass):
|
||||||
|
"""Test the secondary filtration cycle sensor."""
|
||||||
|
|
||||||
entity_id = f"sensor.{spa.brand}_{spa.model}_secondary_filtration_cycle"
|
entity_id = f"sensor.{spa.brand}_{spa.model}_secondary_filtration_cycle"
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state is not None
|
assert state is not None
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
"""Test the SmartTub switch platform."""
|
"""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."""
|
"""Test pump entities."""
|
||||||
|
|
||||||
for pump in spa.get_pumps.return_value:
|
pump = next(pump for pump in await spa.get_pumps() if pump.id == pump_id)
|
||||||
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")
|
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
entity_id = f"switch.{spa.brand}_{spa.model}_{entity_suffix}"
|
||||||
assert state is not None
|
state = hass.states.get(entity_id)
|
||||||
if pump.state == SpaPump.PumpState.OFF:
|
assert state is not None
|
||||||
assert state.state == "off"
|
assert state.state == pump_state
|
||||||
else:
|
|
||||||
assert state.state == "on"
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"switch",
|
"switch",
|
||||||
"toggle",
|
"toggle",
|
||||||
{"entity_id": entity_id},
|
{"entity_id": entity_id},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
pump.toggle.assert_called()
|
pump.toggle.assert_called()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue