Skip to content

Commit

Permalink
discovery_info['hostname'] will be failed soon, and instead of discov…
Browse files Browse the repository at this point in the history
…ery_info.hostname
  • Loading branch information
niceboy committed Dec 12, 2021
1 parent 80003b7 commit f700bbe
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions custom_components/aqara_gateway/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,22 @@ async def async_step_discovery_confirm(self, user_input=None):
async def async_step_zeroconf(self, discovery_info: DiscoveryInfoType):
"""Handle zeroconf discovery."""
# Hostname is format: _aqara._tcp.local., _aqara-setup._tcp.local.
local_name = discovery_info["hostname"][:-1]
node_name = local_name[: -len(".local")]
address = discovery_info["properties"].get(
"address", discovery_info["host"])
model = discovery_info["properties"].get("md", "unknow")
fwversion = discovery_info["properties"].get("fw", "unknow")
fwcloud = discovery_info["properties"].get("cl", "unknow")
if getattr(discovery_info, "hostname"):
local_name = discovery_info.hostname[:-1]
node_name = local_name[: -len(".local")]
address = discovery_info.properties.get(
"address", discovery_info.host)
model = discovery_info.properties.get("md", "unknow")
fwversion = discovery_info.properties.get("fw", "unknow")
fwcloud = discovery_info.properties.get("cl", "unknow")
else:
local_name = discovery_info["hostname"][:-1]
node_name = local_name[: -len(".local")]
address = discovery_info["properties"].get(
"address", discovery_info[CONF_HOST])
model = discovery_info["properties"].get("md", "unknow")
fwversion = discovery_info["properties"].get("fw", "unknow")
fwcloud = discovery_info["properties"].get("cl", "unknow")
self._device_info = (
f"Name: {node_name}\n"
f"Model: {model}\n"
Expand All @@ -170,7 +179,10 @@ async def async_step_zeroconf(self, discovery_info: DiscoveryInfoType):
f"Cloud: {fwcloud}"
)

self._host = discovery_info[CONF_HOST]
if getattr(discovery_info, "hostname"):
self._host = discovery_info.hostname
else:
self._host = discovery_info[CONF_HOST]
self._name = node_name
self._password = ''
self._token = ''
Expand All @@ -180,13 +192,13 @@ async def async_step_zeroconf(self, discovery_info: DiscoveryInfoType):
already_configured = False
if CONF_HOST in entry.data and entry.data[CONF_HOST] in [
address,
discovery_info[CONF_HOST],
self._host,
]:
# Is this address or IP address already configured?
already_configured = True
elif CONF_HOST in entry.options and entry.options[CONF_HOST] in [
address,
discovery_info[CONF_HOST],
self._host,
]:
# Is this address or IP address already configured?
already_configured = True
Expand All @@ -200,7 +212,7 @@ async def async_step_zeroconf(self, discovery_info: DiscoveryInfoType):
await self.async_set_unique_id(node_name)

self._abort_if_unique_id_configured(
updates={CONF_HOST: discovery_info[CONF_HOST]}
updates={CONF_HOST: self._host}
)

if (fwcloud == "miot" and
Expand Down

0 comments on commit f700bbe

Please sign in to comment.