Hydrawise: Explicitly set switch state on toggle (#103827)
Explicitly set switch state on toggle
This commit is contained in:
parent
64c9aa0cff
commit
1888311800
2 changed files with 16 additions and 0 deletions
|
@ -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"
|
||||
|
|
Loading…
Add table
Reference in a new issue