Skip to content

Commit 4e2dca1

Browse files
committed
Support enable/disable_rain_delay services on rain delay switch
The valve service handler routes service calls through both VALVE_DOMAIN and SWITCH_DOMAIN, but only BHyveZoneValve implemented enable_rain_delay and disable_rain_delay. Calling bhyve.enable_rain_delay with a rain delay switch entity logged "Service is not supported by entity" and the requested hours were never applied. Add matching methods to BHyveRainDelaySwitch so the service resolves on the natural target entity, and delegate async_turn_on/off through them to keep a single path to the client. Fixes #407
1 parent 93166d4 commit 4e2dca1

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

custom_components/bhyve/switch.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,16 @@ def extra_state_attributes(self) -> dict[str, Any]:
480480

481481
async def async_turn_on(self, **_kwargs: Any) -> None:
482482
"""Turn the switch on."""
483-
await self.coordinator.client.set_rain_delay(self._device_id, 24)
483+
await self.enable_rain_delay()
484484

485485
async def async_turn_off(self, **_kwargs: Any) -> None:
486486
"""Turn the switch off."""
487+
await self.disable_rain_delay()
488+
489+
async def enable_rain_delay(self, hours: int = 24) -> None:
490+
"""Enable rain delay for the device."""
491+
await self.coordinator.client.set_rain_delay(self._device_id, hours)
492+
493+
async def disable_rain_delay(self) -> None:
494+
"""Disable rain delay for the device."""
487495
await self.coordinator.client.set_rain_delay(self._device_id, 0)

tests/test_switch.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,44 @@ async def test_rain_delay_switch_turn_off(
849849
# Verify set_rain_delay was called with 0 hours to disable
850850
coordinator.client.set_rain_delay.assert_called_once_with(TEST_DEVICE_ID, 0)
851851

852+
async def test_rain_delay_switch_enable_rain_delay(
853+
self,
854+
mock_sprinkler_device: BHyveDevice,
855+
mock_coordinator: MagicMock,
856+
) -> None:
857+
"""Test enable_rain_delay service method honours custom hours."""
858+
description = create_rain_delay_switch_description(mock_sprinkler_device)
859+
switch = BHyveRainDelaySwitch(
860+
coordinator=mock_coordinator,
861+
device=mock_sprinkler_device,
862+
description=description,
863+
)
864+
865+
await switch.enable_rain_delay(hours=5)
866+
867+
mock_coordinator.client.set_rain_delay.assert_called_once_with(
868+
TEST_DEVICE_ID, 5
869+
)
870+
871+
async def test_rain_delay_switch_disable_rain_delay(
872+
self,
873+
mock_sprinkler_device: BHyveDevice,
874+
mock_coordinator: MagicMock,
875+
) -> None:
876+
"""Test disable_rain_delay service method clears the delay."""
877+
description = create_rain_delay_switch_description(mock_sprinkler_device)
878+
switch = BHyveRainDelaySwitch(
879+
coordinator=mock_coordinator,
880+
device=mock_sprinkler_device,
881+
description=description,
882+
)
883+
884+
await switch.disable_rain_delay()
885+
886+
mock_coordinator.client.set_rain_delay.assert_called_once_with(
887+
TEST_DEVICE_ID, 0
888+
)
889+
852890
async def test_rain_delay_switch_websocket_event(
853891
self,
854892
mock_sprinkler_device: BHyveDevice,

0 commit comments

Comments
 (0)