Skip to content

Commit

Permalink
add discovery for tube zigbee gateways
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey committed Mar 27, 2021
1 parent 67791fa commit 6ba0629
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
31 changes: 31 additions & 0 deletions homeassistant/components/zha/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/zha/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
5 changes: 4 additions & 1 deletion homeassistant/components/zha/strings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"config": {
"flow_title": "ZHA: {name}",
"step": {
"user": {
"title": "ZHA",
Expand All @@ -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%]"
}
Expand Down
5 changes: 5 additions & 0 deletions homeassistant/generated/zeroconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@
"domain": "apple_tv"
}
],
"_tube_zb_gw._tcp.local.": [
{
"domain": "zha"
}
],
"_viziocast._tcp.local.": [
{
"domain": "vizio"
Expand Down

0 comments on commit 6ba0629

Please sign in to comment.