From 2d206e7e3172c68a191fb9487ca1370eb7958b15 Mon Sep 17 00:00:00 2001 From: Jafar Atili Date: Mon, 12 Dec 2022 17:00:30 +0200 Subject: [PATCH] Bump pyswitchbee to 1.7.3 (#83748) --- .../components/switchbee/__init__.py | 5 +++-- homeassistant/components/switchbee/button.py | 2 +- homeassistant/components/switchbee/climate.py | 2 +- .../components/switchbee/config_flow.py | 5 +++-- .../components/switchbee/coordinator.py | 7 ++++--- homeassistant/components/switchbee/cover.py | 2 +- homeassistant/components/switchbee/entity.py | 2 +- homeassistant/components/switchbee/light.py | 2 +- .../components/switchbee/manifest.json | 2 +- homeassistant/components/switchbee/switch.py | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../components/switchbee/test_config_flow.py | 20 ++++++++++--------- 13 files changed, 30 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/switchbee/__init__.py b/homeassistant/components/switchbee/__init__.py index 5848477ec71..79b2e449a14 100644 --- a/homeassistant/components/switchbee/__init__.py +++ b/homeassistant/components/switchbee/__init__.py @@ -2,7 +2,8 @@ from __future__ import annotations -from switchbee.api import CentralUnitAPI, SwitchBeeError +from switchbee.api.central_unit import SwitchBeeError +from switchbee.api.polling import CentralUnitPolling from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform @@ -29,7 +30,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: user = entry.data[CONF_USERNAME] password = entry.data[CONF_PASSWORD] websession = async_get_clientsession(hass, verify_ssl=False) - api = CentralUnitAPI(central_unit, user, password, websession) + api = CentralUnitPolling(central_unit, user, password, websession) try: await api.connect() except SwitchBeeError as exp: diff --git a/homeassistant/components/switchbee/button.py b/homeassistant/components/switchbee/button.py index 175aa3af26e..39be264992e 100644 --- a/homeassistant/components/switchbee/button.py +++ b/homeassistant/components/switchbee/button.py @@ -1,6 +1,6 @@ """Support for SwitchBee scenario button.""" -from switchbee.api import SwitchBeeError +from switchbee.api.central_unit import SwitchBeeError from switchbee.device import ApiStateCommand, DeviceType from homeassistant.components.button import ButtonEntity diff --git a/homeassistant/components/switchbee/climate.py b/homeassistant/components/switchbee/climate.py index 6cdf7d700a5..efc9c25d4bd 100644 --- a/homeassistant/components/switchbee/climate.py +++ b/homeassistant/components/switchbee/climate.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any -from switchbee.api import SwitchBeeDeviceOfflineError, SwitchBeeError +from switchbee.api.central_unit import SwitchBeeDeviceOfflineError, SwitchBeeError from switchbee.const import ( ApiAttribute, ThermostatFanSpeed, diff --git a/homeassistant/components/switchbee/config_flow.py b/homeassistant/components/switchbee/config_flow.py index 967af101360..cb9cc27c1d0 100644 --- a/homeassistant/components/switchbee/config_flow.py +++ b/homeassistant/components/switchbee/config_flow.py @@ -4,7 +4,8 @@ from __future__ import annotations import logging from typing import Any -from switchbee.api import CentralUnitAPI, SwitchBeeError +from switchbee.api.central_unit import SwitchBeeError +from switchbee.api.polling import CentralUnitPolling import voluptuous as vol from homeassistant import config_entries @@ -33,7 +34,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> str: """Validate the user input allows us to connect.""" websession = async_get_clientsession(hass, verify_ssl=False) - api = CentralUnitAPI( + api = CentralUnitPolling( data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD], websession ) try: diff --git a/homeassistant/components/switchbee/coordinator.py b/homeassistant/components/switchbee/coordinator.py index 3dee30bac0e..e8453afdbb8 100644 --- a/homeassistant/components/switchbee/coordinator.py +++ b/homeassistant/components/switchbee/coordinator.py @@ -6,7 +6,8 @@ from collections.abc import Mapping from datetime import timedelta import logging -from switchbee.api import CentralUnitAPI, SwitchBeeError +from switchbee.api.central_unit import SwitchBeeError +from switchbee.api.polling import CentralUnitPolling from switchbee.device import DeviceType, SwitchBeeBaseDevice from homeassistant.core import HomeAssistant @@ -24,10 +25,10 @@ class SwitchBeeCoordinator(DataUpdateCoordinator[Mapping[int, SwitchBeeBaseDevic def __init__( self, hass: HomeAssistant, - swb_api: CentralUnitAPI, + swb_api: CentralUnitPolling, ) -> None: """Initialize.""" - self.api: CentralUnitAPI = swb_api + self.api: CentralUnitPolling = swb_api self._reconnect_counts: int = 0 self.mac_formatted: str | None = ( None if self.api.mac is None else format_mac(self.api.mac) diff --git a/homeassistant/components/switchbee/cover.py b/homeassistant/components/switchbee/cover.py index ea5494f7f5b..f317a0e1db8 100644 --- a/homeassistant/components/switchbee/cover.py +++ b/homeassistant/components/switchbee/cover.py @@ -4,7 +4,7 @@ from __future__ import annotations from typing import Any -from switchbee.api import SwitchBeeError, SwitchBeeTokenError +from switchbee.api.central_unit import SwitchBeeError, SwitchBeeTokenError from switchbee.const import SomfyCommand from switchbee.device import SwitchBeeShutter, SwitchBeeSomfy diff --git a/homeassistant/components/switchbee/entity.py b/homeassistant/components/switchbee/entity.py index 28248667c50..6d312b7be22 100644 --- a/homeassistant/components/switchbee/entity.py +++ b/homeassistant/components/switchbee/entity.py @@ -3,7 +3,7 @@ import logging from typing import Generic, TypeVar, cast from switchbee import SWITCHBEE_BRAND -from switchbee.api import SwitchBeeDeviceOfflineError, SwitchBeeError +from switchbee.api.central_unit import SwitchBeeDeviceOfflineError, SwitchBeeError from switchbee.device import DeviceType, SwitchBeeBaseDevice from homeassistant.helpers.entity import DeviceInfo diff --git a/homeassistant/components/switchbee/light.py b/homeassistant/components/switchbee/light.py index 7bcf64598c1..0ff14a45e2f 100644 --- a/homeassistant/components/switchbee/light.py +++ b/homeassistant/components/switchbee/light.py @@ -4,7 +4,7 @@ from __future__ import annotations from typing import Any -from switchbee.api import SwitchBeeDeviceOfflineError, SwitchBeeError +from switchbee.api.central_unit import SwitchBeeDeviceOfflineError, SwitchBeeError from switchbee.device import ApiStateCommand, DeviceType, SwitchBeeDimmer from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity diff --git a/homeassistant/components/switchbee/manifest.json b/homeassistant/components/switchbee/manifest.json index f7bcfef85a4..27201e45090 100644 --- a/homeassistant/components/switchbee/manifest.json +++ b/homeassistant/components/switchbee/manifest.json @@ -3,7 +3,7 @@ "name": "SwitchBee", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/switchbee", - "requirements": ["pyswitchbee==1.6.1"], + "requirements": ["pyswitchbee==1.7.3"], "codeowners": ["@jafar-atili"], "iot_class": "local_polling" } diff --git a/homeassistant/components/switchbee/switch.py b/homeassistant/components/switchbee/switch.py index 48fee37449c..9ed0e6ea9c0 100644 --- a/homeassistant/components/switchbee/switch.py +++ b/homeassistant/components/switchbee/switch.py @@ -4,7 +4,7 @@ from __future__ import annotations from typing import Any, TypeVar, Union -from switchbee.api import SwitchBeeDeviceOfflineError, SwitchBeeError +from switchbee.api.central_unit import SwitchBeeDeviceOfflineError, SwitchBeeError from switchbee.device import ( ApiStateCommand, SwitchBeeGroupSwitch, diff --git a/requirements_all.txt b/requirements_all.txt index 9dcdd18843e..5e754559859 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1956,7 +1956,7 @@ pystiebeleltron==0.0.1.dev2 pysuez==0.1.19 # homeassistant.components.switchbee -pyswitchbee==1.6.1 +pyswitchbee==1.7.3 # homeassistant.components.syncthru pysyncthru==0.7.10 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 4b6d02e1a71..ddb10529702 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1385,7 +1385,7 @@ pyspcwebgw==0.4.0 pysqueezebox==0.6.1 # homeassistant.components.switchbee -pyswitchbee==1.6.1 +pyswitchbee==1.7.3 # homeassistant.components.syncthru pysyncthru==0.7.10 diff --git a/tests/components/switchbee/test_config_flow.py b/tests/components/switchbee/test_config_flow.py index 8b9637a7695..1745d6c5d40 100644 --- a/tests/components/switchbee/test_config_flow.py +++ b/tests/components/switchbee/test_config_flow.py @@ -25,15 +25,15 @@ async def test_form(hass): assert result["errors"] == {} with patch( - "switchbee.api.CentralUnitAPI.get_configuration", + "switchbee.api.polling.CentralUnitPolling.get_configuration", return_value=coordinator_data, ), patch( "homeassistant.components.switchbee.async_setup_entry", return_value=True, ), patch( - "switchbee.api.CentralUnitAPI.fetch_states", return_value=None + "switchbee.api.polling.CentralUnitPolling.fetch_states", return_value=None ), patch( - "switchbee.api.CentralUnitAPI._login", return_value=None + "switchbee.api.polling.CentralUnitPolling._login", return_value=None ): result2 = await hass.config_entries.flow.async_configure( @@ -62,7 +62,7 @@ async def test_form_invalid_auth(hass: HomeAssistant) -> None: ) with patch( - "switchbee.api.CentralUnitAPI._login", + "switchbee.api.polling.CentralUnitPolling._login", side_effect=SwitchBeeError(MOCK_FAILED_TO_LOGIN_MSG), ): result2 = await hass.config_entries.flow.async_configure( @@ -86,7 +86,7 @@ async def test_form_cannot_connect(hass: HomeAssistant) -> None: ) with patch( - "switchbee.api.CentralUnitAPI._login", + "switchbee.api.polling.CentralUnitPolling._login", side_effect=SwitchBeeError(MOCK_INVALID_TOKEN_MGS), ): result2 = await hass.config_entries.flow.async_configure( @@ -109,7 +109,7 @@ async def test_form_unknown_error(hass): ) with patch( - "switchbee.api.CentralUnitAPI._login", + "switchbee.api.polling.CentralUnitPolling._login", side_effect=Exception, ): form_result = await hass.config_entries.flow.async_configure( @@ -144,14 +144,16 @@ async def test_form_entry_exists(hass): DOMAIN, context={"source": config_entries.SOURCE_USER} ) - with patch("switchbee.api.CentralUnitAPI._login", return_value=None), patch( + with patch( + "switchbee.api.polling.CentralUnitPolling._login", return_value=None + ), patch( "homeassistant.components.switchbee.async_setup_entry", return_value=True, ), patch( - "switchbee.api.CentralUnitAPI.get_configuration", + "switchbee.api.polling.CentralUnitPolling.get_configuration", return_value=coordinator_data, ), patch( - "switchbee.api.CentralUnitAPI.fetch_states", return_value=None + "switchbee.api.polling.CentralUnitPolling.fetch_states", return_value=None ): form_result = await hass.config_entries.flow.async_configure( result["flow_id"],