diff --git a/homeassistant/components/switcher_kis/button.py b/homeassistant/components/switcher_kis/button.py index 9454dcabc49..b770c48c11c 100644 --- a/homeassistant/components/switcher_kis/button.py +++ b/homeassistant/components/switcher_kis/button.py @@ -2,11 +2,13 @@ from __future__ import annotations -from collections.abc import Callable +from collections.abc import Callable, Coroutine from dataclasses import dataclass +from typing import Any, cast from aioswitcher.api import ( DeviceState, + SwitcherApi, SwitcherBaseResponse, SwitcherType2Api, ThermostatSwing, @@ -34,7 +36,10 @@ from .utils import get_breeze_remote_manager class SwitcherThermostatButtonEntityDescription(ButtonEntityDescription): """Class to describe a Switcher Thermostat Button entity.""" - press_fn: Callable[[SwitcherType2Api, SwitcherBreezeRemote], SwitcherBaseResponse] + press_fn: Callable[ + [SwitcherApi, SwitcherBreezeRemote], + Coroutine[Any, Any, SwitcherBaseResponse], + ] supported: Callable[[SwitcherBreezeRemote], bool] @@ -85,9 +90,10 @@ async def async_setup_entry( async def async_add_buttons(coordinator: SwitcherDataUpdateCoordinator) -> None: """Get remote and add button from Switcher device.""" + data = cast(SwitcherBreezeRemote, coordinator.data) if coordinator.data.device_type.category == DeviceCategory.THERMOSTAT: remote: SwitcherBreezeRemote = await hass.async_add_executor_job( - get_breeze_remote_manager(hass).get_remote, coordinator.data.remote_id + get_breeze_remote_manager(hass).get_remote, data.remote_id ) async_add_entities( SwitcherThermostatButtonEntity(coordinator, description, remote) @@ -126,7 +132,7 @@ class SwitcherThermostatButtonEntity( async def async_press(self) -> None: """Press the button.""" - response: SwitcherBaseResponse = None + response: SwitcherBaseResponse | None = None error = None try: diff --git a/homeassistant/components/switcher_kis/climate.py b/homeassistant/components/switcher_kis/climate.py index 9797873c73b..e6267e15305 100644 --- a/homeassistant/components/switcher_kis/climate.py +++ b/homeassistant/components/switcher_kis/climate.py @@ -9,6 +9,7 @@ from aioswitcher.api.remotes import SwitcherBreezeRemote from aioswitcher.device import ( DeviceCategory, DeviceState, + SwitcherThermostat, ThermostatFanLevel, ThermostatMode, ThermostatSwing, @@ -68,9 +69,10 @@ async def async_setup_entry( async def async_add_climate(coordinator: SwitcherDataUpdateCoordinator) -> None: """Get remote and add climate from Switcher device.""" + data = cast(SwitcherThermostat, coordinator.data) if coordinator.data.device_type.category == DeviceCategory.THERMOSTAT: remote: SwitcherBreezeRemote = await hass.async_add_executor_job( - get_breeze_remote_manager(hass).get_remote, coordinator.data.remote_id + get_breeze_remote_manager(hass).get_remote, data.remote_id ) async_add_entities([SwitcherClimateEntity(coordinator, remote)]) @@ -133,13 +135,13 @@ class SwitcherClimateEntity( def _update_data(self, force_update: bool = False) -> None: """Update data from device.""" - data = self.coordinator.data + data = cast(SwitcherThermostat, self.coordinator.data) features = self._remote.modes_features[data.mode] if data.target_temperature == 0 and not force_update: return - self._attr_current_temperature = cast(float, data.temperature) + self._attr_current_temperature = data.temperature self._attr_target_temperature = float(data.target_temperature) self._attr_hvac_mode = HVACMode.OFF @@ -162,7 +164,7 @@ class SwitcherClimateEntity( async def _async_control_breeze_device(self, **kwargs: Any) -> None: """Call Switcher Control Breeze API.""" - response: SwitcherBaseResponse = None + response: SwitcherBaseResponse | None = None error = None try: @@ -185,9 +187,8 @@ class SwitcherClimateEntity( async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" - if not self._remote.modes_features[self.coordinator.data.mode][ - "temperature_control" - ]: + data = cast(SwitcherThermostat, self.coordinator.data) + if not self._remote.modes_features[data.mode]["temperature_control"]: raise HomeAssistantError( "Current mode doesn't support setting Target Temperature" ) @@ -199,7 +200,8 @@ class SwitcherClimateEntity( async def async_set_fan_mode(self, fan_mode: str) -> None: """Set new target fan mode.""" - if not self._remote.modes_features[self.coordinator.data.mode]["fan_levels"]: + data = cast(SwitcherThermostat, self.coordinator.data) + if not self._remote.modes_features[data.mode]["fan_levels"]: raise HomeAssistantError("Current mode doesn't support setting Fan Mode") await self._async_control_breeze_device(fan_level=HA_TO_DEVICE_FAN[fan_mode]) @@ -215,7 +217,8 @@ class SwitcherClimateEntity( async def async_set_swing_mode(self, swing_mode: str) -> None: """Set new target swing operation.""" - if not self._remote.modes_features[self.coordinator.data.mode]["swing"]: + data = cast(SwitcherThermostat, self.coordinator.data) + if not self._remote.modes_features[data.mode]["swing"]: raise HomeAssistantError("Current mode doesn't support setting Swing Mode") if swing_mode == SWING_VERTICAL: diff --git a/homeassistant/components/switcher_kis/coordinator.py b/homeassistant/components/switcher_kis/coordinator.py index 08207aa0d79..1fdefda23a2 100644 --- a/homeassistant/components/switcher_kis/coordinator.py +++ b/homeassistant/components/switcher_kis/coordinator.py @@ -45,17 +45,17 @@ class SwitcherDataUpdateCoordinator( @property def model(self) -> str: """Switcher device model.""" - return self.data.device_type.value # type: ignore[no-any-return] + return self.data.device_type.value @property def device_id(self) -> str: """Switcher device id.""" - return self.data.device_id # type: ignore[no-any-return] + return self.data.device_id @property def mac_address(self) -> str: """Switcher device mac address.""" - return self.data.mac_address # type: ignore[no-any-return] + return self.data.mac_address @callback def async_setup(self) -> None: diff --git a/homeassistant/components/switcher_kis/cover.py b/homeassistant/components/switcher_kis/cover.py index 8f75ae49905..258af3e1d5e 100644 --- a/homeassistant/components/switcher_kis/cover.py +++ b/homeassistant/components/switcher_kis/cover.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging -from typing import Any +from typing import Any, cast from aioswitcher.api import SwitcherBaseResponse, SwitcherType2Api from aioswitcher.device import DeviceCategory, ShutterDirection, SwitcherShutter @@ -84,7 +84,7 @@ class SwitcherCoverEntity( def _update_data(self) -> None: """Update data from device.""" - data: SwitcherShutter = self.coordinator.data + data = cast(SwitcherShutter, self.coordinator.data) self._attr_current_cover_position = data.position self._attr_is_closed = data.position == 0 self._attr_is_closing = data.direction == ShutterDirection.SHUTTER_DOWN @@ -93,7 +93,7 @@ class SwitcherCoverEntity( async def _async_call_api(self, api: str, *args: Any) -> None: """Call Switcher API.""" _LOGGER.debug("Calling api for %s, api: '%s', args: %s", self.name, api, args) - response: SwitcherBaseResponse = None + response: SwitcherBaseResponse | None = None error = None try: diff --git a/homeassistant/components/switcher_kis/manifest.json b/homeassistant/components/switcher_kis/manifest.json index bf236013896..52b218fce9c 100644 --- a/homeassistant/components/switcher_kis/manifest.json +++ b/homeassistant/components/switcher_kis/manifest.json @@ -7,6 +7,6 @@ "iot_class": "local_push", "loggers": ["aioswitcher"], "quality_scale": "platinum", - "requirements": ["aioswitcher==3.4.1"], + "requirements": ["aioswitcher==3.4.3"], "single_config_entry": true } diff --git a/homeassistant/components/switcher_kis/switch.py b/homeassistant/components/switcher_kis/switch.py index 1de4e840d96..2280d6bc845 100644 --- a/homeassistant/components/switcher_kis/switch.py +++ b/homeassistant/components/switcher_kis/switch.py @@ -111,7 +111,7 @@ class SwitcherBaseSwitchEntity( _LOGGER.debug( "Calling api for %s, api: '%s', args: %s", self.coordinator.name, api, args ) - response: SwitcherBaseResponse = None + response: SwitcherBaseResponse | None = None error = None try: diff --git a/requirements_all.txt b/requirements_all.txt index 6baa552b0f6..cd8df47364e 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -371,7 +371,7 @@ aiosolaredge==0.2.0 aiosteamist==0.3.2 # homeassistant.components.switcher_kis -aioswitcher==3.4.1 +aioswitcher==3.4.3 # homeassistant.components.syncthing aiosyncthing==0.5.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index ca926fb99ce..da6199e3341 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -344,7 +344,7 @@ aiosolaredge==0.2.0 aiosteamist==0.3.2 # homeassistant.components.switcher_kis -aioswitcher==3.4.1 +aioswitcher==3.4.3 # homeassistant.components.syncthing aiosyncthing==0.5.1