Skip to content

Commit 41dc233

Browse files
author
Ravi Singh
committed
fix(config_flow): use unique hub hostname for zeroconf discovery name
Hubs were all showing as "TankSync Water Monitor" (and colliding as "…-2") in the Discovered list because the config flow used the mDNS service INSTANCE name — which firmware broadcasts as a constant "TankSync Water Monitor" for every hub. The mDNS HOSTNAME is unique per hub (e.g. "tanksync-5704"), so prefer it for the discovery display name — restoring the unique tanksync-XXXX label. Falls back to the instance name (disambiguated by hub_id) only when no hostname is present. Bumps version 0.11.1 -> 0.11.2.
1 parent d8cc3c9 commit 41dc233

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

custom_components/smartghar/config_flow.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,31 @@ async def async_step_zeroconf(
189189
self._discovered_host = ip_str or hostname
190190

191191
self._discovered_hub_id = hub_id
192-
# Hub friendly name not in TXT yet; fall back to mDNS instance.
193-
self._discovered_name = (
192+
# Prefer the mDNS HOSTNAME (unique per hub, e.g. "tanksync-5704") for the
193+
# display name. Firmware broadcasts a constant service INSTANCE name
194+
# ("TankSync Water Monitor"), so using discovery_info.name made every hub
195+
# look identical and collide as "…-2" — a regression from the unique
196+
# tanksync-XXXX label that the hostname still carries. Fall back to the
197+
# instance name (disambiguated by hub_id) only if no hostname is present.
198+
host_label = (discovery_info.hostname or "").rstrip(".")
199+
if host_label.lower().endswith(".local"):
200+
host_label = host_label[: -len(".local")]
201+
instance = (
194202
discovery_info.name.split(".")[0].replace("\\032", " ")
195203
if discovery_info.name
196-
else None
204+
else ""
197205
)
206+
short = hub_id[-4:] if hub_id else ""
207+
if host_label:
208+
self._discovered_name = host_label
209+
elif instance and short and short.lower() not in instance.lower():
210+
self._discovered_name = f"{instance} ({short})"
211+
elif instance:
212+
self._discovered_name = instance
213+
elif short:
214+
self._discovered_name = f"SmartGhar Hub {short}"
215+
else:
216+
self._discovered_name = None
198217

199218
await self.async_set_unique_id(hub_id)
200219
self._abort_if_unique_id_configured(updates={CONF_HOST: self._discovered_host})

custom_components/smartghar/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"requirements": [
1414
"pyserial-asyncio-fast==0.16"
1515
],
16-
"version": "0.11.1",
16+
"version": "0.11.2",
1717
"zeroconf": [
1818
"_smartghar._tcp.local."
1919
]

0 commit comments

Comments
 (0)