Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in rainbird switch when turning off a switch that is already off #115421

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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