mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
fix possible mac collision in enphase_envoy (#145549)
* fix possible mac collision in enphase_envoy * remove redundant device registry async_get
This commit is contained in:
parent
0f27d0bf4a
commit
9b90ed04e5
@ -180,9 +180,15 @@ class EnphaseUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
device_registry.async_update_device(
|
device_registry.async_get_or_create(
|
||||||
device_id=envoy_device.id,
|
config_entry_id=self.config_entry.entry_id,
|
||||||
new_connections={connection},
|
identifiers={
|
||||||
|
(
|
||||||
|
DOMAIN,
|
||||||
|
self.envoy_serial_number,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
connections={connection},
|
||||||
)
|
)
|
||||||
_LOGGER.debug("added connection: %s to %s", connection, self.name)
|
_LOGGER.debug("added connection: %s to %s", connection, self.name)
|
||||||
|
|
||||||
|
@ -510,7 +510,6 @@ async def test_coordinator_interface_information_no_device(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# update device to force no device found in mac verification
|
# update device to force no device found in mac verification
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
envoy_device = device_registry.async_get_device(
|
envoy_device = device_registry.async_get_device(
|
||||||
identifiers={
|
identifiers={
|
||||||
(
|
(
|
||||||
@ -531,3 +530,60 @@ async def test_coordinator_interface_information_no_device(
|
|||||||
|
|
||||||
# verify no device found message in log
|
# verify no device found message in log
|
||||||
assert "No envoy device found in device registry" in caplog.text
|
assert "No envoy device found in device registry" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
@respx.mock
|
||||||
|
async def test_coordinator_interface_information_mac_also_in_other_device(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
mock_envoy: AsyncMock,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
) -> None:
|
||||||
|
"""Test coordinator interface mac verification with MAC also in other existing device."""
|
||||||
|
await setup_integration(hass, config_entry)
|
||||||
|
|
||||||
|
caplog.set_level(logging.DEBUG)
|
||||||
|
logging.getLogger("homeassistant.components.enphase_envoy.coordinator").setLevel(
|
||||||
|
logging.DEBUG
|
||||||
|
)
|
||||||
|
|
||||||
|
# add existing device with MAC and sparsely populated i.e. unifi that found envoy
|
||||||
|
other_config_entry = MockConfigEntry(domain="test", data={})
|
||||||
|
other_config_entry.add_to_hass(hass)
|
||||||
|
device_registry.async_get_or_create(
|
||||||
|
config_entry_id=other_config_entry.entry_id,
|
||||||
|
connections={(dr.CONNECTION_NETWORK_MAC, "00:11:22:33:44:55")},
|
||||||
|
manufacturer="Enphase Energy",
|
||||||
|
)
|
||||||
|
|
||||||
|
envoy_device = device_registry.async_get_device(
|
||||||
|
identifiers={
|
||||||
|
(
|
||||||
|
DOMAIN,
|
||||||
|
mock_envoy.serial_number,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assert envoy_device
|
||||||
|
|
||||||
|
# move time forward so interface information is fetched
|
||||||
|
freezer.tick(MAC_VERIFICATION_DELAY)
|
||||||
|
async_fire_time_changed(hass)
|
||||||
|
await hass.async_block_till_done(wait_background_tasks=True)
|
||||||
|
|
||||||
|
# verify mac was added
|
||||||
|
assert "added connection: ('mac', '00:11:22:33:44:55') to Envoy 1234" in caplog.text
|
||||||
|
|
||||||
|
# verify connection is now in envoy device
|
||||||
|
envoy_device_refetched = device_registry.async_get(envoy_device.id)
|
||||||
|
assert envoy_device_refetched
|
||||||
|
assert envoy_device_refetched.name == "Envoy 1234"
|
||||||
|
assert envoy_device_refetched.serial_number == "1234"
|
||||||
|
assert envoy_device_refetched.connections == {
|
||||||
|
(
|
||||||
|
dr.CONNECTION_NETWORK_MAC,
|
||||||
|
"00:11:22:33:44:55",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user