mirror of
https://github.com/home-assistant/core.git
synced 2025-06-05 05:37:04 +00:00
Avoid validation of ESPHome MAC when discovered entry is ignored or unchanged (#144071)
fixes #144033 fixes #143991
This commit is contained in:
parent
851779e7ad
commit
eba0daa2e9
@ -22,6 +22,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import (
|
||||||
|
SOURCE_IGNORE,
|
||||||
SOURCE_REAUTH,
|
SOURCE_REAUTH,
|
||||||
SOURCE_RECONFIGURE,
|
SOURCE_RECONFIGURE,
|
||||||
ConfigEntry,
|
ConfigEntry,
|
||||||
@ -31,6 +32,7 @@ from homeassistant.config_entries import (
|
|||||||
)
|
)
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.data_entry_flow import AbortFlow
|
||||||
from homeassistant.helpers.device_registry import format_mac
|
from homeassistant.helpers.device_registry import format_mac
|
||||||
from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo
|
from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo
|
||||||
from homeassistant.helpers.service_info.hassio import HassioServiceInfo
|
from homeassistant.helpers.service_info.hassio import HassioServiceInfo
|
||||||
@ -302,7 +304,15 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
if entry.source == SOURCE_IGNORE:
|
||||||
|
# Don't call _fetch_device_info() for ignored entries
|
||||||
|
raise AbortFlow("already_configured")
|
||||||
|
configured_host: str | None = entry.data.get(CONF_HOST)
|
||||||
configured_port: int | None = entry.data.get(CONF_PORT)
|
configured_port: int | None = entry.data.get(CONF_PORT)
|
||||||
|
if configured_host == host and configured_port == port:
|
||||||
|
# Don't probe to verify the mac is correct since
|
||||||
|
# the host and port matches.
|
||||||
|
raise AbortFlow("already_configured")
|
||||||
configured_psk: str | None = entry.data.get(CONF_NOISE_PSK)
|
configured_psk: str | None = entry.data.get(CONF_NOISE_PSK)
|
||||||
await self._fetch_device_info(host, port or configured_port, configured_psk)
|
await self._fetch_device_info(host, port or configured_port, configured_psk)
|
||||||
updates: dict[str, Any] = {}
|
updates: dict[str, Any] = {}
|
||||||
|
@ -27,7 +27,7 @@ from homeassistant.components.esphome.const import (
|
|||||||
DEFAULT_NEW_CONFIG_ALLOW_ALLOW_SERVICE_CALLS,
|
DEFAULT_NEW_CONFIG_ALLOW_ALLOW_SERVICE_CALLS,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigFlowResult
|
from homeassistant.config_entries import SOURCE_IGNORE, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
@ -747,6 +747,35 @@ async def test_discovery_already_configured(hass: HomeAssistant) -> None:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_client", "mock_setup_entry", "mock_zeroconf")
|
||||||
|
async def test_discovery_ignored(hass: HomeAssistant) -> None:
|
||||||
|
"""Test discovery does not probe and ignored entry."""
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
data={CONF_HOST: "test8266.local", CONF_PORT: 6053, CONF_PASSWORD: ""},
|
||||||
|
unique_id="11:22:33:44:55:aa",
|
||||||
|
source=SOURCE_IGNORE,
|
||||||
|
)
|
||||||
|
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
service_info = ZeroconfServiceInfo(
|
||||||
|
ip_address=ip_address("192.168.43.183"),
|
||||||
|
ip_addresses=[ip_address("192.168.43.183")],
|
||||||
|
hostname="test8266.local.",
|
||||||
|
name="mock_name",
|
||||||
|
port=6053,
|
||||||
|
properties={"mac": "1122334455aa"},
|
||||||
|
type="mock_type",
|
||||||
|
)
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_client", "mock_setup_entry", "mock_zeroconf")
|
@pytest.mark.usefixtures("mock_client", "mock_setup_entry", "mock_zeroconf")
|
||||||
async def test_discovery_duplicate_data(hass: HomeAssistant) -> None:
|
async def test_discovery_duplicate_data(hass: HomeAssistant) -> None:
|
||||||
"""Test discovery aborts if same mDNS packet arrives."""
|
"""Test discovery aborts if same mDNS packet arrives."""
|
||||||
@ -786,8 +815,8 @@ async def test_discovery_updates_unique_id(hass: HomeAssistant) -> None:
|
|||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
service_info = ZeroconfServiceInfo(
|
service_info = ZeroconfServiceInfo(
|
||||||
ip_address=ip_address("192.168.43.183"),
|
ip_address=ip_address("192.168.43.184"),
|
||||||
ip_addresses=[ip_address("192.168.43.183")],
|
ip_addresses=[ip_address("192.168.43.184")],
|
||||||
hostname="test8266.local.",
|
hostname="test8266.local.",
|
||||||
name="mock_name",
|
name="mock_name",
|
||||||
port=6053,
|
port=6053,
|
||||||
@ -806,9 +835,40 @@ async def test_discovery_updates_unique_id(hass: HomeAssistant) -> None:
|
|||||||
"mac": "11:22:33:44:55:aa",
|
"mac": "11:22:33:44:55:aa",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert entry.data[CONF_HOST] == "192.168.43.184"
|
||||||
assert entry.unique_id == "11:22:33:44:55:aa"
|
assert entry.unique_id == "11:22:33:44:55:aa"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_client", "mock_setup_entry", "mock_zeroconf")
|
||||||
|
async def test_discovery_abort_without_update_same_host_port(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
|
"""Test discovery aborts without update when hsot and port are the same."""
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
data={CONF_HOST: "192.168.43.183", CONF_PORT: 6053, CONF_PASSWORD: ""},
|
||||||
|
unique_id="11:22:33:44:55:aa",
|
||||||
|
)
|
||||||
|
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
service_info = ZeroconfServiceInfo(
|
||||||
|
ip_address=ip_address("192.168.43.183"),
|
||||||
|
ip_addresses=[ip_address("192.168.43.183")],
|
||||||
|
hostname="test8266.local.",
|
||||||
|
name="mock_name",
|
||||||
|
port=6053,
|
||||||
|
properties={"address": "test8266.local", "mac": "1122334455aa"},
|
||||||
|
type="mock_type",
|
||||||
|
)
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_setup_entry", "mock_zeroconf")
|
@pytest.mark.usefixtures("mock_setup_entry", "mock_zeroconf")
|
||||||
async def test_user_requires_psk(hass: HomeAssistant, mock_client: APIClient) -> None:
|
async def test_user_requires_psk(hass: HomeAssistant, mock_client: APIClient) -> None:
|
||||||
"""Test user step with requiring encryption key."""
|
"""Test user step with requiring encryption key."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user