mirror of
https://github.com/home-assistant/core.git
synced 2025-11-14 21:40:16 +00:00
Fix missing Shelly MAC address checks (#130833)
* Fix missing Shelly MAC address checks * Make new error for mac_address_mismatch * Use reference in translation
This commit is contained in:
@@ -16,7 +16,7 @@ import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.components.shelly import config_flow
|
||||
from homeassistant.components.shelly import MacAddressMismatchError, config_flow
|
||||
from homeassistant.components.shelly.const import (
|
||||
CONF_BLE_SCANNER_MODE,
|
||||
DOMAIN,
|
||||
@@ -331,6 +331,7 @@ async def test_form_missing_model_key_zeroconf(
|
||||
("exc", "base_error"),
|
||||
[
|
||||
(DeviceConnectionError, "cannot_connect"),
|
||||
(MacAddressMismatchError, "mac_address_mismatch"),
|
||||
(ValueError, "unknown"),
|
||||
],
|
||||
)
|
||||
@@ -436,6 +437,7 @@ async def test_user_setup_ignored_device(
|
||||
[
|
||||
(InvalidAuthError, "invalid_auth"),
|
||||
(DeviceConnectionError, "cannot_connect"),
|
||||
(MacAddressMismatchError, "mac_address_mismatch"),
|
||||
(ValueError, "unknown"),
|
||||
],
|
||||
)
|
||||
@@ -473,6 +475,7 @@ async def test_form_auth_errors_test_connection_gen1(
|
||||
[
|
||||
(DeviceConnectionError, "cannot_connect"),
|
||||
(InvalidAuthError, "invalid_auth"),
|
||||
(MacAddressMismatchError, "mac_address_mismatch"),
|
||||
(ValueError, "unknown"),
|
||||
],
|
||||
)
|
||||
@@ -844,8 +847,19 @@ async def test_reauth_successful(
|
||||
(3, {"password": "test2 password"}),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("exc", "abort_reason"),
|
||||
[
|
||||
(DeviceConnectionError, "reauth_unsuccessful"),
|
||||
(MacAddressMismatchError, "mac_address_mismatch"),
|
||||
],
|
||||
)
|
||||
async def test_reauth_unsuccessful(
|
||||
hass: HomeAssistant, gen: int, user_input: dict[str, str]
|
||||
hass: HomeAssistant,
|
||||
gen: int,
|
||||
user_input: dict[str, str],
|
||||
exc: Exception,
|
||||
abort_reason: str,
|
||||
) -> None:
|
||||
"""Test reauthentication flow failed."""
|
||||
entry = MockConfigEntry(
|
||||
@@ -862,13 +876,9 @@ async def test_reauth_unsuccessful(
|
||||
return_value={"mac": "test-mac", "type": MODEL_1, "auth": True, "gen": gen},
|
||||
),
|
||||
patch(
|
||||
"aioshelly.block_device.BlockDevice.create",
|
||||
new=AsyncMock(side_effect=InvalidAuthError),
|
||||
),
|
||||
patch(
|
||||
"aioshelly.rpc_device.RpcDevice.create",
|
||||
new=AsyncMock(side_effect=InvalidAuthError),
|
||||
"aioshelly.block_device.BlockDevice.create", new=AsyncMock(side_effect=exc)
|
||||
),
|
||||
patch("aioshelly.rpc_device.RpcDevice.create", new=AsyncMock(side_effect=exc)),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
@@ -876,7 +886,7 @@ async def test_reauth_unsuccessful(
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reauth_unsuccessful"
|
||||
assert result["reason"] == abort_reason
|
||||
|
||||
|
||||
async def test_reauth_get_info_error(hass: HomeAssistant) -> None:
|
||||
|
||||
Reference in New Issue
Block a user