mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Ensure bond unique ids are unique across hubs (#38496)
This commit is contained in:
parent
ce71775722
commit
542c6cce25
@ -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]:
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user