mirror of
https://github.com/home-assistant/core.git
synced 2026-09-27 18:08:37 -04:00
Fix Magic Home devices with multiple network interfaces (#68029)
This commit is contained in:
@@ -39,6 +39,8 @@ MODEL_NUM = 0x35
|
||||
MODEL = "AK001-ZJ2149"
|
||||
MODEL_DESCRIPTION = "Bulb RGBCW"
|
||||
MAC_ADDRESS = "aa:bb:cc:dd:ee:ff"
|
||||
MAC_ADDRESS_ONE_OFF = "aa:bb:cc:dd:ee:fe"
|
||||
|
||||
FLUX_MAC_ADDRESS = "AABBCCDDEEFF"
|
||||
SHORT_MAC_ADDRESS = "DDEEFF"
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ from . import (
|
||||
FLUX_DISCOVERY_PARTIAL,
|
||||
IP_ADDRESS,
|
||||
MAC_ADDRESS,
|
||||
MAC_ADDRESS_ONE_OFF,
|
||||
MODEL,
|
||||
MODEL_DESCRIPTION,
|
||||
MODEL_NUM,
|
||||
@@ -546,6 +547,7 @@ async def test_discovered_by_dhcp_partial_udp_response_fallback_tcp(hass):
|
||||
CONF_MODEL_NUM: MODEL_NUM,
|
||||
CONF_MODEL_DESCRIPTION: MODEL_DESCRIPTION,
|
||||
}
|
||||
assert result2["title"] == "Bulb RGBCW DDEEFF"
|
||||
assert mock_async_setup.called
|
||||
assert mock_async_setup_entry.called
|
||||
|
||||
@@ -589,6 +591,46 @@ async def test_discovered_by_dhcp_or_discovery_adds_missing_unique_id(
|
||||
assert config_entry.unique_id == MAC_ADDRESS
|
||||
|
||||
|
||||
async def test_mac_address_off_by_one_updated_via_discovery(hass):
|
||||
"""Test the mac address is updated when its off by one from integration discovery."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_HOST: IP_ADDRESS}, unique_id=MAC_ADDRESS_ONE_OFF
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with _patch_discovery(), _patch_wifibulb():
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=FLUX_DISCOVERY,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
assert config_entry.unique_id == MAC_ADDRESS
|
||||
|
||||
|
||||
async def test_mac_address_off_by_one_not_updated_from_dhcp(hass):
|
||||
"""Test the mac address is NOT updated when its off by one from dhcp discovery."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_HOST: IP_ADDRESS}, unique_id=MAC_ADDRESS_ONE_OFF
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with _patch_discovery(), _patch_wifibulb():
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_DHCP}, data=DHCP_DISCOVERY
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
assert config_entry.unique_id == MAC_ADDRESS_ONE_OFF
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"source, data",
|
||||
[
|
||||
|
||||
@@ -26,6 +26,7 @@ from . import (
|
||||
FLUX_DISCOVERY_PARTIAL,
|
||||
IP_ADDRESS,
|
||||
MAC_ADDRESS,
|
||||
MAC_ADDRESS_ONE_OFF,
|
||||
_mocked_bulb,
|
||||
_patch_discovery,
|
||||
_patch_wifibulb,
|
||||
@@ -82,7 +83,9 @@ async def test_configuring_flux_led_causes_discovery_multiple_addresses(
|
||||
|
||||
async def test_config_entry_reload(hass: HomeAssistant) -> None:
|
||||
"""Test that a config entry can be reloaded."""
|
||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=MAC_ADDRESS)
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_HOST: IP_ADDRESS}, unique_id=MAC_ADDRESS
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
with _patch_discovery(), _patch_wifibulb():
|
||||
await async_setup_component(hass, flux_led.DOMAIN, {flux_led.DOMAIN: {}})
|
||||
@@ -126,11 +129,11 @@ async def test_config_entry_fills_unique_id_with_directed_discovery(
|
||||
# Only return discovery results when doing directed discovery
|
||||
nonlocal last_address
|
||||
last_address = address
|
||||
return [FLUX_DISCOVERY] if address == IP_ADDRESS else []
|
||||
return [discovery] if address == IP_ADDRESS else []
|
||||
|
||||
def _mock_getBulbInfo(*args, **kwargs):
|
||||
nonlocal last_address
|
||||
return [FLUX_DISCOVERY] if last_address == IP_ADDRESS else []
|
||||
return [discovery] if last_address == IP_ADDRESS else []
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.flux_led.discovery.AIOBulbScanner.async_scan",
|
||||
@@ -149,7 +152,9 @@ async def test_config_entry_fills_unique_id_with_directed_discovery(
|
||||
|
||||
async def test_time_sync_startup_and_next_day(hass: HomeAssistant) -> None:
|
||||
"""Test that time is synced on startup and next day."""
|
||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=MAC_ADDRESS)
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_HOST: IP_ADDRESS}, unique_id=MAC_ADDRESS
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
bulb = _mocked_bulb()
|
||||
with _patch_discovery(), _patch_wifibulb(device=bulb):
|
||||
@@ -204,3 +209,72 @@ async def test_unique_id_migrate_when_mac_discovered(hass: HomeAssistant) -> Non
|
||||
entity_registry.async_get("switch.bulb_rgbcw_ddeeff_remote_access").unique_id
|
||||
== f"{config_entry.unique_id}_remote_access"
|
||||
)
|
||||
|
||||
|
||||
async def test_unique_id_migrate_when_mac_discovered_via_discovery(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test unique id migrated when mac discovered via discovery and the mac address from dhcp was one off."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_REMOTE_ACCESS_HOST: "any",
|
||||
CONF_REMOTE_ACCESS_ENABLED: True,
|
||||
CONF_REMOTE_ACCESS_PORT: 1234,
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_NAME: DEFAULT_ENTRY_TITLE,
|
||||
},
|
||||
unique_id=MAC_ADDRESS_ONE_OFF,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
bulb = _mocked_bulb()
|
||||
with _patch_discovery(no_device=True), _patch_wifibulb(device=bulb):
|
||||
await async_setup_component(hass, flux_led.DOMAIN, {flux_led.DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.unique_id == MAC_ADDRESS_ONE_OFF
|
||||
entity_registry = er.async_get(hass)
|
||||
assert (
|
||||
entity_registry.async_get("light.bulb_rgbcw_ddeeff").unique_id
|
||||
== MAC_ADDRESS_ONE_OFF
|
||||
)
|
||||
assert (
|
||||
entity_registry.async_get("switch.bulb_rgbcw_ddeeff_remote_access").unique_id
|
||||
== f"{MAC_ADDRESS_ONE_OFF}_remote_access"
|
||||
)
|
||||
|
||||
for _ in range(2):
|
||||
with _patch_discovery(), _patch_wifibulb(device=bulb):
|
||||
await hass.config_entries.async_reload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
entity_registry.async_get("light.bulb_rgbcw_ddeeff").unique_id
|
||||
== config_entry.unique_id
|
||||
)
|
||||
assert (
|
||||
entity_registry.async_get(
|
||||
"switch.bulb_rgbcw_ddeeff_remote_access"
|
||||
).unique_id
|
||||
== f"{config_entry.unique_id}_remote_access"
|
||||
)
|
||||
|
||||
|
||||
async def test_name_removed_when_it_matches_entry_title(hass: HomeAssistant) -> None:
|
||||
"""Test name is removed when it matches the entry title."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_REMOTE_ACCESS_HOST: "any",
|
||||
CONF_REMOTE_ACCESS_ENABLED: True,
|
||||
CONF_REMOTE_ACCESS_PORT: 1234,
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_NAME: DEFAULT_ENTRY_TITLE,
|
||||
},
|
||||
title=DEFAULT_ENTRY_TITLE,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
with _patch_discovery(), _patch_wifibulb():
|
||||
await async_setup_component(hass, flux_led.DOMAIN, {flux_led.DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
assert CONF_NAME not in config_entry.data
|
||||
|
||||
Reference in New Issue
Block a user