Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for SwitchBot relay switch #130863

Merged
merged 34 commits into from
Dec 20, 2024
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e581d25
Support relay switch
greyeee Nov 15, 2024
60f1e83
更新下版本
greyeee Nov 18, 2024
4b1cb67
add test case
greyeee Nov 18, 2024
eb2b5de
Merge branch 'dev' into feature/relay-switch
greyeee Nov 18, 2024
87a706d
change to async_abort
greyeee Nov 18, 2024
9f49927
Merge branch 'feature/relay-switch' of https://github.com/greyeee/cor…
greyeee Nov 18, 2024
b29a7e4
Merge branch 'dev' into feature/relay-switch
greyeee Nov 18, 2024
74bf688
Upgrade PySwitchbot to 0.53.2
greyeee Nov 19, 2024
dab6e8c
Merge branch 'feature/relay-switch' of https://github.com/greyeee/cor…
greyeee Nov 19, 2024
d74f14f
Merge branch 'dev' into feature/relay-switch
greyeee Nov 19, 2024
239bb00
Merge branch 'dev' into feature/relay-switch
bdraco Nov 19, 2024
6dd242a
change unit to volt
greyeee Nov 28, 2024
8fabc07
upgrade pySwitchbot dependency
greyeee Nov 28, 2024
082a64e
Merge branch 'feature/relay-switch' of https://github.com/greyeee/cor…
greyeee Nov 28, 2024
4a750d7
Merge branch 'dev' into feature/relay-switch
joostlek Dec 12, 2024
6101335
Merge branch 'dev' into feature/relay-switch
greyeee Dec 16, 2024
690dbfe
bump lib, will be split into a seperate PR after testing is finished
bdraco Dec 20, 2024
54a2689
Merge branch 'dev' into feature/relay-switch
bdraco Dec 20, 2024
ffd1196
dry
bdraco Dec 20, 2024
efb6ff9
dry
bdraco Dec 20, 2024
56478df
dry
bdraco Dec 20, 2024
6c46cde
dry
bdraco Dec 20, 2024
7aaa1a6
dry
bdraco Dec 20, 2024
062634f
dry
bdraco Dec 20, 2024
fb5e040
dry
bdraco Dec 20, 2024
9c4bab3
update tests
bdraco Dec 20, 2024
45e30ba
fixes
bdraco Dec 20, 2024
47ddf59
fixes
bdraco Dec 20, 2024
9904851
cleanups
bdraco Dec 20, 2024
ca5bae7
fixes
bdraco Dec 20, 2024
c42faf7
fixes
bdraco Dec 20, 2024
cd9bbfa
fixes
bdraco Dec 20, 2024
5edb5e7
bump again
bdraco Dec 20, 2024
07bca62
Merge branch 'dev' into feature/relay-switch
bdraco Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dry
  • Loading branch information
bdraco committed Dec 20, 2024
commit 6c46cde2ae24fa77dcd6e602af37b92ea3ac078c
96 changes: 48 additions & 48 deletions homeassistant/components/switchbot/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,54 @@ async def async_step_password(
},
)

async def async_step_encrypted_auth(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the SwitchBot API auth step."""
errors = {}
assert self._discovered_adv is not None
description_placeholders = {}
if user_input is not None:
try:
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 (SwitchbotApiError, SwitchbotAccountConnectionError) as ex:
_LOGGER.debug(
"Failed to connect to SwitchBot API: %s", ex, exc_info=True
)
return self.async_abort(
reason="api_error",
description_placeholders={"error_detail": str(ex)},
)
except SwitchbotAuthenticationError as ex:
_LOGGER.debug("Authentication failed: %s", ex, exc_info=True)
errors = {"base": "auth_failed"}
description_placeholders = {"error_detail": str(ex)}
else:
return await self.async_step_encrypted_key(key_details)

user_input = user_input or {}
return self.async_show_form(
step_id="auth",
errors=errors,
data_schema=vol.Schema(
{
vol.Required(
CONF_USERNAME, default=user_input.get(CONF_USERNAME)
): str,
vol.Required(CONF_PASSWORD): str,
}
),
description_placeholders={
"name": name_from_discovery(self._discovered_adv),
**description_placeholders,
},
)

async def async_step_encrypted_choose_method(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
Expand Down Expand Up @@ -221,54 +269,6 @@ async def async_step_encrypted_key(
},
)

async def async_step_encrypted_auth(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the SwitchBot API auth step."""
errors = {}
assert self._discovered_adv is not None
description_placeholders = {}
if user_input is not None:
try:
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 (SwitchbotApiError, SwitchbotAccountConnectionError) as ex:
_LOGGER.debug(
"Failed to connect to SwitchBot API: %s", ex, exc_info=True
)
return self.async_abort(
reason="api_error",
description_placeholders={"error_detail": str(ex)},
)
except SwitchbotAuthenticationError as ex:
_LOGGER.debug("Authentication failed: %s", ex, exc_info=True)
errors = {"base": "auth_failed"}
description_placeholders = {"error_detail": str(ex)}
else:
return await self.async_step_encrypted_key(key_details)

user_input = user_input or {}
return self.async_show_form(
step_id="auth",
errors=errors,
data_schema=vol.Schema(
{
vol.Required(
CONF_USERNAME, default=user_input.get(CONF_USERNAME)
): str,
vol.Required(CONF_PASSWORD): str,
}
),
description_placeholders={
"name": name_from_discovery(self._discovered_adv),
**description_placeholders,
},
)

@callback
def _async_discover_devices(self) -> None:
current_addresses = self._async_current_ids()
Expand Down
Loading