From e4468570017df23db561c43bb94afea25973ba53 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Sat, 6 Jan 2024 23:06:28 -0700 Subject: [PATCH] Clean up buggy Guardian `switch` context managers (#107426) --- homeassistant/components/guardian/switch.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/guardian/switch.py b/homeassistant/components/guardian/switch.py index 69d86c10e04..1ed5239641d 100644 --- a/homeassistant/components/guardian/switch.py +++ b/homeassistant/components/guardian/switch.py @@ -49,22 +49,26 @@ class ValveControllerSwitchDescription( async def _async_disable_ap(client: Client) -> None: """Disable the onboard AP.""" - await client.wifi.disable_ap() + async with client: + await client.wifi.disable_ap() async def _async_enable_ap(client: Client) -> None: """Enable the onboard AP.""" - await client.wifi.enable_ap() + async with client: + await client.wifi.enable_ap() async def _async_close_valve(client: Client) -> None: """Close the valve.""" - await client.valve.close() + async with client: + await client.valve.close() async def _async_open_valve(client: Client) -> None: """Open the valve.""" - await client.valve.open() + async with client: + await client.valve.open() VALVE_CONTROLLER_DESCRIPTIONS = ( @@ -141,13 +145,11 @@ class ValveControllerSwitch(ValveControllerEntity, SwitchEntity): @convert_exceptions_to_homeassistant_error async def async_turn_off(self, **kwargs: Any) -> None: """Turn the switch off.""" - async with self._client: - await self.entity_description.off_fn(self._client) + await self.entity_description.off_fn(self._client) await self.coordinator.async_request_refresh() @convert_exceptions_to_homeassistant_error async def async_turn_on(self, **kwargs: Any) -> None: """Turn the switch on.""" - async with self._client: - await self.entity_description.on_fn(self._client) + await self.entity_description.on_fn(self._client) await self.coordinator.async_request_refresh()