Skip to content

Commit

Permalink
Avoid probing ipp printers for unique_id when it is available via mdns
Browse files Browse the repository at this point in the history
We would always probe the device in the ipp flow and than
abort if it was already configured. We avoid the probe for
most printers.
  • Loading branch information
bdraco committed Sep 9, 2023
1 parent dced72f commit ec4aea8
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions homeassistant/components/ipp/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ async def async_step_zeroconf(
name = discovery_info.name.replace(f".{zctype}", "")
tls = zctype == "_ipps._tcp.local."
base_path = discovery_info.properties.get("rp", "ipp/print")

self.context.update({"title_placeholders": {"name": name}})
unique_id = discovery_info.properties.get("UUID")

self.discovery_info.update(
{
Expand All @@ -127,10 +126,24 @@ async def async_step_zeroconf(
CONF_VERIFY_SSL: False,
CONF_BASE_PATH: f"/{base_path}",
CONF_NAME: name,
CONF_UUID: discovery_info.properties.get("UUID"),
CONF_UUID: unique_id,
}
)

if unique_id:
# If we already have the unique id, try to set it now
# so we can avoid probing the device if its already
# configured or ignored
await self.async_set_unique_id(unique_id)
self._abort_if_unique_id_configured(

Check warning on line 138 in homeassistant/components/ipp/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/ipp/config_flow.py#L137-L138

Added lines #L137 - L138 were not covered by tests
updates={
CONF_HOST: self.discovery_info[CONF_HOST],
CONF_NAME: self.discovery_info[CONF_NAME],
},
)

self.context.update({"title_placeholders": {"name": name}})

try:
info = await validate_input(self.hass, self.discovery_info)
except IPPConnectionUpgradeRequired:
Expand All @@ -147,7 +160,6 @@ async def async_step_zeroconf(
_LOGGER.debug("IPP Error", exc_info=True)
return self.async_abort(reason="ipp_error")

unique_id = self.discovery_info[CONF_UUID]
if not unique_id and info[CONF_UUID]:
_LOGGER.debug(
"Printer UUID is missing from discovery info. Falling back to IPP UUID"
Expand All @@ -164,7 +176,7 @@ async def async_step_zeroconf(
"Unable to determine unique id from discovery info and IPP response"
)

if unique_id:
if unique_id and self.unique_id != unique_id:
await self.async_set_unique_id(unique_id)
self._abort_if_unique_id_configured(
updates={
Expand Down

0 comments on commit ec4aea8

Please sign in to comment.