Ensure bond unique ids are unique across hubs (#38496)

This commit is contained in:
Eugene Prystupa 2020-08-02 22:50:03 -04:00 committed by GitHub
parent ce71775722
commit 542c6cce25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 10 deletions

View File

@ -27,7 +27,9 @@ class BondEntity(Entity):
@property
def unique_id(self) -> Optional[str]:
"""Get unique ID for the entity."""
return self._device.device_id
hub_id = self._hub.bond_id
device_id = self._device.device_id
return f"{hub_id}_{device_id}"
@property
def name(self) -> Optional[str]:

View File

@ -58,7 +58,7 @@ async def setup_platform(
"""Set up the specified Bond platform."""
mock_entry = MockConfigEntry(
domain=BOND_DOMAIN,
data={CONF_HOST: "1.1.1.1", CONF_ACCESS_TOKEN: "test-token"},
data={CONF_HOST: "some host", CONF_ACCESS_TOKEN: "test-token"},
)
mock_entry.add_to_hass(hass)

View File

@ -34,10 +34,17 @@ def shades(name: str):
async def test_entity_registry(hass: core.HomeAssistant):
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, COVER_DOMAIN, shades("name-1"))
await setup_platform(
hass,
COVER_DOMAIN,
shades("name-1"),
bond_version={"bondid": "test-hub-id"},
bond_device_id="test-device-id",
)
registry: EntityRegistry = await hass.helpers.entity_registry.async_get_registry()
assert [key for key in registry.entities] == ["cover.name_1"]
entity = registry.entities["cover.name_1"]
assert entity.unique_id == "test-hub-id_test-device-id"
async def test_open_cover(hass: core.HomeAssistant):

View File

@ -52,10 +52,17 @@ async def turn_fan_on(
async def test_entity_registry(hass: core.HomeAssistant):
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, FAN_DOMAIN, ceiling_fan("name-1"))
await setup_platform(
hass,
FAN_DOMAIN,
ceiling_fan("name-1"),
bond_version={"bondid": "test-hub-id"},
bond_device_id="test-device-id",
)
registry: EntityRegistry = await hass.helpers.entity_registry.async_get_registry()
assert [key for key in registry.entities] == ["fan.name_1"]
entity = registry.entities["fan.name_1"]
assert entity.unique_id == "test-hub-id_test-device-id"
async def test_non_standard_speed_list(hass: core.HomeAssistant):

View File

@ -57,10 +57,17 @@ def fireplace(name: str):
async def test_entity_registry(hass: core.HomeAssistant):
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, LIGHT_DOMAIN, ceiling_fan("name-1"))
await setup_platform(
hass,
LIGHT_DOMAIN,
ceiling_fan("name-1"),
bond_version={"bondid": "test-hub-id"},
bond_device_id="test-device-id",
)
registry: EntityRegistry = await hass.helpers.entity_registry.async_get_registry()
assert [key for key in registry.entities] == ["light.name_1"]
entity = registry.entities["light.name_1"]
assert entity.unique_id == "test-hub-id_test-device-id"
async def test_sbb_trust_state(hass: core.HomeAssistant):

View File

@ -29,10 +29,17 @@ def generic_device(name: str):
async def test_entity_registry(hass: core.HomeAssistant):
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, SWITCH_DOMAIN, generic_device("name-1"))
await setup_platform(
hass,
SWITCH_DOMAIN,
generic_device("name-1"),
bond_version={"bondid": "test-hub-id"},
bond_device_id="test-device-id",
)
registry: EntityRegistry = await hass.helpers.entity_registry.async_get_registry()
assert [key for key in registry.entities] == ["switch.name_1"]
entity = registry.entities["switch.name_1"]
assert entity.unique_id == "test-hub-id_test-device-id"
async def test_turn_on_switch(hass: core.HomeAssistant):