Skip to content
Snippets Groups Projects
Unverified Commit 18883118 authored by David Knowles's avatar David Knowles Committed by GitHub
Browse files

Hydrawise: Explicitly set switch state on toggle (#103827)

Explicitly set switch state on toggle
parent 64c9aa0c
No related branches found
No related tags found
No related merge requests found
......@@ -114,6 +114,8 @@ class HydrawiseSwitch(HydrawiseEntity, SwitchEntity):
self.coordinator.api.run_zone(self._default_watering_timer, zone_number)
elif self.entity_description.key == "auto_watering":
self.coordinator.api.suspend_zone(0, zone_number)
self._attr_is_on = True
self.async_write_ha_state()
def turn_off(self, **kwargs: Any) -> None:
"""Turn the device off."""
......@@ -122,6 +124,8 @@ class HydrawiseSwitch(HydrawiseEntity, SwitchEntity):
self.coordinator.api.run_zone(0, zone_number)
elif self.entity_description.key == "auto_watering":
self.coordinator.api.suspend_zone(365, zone_number)
self._attr_is_on = False
self.async_write_ha_state()
def _update_attrs(self) -> None:
"""Update state attributes."""
......
......@@ -45,6 +45,9 @@ async def test_manual_watering_services(
blocking=True,
)
mock_pydrawise.run_zone.assert_called_once_with(15, 1)
state = hass.states.get("switch.zone_one_manual_watering")
assert state is not None
assert state.state == "on"
mock_pydrawise.reset_mock()
await hass.services.async_call(
......@@ -54,6 +57,9 @@ async def test_manual_watering_services(
blocking=True,
)
mock_pydrawise.run_zone.assert_called_once_with(0, 1)
state = hass.states.get("switch.zone_one_manual_watering")
assert state is not None
assert state.state == "off"
async def test_auto_watering_services(
......@@ -67,6 +73,9 @@ async def test_auto_watering_services(
blocking=True,
)
mock_pydrawise.suspend_zone.assert_called_once_with(365, 1)
state = hass.states.get("switch.zone_one_automatic_watering")
assert state is not None
assert state.state == "off"
mock_pydrawise.reset_mock()
await hass.services.async_call(
......@@ -76,3 +85,6 @@ async def test_auto_watering_services(
blocking=True,
)
mock_pydrawise.suspend_zone.assert_called_once_with(0, 1)
state = hass.states.get("switch.zone_one_automatic_watering")
assert state is not None
assert state.state == "on"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment