Skip to content

Commit

Permalink
Update pySwitchbot to 0.46.0 to fix lock key retrieval (#118005)
Browse files Browse the repository at this point in the history
* Update pySwitchbot to 0.46.0 to fix lock key retrieval

needs sblibs/pySwitchbot#236

* bump

* fixes
  • Loading branch information
bdraco authored and frenck committed May 24, 2024
1 parent 09779b5 commit f4b653a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
15 changes: 11 additions & 4 deletions homeassistant/components/switchbot/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from switchbot import (
SwitchbotAccountConnectionError,
SwitchBotAdvertisement,
SwitchbotApiError,
SwitchbotAuthenticationError,
SwitchbotLock,
SwitchbotModel,
Expand All @@ -33,6 +34,7 @@
)
from homeassistant.core import callback
from homeassistant.data_entry_flow import AbortFlow
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import (
CONF_ENCRYPTION_KEY,
Expand Down Expand Up @@ -175,14 +177,19 @@ async def async_step_lock_auth(
description_placeholders = {}
if user_input is not None:
try:
key_details = await self.hass.async_add_executor_job(
SwitchbotLock.retrieve_encryption_key,
key_details = await SwitchbotLock.async_retrieve_encryption_key(
async_get_clientsession(self.hass),
self._discovered_adv.address,
user_input[CONF_USERNAME],
user_input[CONF_PASSWORD],
)
except SwitchbotAccountConnectionError as ex:
raise AbortFlow("cannot_connect") from ex
except (SwitchbotApiError, SwitchbotAccountConnectionError) as ex:
_LOGGER.debug(
"Failed to connect to SwitchBot API: %s", ex, exc_info=True
)
raise AbortFlow(
"api_error", description_placeholders={"error_detail": str(ex)}
) from ex
except SwitchbotAuthenticationError as ex:
_LOGGER.debug("Authentication failed: %s", ex, exc_info=True)
errors = {"base": "auth_failed"}
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/switchbot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
"documentation": "https://www.home-assistant.io/integrations/switchbot",
"iot_class": "local_push",
"loggers": ["switchbot"],
"requirements": ["PySwitchbot==0.45.0"]
"requirements": ["PySwitchbot==0.46.0"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/switchbot/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"already_configured_device": "[%key:common::config_flow::abort::already_configured_device%]",
"no_devices_found": "No supported SwitchBot devices found in range; If the device is in range, ensure the scanner has active scanning enabled, as SwitchBot devices cannot be discovered with passive scans. Active scans can be disabled once the device is configured. If you need clarification on whether the device is in-range, download the diagnostics for the integration that provides your Bluetooth adapter or proxy and check if the MAC address of the SwitchBot device is present.",
"unknown": "[%key:common::config_flow::error::unknown%]",
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"api_error": "Error while communicating with SwitchBot API: {error_detail}",
"switchbot_unsupported_type": "Unsupported Switchbot Type."
}
},
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ PyQRCode==1.2.1
PyRMVtransport==0.3.3

# homeassistant.components.switchbot
PySwitchbot==0.45.0
PySwitchbot==0.46.0

# homeassistant.components.switchmate
PySwitchmate==0.5.1
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ PyQRCode==1.2.1
PyRMVtransport==0.3.3

# homeassistant.components.switchbot
PySwitchbot==0.45.0
PySwitchbot==0.46.0

# homeassistant.components.syncthru
PySyncThru==0.7.10
Expand Down
11 changes: 6 additions & 5 deletions tests/components/switchbot/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ async def test_user_setup_wolock_auth(hass: HomeAssistant) -> None:
assert result["errors"] == {}

with patch(
"homeassistant.components.switchbot.config_flow.SwitchbotLock.retrieve_encryption_key",
"homeassistant.components.switchbot.config_flow.SwitchbotLock.async_retrieve_encryption_key",
side_effect=SwitchbotAuthenticationError("error from api"),
):
result = await hass.config_entries.flow.async_configure(
Expand All @@ -510,7 +510,7 @@ async def test_user_setup_wolock_auth(hass: HomeAssistant) -> None:
return_value=True,
),
patch(
"homeassistant.components.switchbot.config_flow.SwitchbotLock.retrieve_encryption_key",
"homeassistant.components.switchbot.config_flow.SwitchbotLock.async_retrieve_encryption_key",
return_value={
CONF_KEY_ID: "ff",
CONF_ENCRYPTION_KEY: "ffffffffffffffffffffffffffffffff",
Expand Down Expand Up @@ -560,8 +560,8 @@ async def test_user_setup_wolock_auth_switchbot_api_down(hass: HomeAssistant) ->
assert result["errors"] == {}

with patch(
"homeassistant.components.switchbot.config_flow.SwitchbotLock.retrieve_encryption_key",
side_effect=SwitchbotAccountConnectionError,
"homeassistant.components.switchbot.config_flow.SwitchbotLock.async_retrieve_encryption_key",
side_effect=SwitchbotAccountConnectionError("Switchbot API down"),
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
Expand All @@ -572,7 +572,8 @@ async def test_user_setup_wolock_auth_switchbot_api_down(hass: HomeAssistant) ->
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "cannot_connect"
assert result["reason"] == "api_error"
assert result["description_placeholders"] == {"error_detail": "Switchbot API down"}


async def test_user_setup_wolock_or_bot(hass: HomeAssistant) -> None:
Expand Down

0 comments on commit f4b653a

Please sign in to comment.