Use Switcher _async_call_api in climate (#133230)

pull/133508/head
Shay Levy 2024-12-18 20:46:52 +02:00 committed by GitHub
parent 0ff2a0d66d
commit 3a8b0b3ea6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 25 deletions

View File

@ -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."""

View File

@ -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)