1
0
mirror of https://github.com/home-assistant/core synced 2024-07-01 07:15:04 +00:00

Update pySwitchbot to 0.46.0 to fix lock key retrieval (#118005)

* Update pySwitchbot to 0.46.0 to fix lock key retrieval

needs https://github.com/Danielhiversen/pySwitchbot/pull/236

* bump

* fixes
This commit is contained in:
J. Nick Koston 2024-05-23 17:59:44 -10:00 committed by GitHub
parent d1af40f1eb
commit 93daac9b3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 21 additions and 13 deletions

View File

@ -8,6 +8,7 @@ from typing import Any
from switchbot import (
SwitchbotAccountConnectionError,
SwitchBotAdvertisement,
SwitchbotApiError,
SwitchbotAuthenticationError,
SwitchbotLock,
SwitchbotModel,
@ -33,6 +34,7 @@ from homeassistant.const import (
)
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,
@ -175,14 +177,19 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN):
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"}

View File

@ -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"]
}

View File

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

View File

@ -90,7 +90,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

View File

@ -78,7 +78,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

View File

@ -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(
@ -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",
@ -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"],
@ -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: