diff --git a/homeassistant/components/octoprint/config_flow.py b/homeassistant/components/octoprint/config_flow.py index 04efde16952..b2815b2d10f 100644 --- a/homeassistant/components/octoprint/config_flow.py +++ b/homeassistant/components/octoprint/config_flow.py @@ -6,6 +6,7 @@ import voluptuous as vol from yarl import URL from homeassistant import config_entries, data_entry_flow, exceptions +from homeassistant.components import zeroconf from homeassistant.const import ( CONF_API_KEY, CONF_HOST, @@ -138,20 +139,22 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Handle import.""" return await self.async_step_user(user_input) - async def async_step_zeroconf(self, discovery_info): + async def async_step_zeroconf( + self, discovery_info: zeroconf.ZeroconfServiceInfo + ) -> data_entry_flow.FlowResult: """Handle discovery flow.""" - uuid = discovery_info["properties"]["uuid"] + uuid = discovery_info[zeroconf.ATTR_PROPERTIES]["uuid"] await self.async_set_unique_id(uuid) self._abort_if_unique_id_configured() self.context["title_placeholders"] = { - CONF_HOST: discovery_info[CONF_HOST], + CONF_HOST: discovery_info[zeroconf.ATTR_HOST], } self.discovery_schema = _schema_with_defaults( - host=discovery_info[CONF_HOST], - port=discovery_info[CONF_PORT], - path=discovery_info["properties"][CONF_PATH], + host=discovery_info[zeroconf.ATTR_HOST], + port=discovery_info[zeroconf.ATTR_PORT], + path=discovery_info[zeroconf.ATTR_PROPERTIES][CONF_PATH], ) return await self.async_step_user() diff --git a/tests/components/octoprint/test_config_flow.py b/tests/components/octoprint/test_config_flow.py index f176e5ab288..2c8143fb78c 100644 --- a/tests/components/octoprint/test_config_flow.py +++ b/tests/components/octoprint/test_config_flow.py @@ -4,6 +4,7 @@ from unittest.mock import patch from pyoctoprintapi import ApiError, DiscoverySettings from homeassistant import config_entries, data_entry_flow +from homeassistant.components import zeroconf from homeassistant.components.octoprint.const import DOMAIN from homeassistant.core import HomeAssistant @@ -169,13 +170,12 @@ async def test_show_zerconf_form(hass: HomeAssistant) -> None: result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_ZEROCONF}, - data={ - "host": "192.168.1.123", - "port": 80, - "hostname": "example.local.", - "uuid": "83747482", - "properties": {"uuid": "83747482", "path": "/foo/"}, - }, + data=zeroconf.ZeroconfServiceInfo( + host="192.168.1.123", + port=80, + hostname="example.local.", + properties={"uuid": "83747482", "path": "/foo/"}, + ), ) assert result["type"] == "form" assert not result["errors"] @@ -485,13 +485,12 @@ async def test_duplicate_zerconf_ignored(hass: HomeAssistant) -> None: result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_ZEROCONF}, - data={ - "host": "192.168.1.123", - "port": 80, - "hostname": "example.local.", - "uuid": "83747482", - "properties": {"uuid": "83747482", "path": "/foo/"}, - }, + data=zeroconf.ZeroconfServiceInfo( + host="192.168.1.123", + port=80, + hostname="example.local.", + properties={"uuid": "83747482", "path": "/foo/"}, + ), ) assert result["type"] == "abort" assert result["reason"] == "already_configured"