Prevent accidental device reg override (#17136)
This commit is contained in:
parent
59d78b060f
commit
4b7f85518f
2 changed files with 59 additions and 10 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue