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

Handle missing or incorrect device name and unique id for ESPHome during manual add #95678

Merged
merged 11 commits into from
Jul 2, 2023
Prev Previous commit
Next Next commit
less connections when we know we will fail
  • Loading branch information
bdraco committed Jul 1, 2023
commit 6f34eb8a21092ae6b300320b91a55ec901bec774
14 changes: 8 additions & 6 deletions homeassistant/components/esphome/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ async def _async_try_fetch_device_info(self) -> FlowResult:
error = await self.fetch_device_info()
self._noise_psk = None

if self._device_name:
await self._retrieve_encryption_key_from_dashboard()
if (
self._device_name
and await self._retrieve_encryption_key_from_dashboard()
):
error = await self.fetch_device_info()

# If the fetched key is invalid, unset it again.
Expand Down Expand Up @@ -387,10 +389,10 @@ async def _retrieve_encryption_key_from_dashboard(self) -> bool:

Return boolean if a key was retrieved.
"""
if self._device_name is None:
return False

if (dashboard := async_get_dashboard(self.hass)) is None:
if (
self._device_name is None
or (dashboard := async_get_dashboard(self.hass)) is None
):
return False

await dashboard.async_request_refresh()
Expand Down
2 changes: 0 additions & 2 deletions tests/components/esphome/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ async def test_user_discovers_name_and_gets_key_from_dashboard_fails(
mock_client.device_info.side_effect = [
RequiresEncryptionAPIError,
InvalidEncryptionKeyAPIError("Wrong key", "test"),
RequiresEncryptionAPIError,
DeviceInfo(
uses_password=False,
name="test",
Expand Down Expand Up @@ -382,7 +381,6 @@ async def test_user_discovers_name_and_dashboard_is_unavailable(
mock_client.device_info.side_effect = [
RequiresEncryptionAPIError,
InvalidEncryptionKeyAPIError("Wrong key", "test"),
RequiresEncryptionAPIError,
DeviceInfo(
uses_password=False,
name="test",
Expand Down