mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Abort Shelly setup if MAC address mismatch (#98807)
This commit is contained in:
parent
097c7fbfef
commit
406f06f0fc
@ -6,7 +6,11 @@ from typing import Any, Final
|
|||||||
|
|
||||||
from aioshelly.block_device import BlockDevice, BlockUpdateType
|
from aioshelly.block_device import BlockDevice, BlockUpdateType
|
||||||
from aioshelly.common import ConnectionOptions
|
from aioshelly.common import ConnectionOptions
|
||||||
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError
|
from aioshelly.exceptions import (
|
||||||
|
DeviceConnectionError,
|
||||||
|
InvalidAuthError,
|
||||||
|
MacAddressMismatchError,
|
||||||
|
)
|
||||||
from aioshelly.rpc_device import RpcDevice, RpcUpdateType
|
from aioshelly.rpc_device import RpcDevice, RpcUpdateType
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -185,7 +189,7 @@ async def _async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> b
|
|||||||
LOGGER.debug("Setting up online block device %s", entry.title)
|
LOGGER.debug("Setting up online block device %s", entry.title)
|
||||||
try:
|
try:
|
||||||
await device.initialize()
|
await device.initialize()
|
||||||
except DeviceConnectionError as err:
|
except (DeviceConnectionError, MacAddressMismatchError) as err:
|
||||||
raise ConfigEntryNotReady(repr(err)) from err
|
raise ConfigEntryNotReady(repr(err)) from err
|
||||||
except InvalidAuthError as err:
|
except InvalidAuthError as err:
|
||||||
raise ConfigEntryAuthFailed(repr(err)) from err
|
raise ConfigEntryAuthFailed(repr(err)) from err
|
||||||
@ -271,7 +275,7 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ConfigEntry) -> boo
|
|||||||
LOGGER.debug("Setting up online RPC device %s", entry.title)
|
LOGGER.debug("Setting up online RPC device %s", entry.title)
|
||||||
try:
|
try:
|
||||||
await device.initialize()
|
await device.initialize()
|
||||||
except DeviceConnectionError as err:
|
except (DeviceConnectionError, MacAddressMismatchError) as err:
|
||||||
raise ConfigEntryNotReady(repr(err)) from err
|
raise ConfigEntryNotReady(repr(err)) from err
|
||||||
except InvalidAuthError as err:
|
except InvalidAuthError as err:
|
||||||
raise ConfigEntryAuthFailed(repr(err)) from err
|
raise ConfigEntryAuthFailed(repr(err)) from err
|
||||||
|
@ -3,7 +3,11 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError
|
from aioshelly.exceptions import (
|
||||||
|
DeviceConnectionError,
|
||||||
|
InvalidAuthError,
|
||||||
|
MacAddressMismatchError,
|
||||||
|
)
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.shelly.const import (
|
from homeassistant.components.shelly.const import (
|
||||||
@ -86,6 +90,22 @@ async def test_device_connection_error(
|
|||||||
assert entry.state == ConfigEntryState.SETUP_RETRY
|
assert entry.state == ConfigEntryState.SETUP_RETRY
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("gen", [1, 2])
|
||||||
|
async def test_mac_mismatch_error(
|
||||||
|
hass: HomeAssistant, gen, mock_block_device, mock_rpc_device, monkeypatch
|
||||||
|
) -> None:
|
||||||
|
"""Test device MAC address mismatch error."""
|
||||||
|
monkeypatch.setattr(
|
||||||
|
mock_block_device, "initialize", AsyncMock(side_effect=MacAddressMismatchError)
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
mock_rpc_device, "initialize", AsyncMock(side_effect=MacAddressMismatchError)
|
||||||
|
)
|
||||||
|
|
||||||
|
entry = await init_integration(hass, gen)
|
||||||
|
assert entry.state == ConfigEntryState.SETUP_RETRY
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("gen", [1, 2])
|
@pytest.mark.parametrize("gen", [1, 2])
|
||||||
async def test_device_auth_error(
|
async def test_device_auth_error(
|
||||||
hass: HomeAssistant, gen, mock_block_device, mock_rpc_device, monkeypatch
|
hass: HomeAssistant, gen, mock_block_device, mock_rpc_device, monkeypatch
|
||||||
|
Loading…
x
Reference in New Issue
Block a user