diff --git a/homeassistant/components/zha/config_flow.py b/homeassistant/components/zha/config_flow.py index 9835a9a393738..3fae4efc779f6 100644 --- a/homeassistant/components/zha/config_flow.py +++ b/homeassistant/components/zha/config_flow.py @@ -9,6 +9,8 @@ from zigpy.config import CONF_DEVICE, CONF_DEVICE_PATH from homeassistant import config_entries +from homeassistant.const import CONF_NAME +from homeassistant.helpers.typing import DiscoveryInfoType from .core.const import ( # pylint:disable=unused-import CONF_BAUDRATE, @@ -91,6 +93,31 @@ async def async_step_pick_radio(self, user_input=None): data_schema=vol.Schema(schema), ) + async def async_step_zeroconf(self, discovery_info: DiscoveryInfoType): + """Handle zeroconf discovery.""" + # Hostname is format: livingroom.local. + local_name = discovery_info["hostname"][:-1] + node_name = local_name[: -len(".local")] + + # Check if already configured + if self._async_current_entries(): + return self.async_abort(reason="single_instance_allowed") + + await self.async_set_unique_id(node_name) + self._abort_if_unique_id_configured() + + # pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167 + self.context["title_placeholders"] = { + CONF_NAME: node_name, + } + + self._device_path = f"socket://{local_name}:6638" + self._radio_type = ( + RadioType.ezsp.name if "efr32" in local_name else RadioType.znp.name + ) + + return await self.async_step_port_config() + async def async_step_port_config(self, user_input=None): """Enter port settings specific for this type of radio.""" errors = {} @@ -118,9 +145,13 @@ async def async_step_port_config(self, user_input=None): if isinstance(radio_schema, vol.Schema): radio_schema = radio_schema.schema + # pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167 + source = self.context.get("source") for param, value in radio_schema.items(): if param in SUPPORTED_PORT_SETTINGS: schema[param] = value + if source == config_entries.SOURCE_ZEROCONF and param == CONF_BAUDRATE: + schema[param] = 115200 return self.async_show_form( step_id="port_config", diff --git a/homeassistant/components/zha/manifest.json b/homeassistant/components/zha/manifest.json index 6493bd138bf62..e77c923561175 100644 --- a/homeassistant/components/zha/manifest.json +++ b/homeassistant/components/zha/manifest.json @@ -15,5 +15,7 @@ "zigpy-zigate==0.7.3", "zigpy-znp==0.4.0" ], - "codeowners": ["@dmulcahey", "@adminiuga"] + "codeowners": ["@dmulcahey", "@adminiuga"], + "zeroconf": [{ "type": "_tube_zb_gw._tcp.local." }], + "after_dependencies": ["zeroconf"] } diff --git a/homeassistant/components/zha/strings.json b/homeassistant/components/zha/strings.json index 93b5cd7ccf5d6..550fad3c2c588 100644 --- a/homeassistant/components/zha/strings.json +++ b/homeassistant/components/zha/strings.json @@ -1,5 +1,6 @@ { "config": { + "flow_title": "ZHA: {name}", "step": { "user": { "title": "ZHA", @@ -21,7 +22,9 @@ } } }, - "error": { "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]" }, + "error": { + "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]" + }, "abort": { "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" } diff --git a/homeassistant/generated/zeroconf.py b/homeassistant/generated/zeroconf.py index d3a976e78ea98..48062e7ec8a49 100644 --- a/homeassistant/generated/zeroconf.py +++ b/homeassistant/generated/zeroconf.py @@ -155,6 +155,11 @@ "domain": "apple_tv" } ], + "_tube_zb_gw._tcp.local.": [ + { + "domain": "zha" + } + ], "_viziocast._tcp.local.": [ { "domain": "vizio"