Use entry ID when IPP printer offers no identifier (#34316)

This commit is contained in:
Chris Talkington
2020-04-30 00:22:05 -07:00
committed by Paulus Schoutsen
parent 38f9559348
commit ade4e36da7
4 changed files with 50 additions and 19 deletions
+7 -3
View File
@@ -62,7 +62,11 @@ def load_fixture_binary(filename):
async def init_integration(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, skip_setup: bool = False,
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
skip_setup: bool = False,
uuid: str = "cfe92100-67c4-11d4-a45f-f8d027761251",
unique_id: str = "cfe92100-67c4-11d4-a45f-f8d027761251",
) -> MockConfigEntry:
"""Set up the IPP integration in Home Assistant."""
fixture = "ipp/get-printer-attributes.bin"
@@ -74,14 +78,14 @@ async def init_integration(
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="cfe92100-67c4-11d4-a45f-f8d027761251",
unique_id=unique_id,
data={
CONF_HOST: "192.168.1.31",
CONF_PORT: 631,
CONF_SSL: False,
CONF_VERIFY_SSL: True,
CONF_BASE_PATH: "/ipp/print",
CONF_UUID: "cfe92100-67c4-11d4-a45f-f8d027761251",
CONF_UUID: uuid,
},
)
+12
View File
@@ -94,3 +94,15 @@ async def test_disabled_by_default_sensors(
assert entry
assert entry.disabled
assert entry.disabled_by == "integration"
async def test_missing_entry_unique_id(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the unique_id of IPP sensor when printer is missing identifiers."""
entry = await init_integration(hass, aioclient_mock, uuid=None, unique_id=None)
registry = await hass.helpers.entity_registry.async_get_registry()
entity = registry.async_get("sensor.epson_xp_6000_series")
assert entity
assert entity.unique_id == f"{entry.entry_id}_printer"