Restore switch.turn_on and switch.turn_off functionality for SmartTub pumps (#47586)

Revert "Remove turn_on and turn_off from SmartTub pump switches (#47184)"

This reverts commit bab66a5cb968bcc7c6ef7787c9dc645885569429.
This commit is contained in:
Matt Zimmerman 2021-03-09 16:26:54 -08:00 committed by GitHub
parent a060acc2b1
commit 7840db0598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -61,6 +61,20 @@ class SmartTubPump(SmartTubEntity, SwitchEntity):
"""Return True if the pump is on."""
return self.pump.state != SpaPump.PumpState.OFF
async def async_turn_on(self, **kwargs) -> None:
"""Turn the pump on."""
# the API only supports toggling
if not self.is_on:
await self.async_toggle()
async def async_turn_off(self, **kwargs) -> None:
"""Turn the pump off."""
# the API only supports toggling
if self.is_on:
await self.async_toggle()
async def async_toggle(self, **kwargs) -> None:
"""Toggle the pump on or off."""
async with async_timeout.timeout(API_TIMEOUT):

View File

@ -2,6 +2,8 @@
import pytest
from homeassistant.const import STATE_OFF, STATE_ON
@pytest.mark.parametrize(
"pump_id,entity_suffix,pump_state",
@ -28,3 +30,22 @@ async def test_pumps(spa, setup_entry, hass, pump_id, pump_state, entity_suffix)
blocking=True,
)
pump.toggle.assert_called()
if state.state == STATE_OFF:
await hass.services.async_call(
"switch",
"turn_on",
{"entity_id": entity_id},
blocking=True,
)
pump.toggle.assert_called()
else:
assert state.state == STATE_ON
await hass.services.async_call(
"switch",
"turn_off",
{"entity_id": entity_id},
blocking=True,
)
pump.toggle.assert_called()