mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Prevent accidental device reg override (#17136)
This commit is contained in:
@@ -728,3 +728,45 @@ async def test_device_info_called(hass):
|
||||
assert device.name == 'test-name'
|
||||
assert device.sw_version == 'test-sw'
|
||||
assert device.hub_device_id == hub.id
|
||||
|
||||
|
||||
async def test_device_info_not_overrides(hass):
|
||||
"""Test device info is forwarded correctly."""
|
||||
registry = await hass.helpers.device_registry.async_get_registry()
|
||||
device = registry.async_get_or_create(
|
||||
config_entry_id='bla',
|
||||
connections={('mac', 'abcd')},
|
||||
manufacturer='test-manufacturer',
|
||||
model='test-model'
|
||||
)
|
||||
|
||||
assert device.manufacturer == 'test-manufacturer'
|
||||
assert device.model == 'test-model'
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Mock setup entry method."""
|
||||
async_add_entities([
|
||||
MockEntity(unique_id='qwer', device_info={
|
||||
'connections': {('mac', 'abcd')},
|
||||
}),
|
||||
])
|
||||
return True
|
||||
|
||||
platform = MockPlatform(
|
||||
async_setup_entry=async_setup_entry
|
||||
)
|
||||
config_entry = MockConfigEntry(entry_id='super-mock-id')
|
||||
entity_platform = MockEntityPlatform(
|
||||
hass,
|
||||
platform_name=config_entry.domain,
|
||||
platform=platform
|
||||
)
|
||||
|
||||
assert await entity_platform.async_setup_entry(config_entry)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device2 = registry.async_get_device(set(), {('mac', 'abcd')})
|
||||
assert device2 is not None
|
||||
assert device.id == device2.id
|
||||
assert device2.manufacturer == 'test-manufacturer'
|
||||
assert device2.model == 'test-model'
|
||||
|
||||
Reference in New Issue
Block a user