Fix bug in rainbird switch when turning off a switch that is already 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>
pull/115463/head
Allen Porter 2024-04-11 19:14:52 -07:00 committed by Franck Nijhof
parent 5fa06e5a9c
commit a455e142ac
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 9 additions and 4 deletions

View File

@ -123,6 +123,7 @@ class RainBirdSwitch(CoordinatorEntity[RainbirdUpdateCoordinator], SwitchEntity)
# The device reflects the old state for a few moments. Update the # The device reflects the old state for a few moments. Update the
# state manually and trigger a refresh after a short debounced delay. # state manually and trigger a refresh after a short debounced delay.
if self.is_on:
self.coordinator.data.active_zones.remove(self._zone) self.coordinator.data.active_zones.remove(self._zone)
self.async_write_ha_state() self.async_write_ha_state()
await self.coordinator.async_request_refresh() await self.coordinator.async_request_refresh()

View File

@ -146,20 +146,24 @@ async def test_switch_on(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"zone_state_response", ("zone_state_response", "start_state"),
[ZONE_3_ON_RESPONSE], [
(ZONE_3_ON_RESPONSE, "on"),
(ZONE_OFF_RESPONSE, "off"), # Already off
],
) )
async def test_switch_off( async def test_switch_off(
hass: HomeAssistant, hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker, aioclient_mock: AiohttpClientMocker,
responses: list[AiohttpClientMockResponse], responses: list[AiohttpClientMockResponse],
start_state: str,
) -> None: ) -> None:
"""Test turning off irrigation switch.""" """Test turning off irrigation switch."""
# Initially the test zone is on # Initially the test zone is on
zone = hass.states.get("switch.rain_bird_sprinkler_3") zone = hass.states.get("switch.rain_bird_sprinkler_3")
assert zone is not None assert zone is not None
assert zone.state == "on" assert zone.state == start_state
aioclient_mock.mock_calls.clear() aioclient_mock.mock_calls.clear()
responses.extend( responses.extend(