mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
ESPHome: Use MAC as unique ID (#83741)
* ESPHome: Use MAC as unique ID * Normalize incoming zeroconf/dhcp macs * Update comment * Test ESPHome without mac in zeroconf * Use format_mac * Remove unique ID index from DomainData
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
"""esphome session fixtures."""
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from aioesphomeapi import APIClient
|
||||
import pytest
|
||||
from zeroconf import Zeroconf
|
||||
|
||||
from homeassistant.components.esphome import CONF_NOISE_PSK, DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT
|
||||
@@ -25,7 +31,7 @@ def mock_config_entry() -> MockConfigEntry:
|
||||
CONF_PASSWORD: "pwd",
|
||||
CONF_NOISE_PSK: "12345678123456781234567812345678",
|
||||
},
|
||||
unique_id="esphome-device",
|
||||
unique_id="11:22:33:44:55:aa",
|
||||
)
|
||||
|
||||
|
||||
@@ -40,3 +46,37 @@ async def init_integration(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return mock_config_entry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_client():
|
||||
"""Mock APIClient."""
|
||||
mock_client = Mock(spec=APIClient)
|
||||
|
||||
def mock_constructor(
|
||||
address: str,
|
||||
port: int,
|
||||
password: str | None,
|
||||
*,
|
||||
client_info: str = "aioesphomeapi",
|
||||
keepalive: float = 15.0,
|
||||
zeroconf_instance: Zeroconf = None,
|
||||
noise_psk: str | None = None,
|
||||
expected_name: str | None = None,
|
||||
):
|
||||
"""Fake the client constructor."""
|
||||
mock_client.host = address
|
||||
mock_client.port = port
|
||||
mock_client.password = password
|
||||
mock_client.zeroconf_instance = zeroconf_instance
|
||||
mock_client.noise_psk = noise_psk
|
||||
return mock_client
|
||||
|
||||
mock_client.side_effect = mock_constructor
|
||||
mock_client.connect = AsyncMock()
|
||||
mock_client.disconnect = AsyncMock()
|
||||
|
||||
with patch("homeassistant.components.esphome.APIClient", mock_client), patch(
|
||||
"homeassistant.components.esphome.config_flow.APIClient", mock_client
|
||||
):
|
||||
yield mock_client
|
||||
|
||||
Reference in New Issue
Block a user