Add light platform to SmartTub (#46886)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Matt Zimmerman
2021-02-21 20:09:21 -10:00
committed by GitHub
co-authored by J. Nick Koston
parent 1a27af43cc
commit 5cd022a683
6 changed files with 204 additions and 2 deletions
+14
View File
@@ -90,6 +90,20 @@ def mock_spa():
mock_spa.get_pumps.return_value = [mock_circulation_pump, mock_jet_off, mock_jet_on]
mock_light_off = create_autospec(smarttub.SpaLight, instance=True)
mock_light_off.spa = mock_spa
mock_light_off.zone = 1
mock_light_off.intensity = 0
mock_light_off.mode = smarttub.SpaLight.LightMode.OFF
mock_light_on = create_autospec(smarttub.SpaLight, instance=True)
mock_light_on.spa = mock_spa
mock_light_on.zone = 2
mock_light_on.intensity = 50
mock_light_on.mode = smarttub.SpaLight.LightMode.PURPLE
mock_spa.get_lights.return_value = [mock_light_off, mock_light_on]
return mock_spa
+38
View File
@@ -0,0 +1,38 @@
"""Test the SmartTub light platform."""
from smarttub import SpaLight
async def test_light(spa, setup_entry, hass):
"""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()
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)
else:
assert state.state == "on"
await hass.services.async_call(
"light",
"turn_off",
{"entity_id": entity_id},
blocking=True,
)