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
parent
5fa06e5a9c
commit
a455e142ac
|
@ -123,7 +123,8 @@ class RainBirdSwitch(CoordinatorEntity[RainbirdUpdateCoordinator], SwitchEntity)
|
|||
|
||||
# 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()
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue