diff --git a/homeassistant/components/switcher_kis/climate.py b/homeassistant/components/switcher_kis/climate.py index 5285e7549ef..2fc4a331676 100644 --- a/homeassistant/components/switcher_kis/climate.py +++ b/homeassistant/components/switcher_kis/climate.py @@ -4,7 +4,6 @@ from __future__ import annotations from typing import Any, cast -from aioswitcher.api import SwitcherApi, SwitcherBaseResponse from aioswitcher.api.remotes import SwitcherBreezeRemote from aioswitcher.device import ( DeviceCategory, @@ -38,6 +37,8 @@ from .coordinator import SwitcherDataUpdateCoordinator from .entity import SwitcherEntity from .utils import get_breeze_remote_manager +API_CONTROL_BREEZE_DEVICE = "control_breeze_device" + DEVICE_MODE_TO_HA = { ThermostatMode.COOL: HVACMode.COOL, ThermostatMode.HEAT: HVACMode.HEAT, @@ -155,27 +156,7 @@ class SwitcherClimateEntity(SwitcherEntity, ClimateEntity): async def _async_control_breeze_device(self, **kwargs: Any) -> None: """Call Switcher Control Breeze API.""" - response: SwitcherBaseResponse | None = None - error = None - - try: - async with SwitcherApi( - self.coordinator.data.device_type, - self.coordinator.data.ip_address, - self.coordinator.data.device_id, - self.coordinator.data.device_key, - ) as swapi: - response = await swapi.control_breeze_device(self._remote, **kwargs) - except (TimeoutError, OSError, RuntimeError) as err: - error = repr(err) - - if error or not response or not response.successful: - self.coordinator.last_update_success = False - self.async_write_ha_state() - raise HomeAssistantError( - f"Call Breeze control for {self.name} failed, " - f"response/error: {response or error}" - ) + await self._async_call_api(API_CONTROL_BREEZE_DEVICE, self._remote, **kwargs) async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" diff --git a/homeassistant/components/switcher_kis/entity.py b/homeassistant/components/switcher_kis/entity.py index e24f59a4a1c..82b892d548d 100644 --- a/homeassistant/components/switcher_kis/entity.py +++ b/homeassistant/components/switcher_kis/entity.py @@ -3,7 +3,8 @@ import logging from typing import Any -from aioswitcher.api import SwitcherApi, SwitcherBaseResponse +from aioswitcher.api import SwitcherApi +from aioswitcher.api.messages import SwitcherBaseResponse from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import device_registry as dr @@ -27,7 +28,7 @@ class SwitcherEntity(CoordinatorEntity[SwitcherDataUpdateCoordinator]): connections={(dr.CONNECTION_NETWORK_MAC, coordinator.mac_address)} ) - async def _async_call_api(self, api: str, *args: Any) -> None: + async def _async_call_api(self, api: str, *args: Any, **kwargs: Any) -> None: """Call Switcher API.""" _LOGGER.debug("Calling api for %s, api: '%s', args: %s", self.name, api, args) response: SwitcherBaseResponse | None = None @@ -41,7 +42,7 @@ class SwitcherEntity(CoordinatorEntity[SwitcherDataUpdateCoordinator]): self.coordinator.data.device_key, self.coordinator.token, ) as swapi: - response = await getattr(swapi, api)(*args) + response = await getattr(swapi, api)(*args, **kwargs) except (TimeoutError, OSError, RuntimeError) as err: error = repr(err)