Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions homeassistant/components/esphome/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from collections import OrderedDict
from collections.abc import Mapping
import json
import logging
from typing import Any

Expand Down Expand Up @@ -408,6 +409,11 @@ async def _retrieve_encryption_key_from_dashboard(self) -> bool:
except aiohttp.ClientError as err:
_LOGGER.error("Error talking to the dashboard: %s", err)
return False
except json.JSONDecodeError as err:
_LOGGER.error(
"Error parsing response from dashboard: %s", err, exc_info=True
)
return False

self._noise_psk = noise_psk
return True
Expand Down
8 changes: 7 additions & 1 deletion tests/components/esphome/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test config flow."""
import asyncio
import json
from unittest.mock import AsyncMock, MagicMock, patch

from aioesphomeapi import (
Expand Down Expand Up @@ -414,8 +415,13 @@ async def test_user_discovers_name_and_gets_key_from_dashboard(
assert mock_client.noise_psk == VALID_NOISE_PSK


@pytest.mark.parametrize(
"dashboard_exception",
[aiohttp.ClientError(), json.JSONDecodeError("test", "test", 0)],
)
async def test_user_discovers_name_and_gets_key_from_dashboard_fails(
hass: HomeAssistant,
dashboard_exception: Exception,
mock_client,
mock_dashboard,
mock_zeroconf: None,
Expand All @@ -442,7 +448,7 @@ async def test_user_discovers_name_and_gets_key_from_dashboard_fails(

with patch(
"homeassistant.components.esphome.dashboard.ESPHomeDashboardAPI.get_encryption_key",
side_effect=aiohttp.ClientError,
side_effect=dashboard_exception,
):
result = await hass.config_entries.flow.async_init(
"esphome",
Expand Down