Skip to content

Commit

Permalink
Fix bug in rainbird switch when turning off a switch that is already …
Browse files Browse the repository at this point in the history
…off (#115421)

Fix big in rainbird switch when turning off a switch that is already off

Co-authored-by: J. Nick Koston <nick@koston.org>
  • Loading branch information
2 people authored and frenck committed Apr 12, 2024
1 parent 5fa06e5 commit a455e14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion homeassistant/components/rainbird/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ async def async_turn_off(self, **kwargs):

# The device reflects the old state for a few moments. Update the
# state manually and trigger a refresh after a short debounced delay.
self.coordinator.data.active_zones.remove(self._zone)
if self.is_on:
self.coordinator.data.active_zones.remove(self._zone)
self.async_write_ha_state()
await self.coordinator.async_request_refresh()

Expand Down
10 changes: 7 additions & 3 deletions tests/components/rainbird/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,24 @@ async def test_switch_on(


@pytest.mark.parametrize(
"zone_state_response",
[ZONE_3_ON_RESPONSE],
("zone_state_response", "start_state"),
[
(ZONE_3_ON_RESPONSE, "on"),
(ZONE_OFF_RESPONSE, "off"), # Already off
],
)
async def test_switch_off(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
responses: list[AiohttpClientMockResponse],
start_state: str,
) -> None:
"""Test turning off irrigation switch."""

# Initially the test zone is on
zone = hass.states.get("switch.rain_bird_sprinkler_3")
assert zone is not None
assert zone.state == "on"
assert zone.state == start_state

aioclient_mock.mock_calls.clear()
responses.extend(
Expand Down

0 comments on commit a455e14

Please sign in to comment.