Fix yeelight binary sensor unique ID (#42562)

This commit is contained in:
Xiaonan Shen
2020-11-09 14:32:21 +07:00
committed by GitHub
parent d9d21ab05e
commit f499187835
2 changed files with 10 additions and 2 deletions

View File

@@ -34,6 +34,11 @@ class YeelightNightlightModeSensor(YeelightEntity, BinarySensorEntity):
)
)
@property
def unique_id(self) -> str:
"""Return a unique ID."""
return f"{self._unique_id}-nightlight_sensor"
@property
def name(self):
"""Return the name of the sensor."""

View File

@@ -96,7 +96,7 @@ async def test_unique_ids_device(hass: HomeAssistant):
await hass.async_block_till_done()
er = await entity_registry.async_get_registry(hass)
assert er.async_get(ENTITY_BINARY_SENSOR).unique_id == ID
assert er.async_get(ENTITY_BINARY_SENSOR).unique_id == f"{ID}-nightlight_sensor"
assert er.async_get(ENTITY_LIGHT).unique_id == ID
assert er.async_get(ENTITY_NIGHTLIGHT).unique_id == f"{ID}-nightlight"
assert er.async_get(ENTITY_AMBILIGHT).unique_id == f"{ID}-ambilight"
@@ -120,7 +120,10 @@ async def test_unique_ids_entry(hass: HomeAssistant):
await hass.async_block_till_done()
er = await entity_registry.async_get_registry(hass)
assert er.async_get(ENTITY_BINARY_SENSOR).unique_id == config_entry.entry_id
assert (
er.async_get(ENTITY_BINARY_SENSOR).unique_id
== f"{config_entry.entry_id}-nightlight_sensor"
)
assert er.async_get(ENTITY_LIGHT).unique_id == config_entry.entry_id
assert (
er.async_get(ENTITY_NIGHTLIGHT).unique_id