Skip to content

Commit b2a3c65

Browse files
author
Ravi Singh
committed
fix(mdns+webui): pass NULL instance name + return hub_name in /api/v1/info
Two bench-discovered bugs in v6.2.0-alpha.2 that made AmbiSense show up in HA's SmartGhar integration with broken labels: netmgr.c — mDNS instance name leak: mdns_service_add("_smartghar", "_smartghar", "_tcp", ...) passed the raw service label as the friendly instance name (1st arg). Result: HA's discovery card showed "_smartghar [random]" instead of the device's name. Fix: pass NULL so the service inherits the global mdns_instance_name_set("AmbiSense") set above. webui.c — missing hub_name field: smartghar-homeassistant's SmartGharHubSensor.device_info reads info.get("hub_name") to populate HA's device-registry name. Without it, the integration falls back to "SmartGhar Hub (XXXXXX)" which is ugly. TankSync emits hub_name as the hostname ("tanksync-f6dc"); AmbiSense now does the same ("ambisense-f6dc"). Bench-tested: discovery card now reads "AmbiSense" instead of "_smartghar"; device-registry name populates as "ambisense-XXXX" matching the host. Combined with the existing product=ambisense field, the device-registry model resolves correctly to "AmbiSense Hub" via hub_model_for_product() in smartghar-homeassistant v0.7.0.
1 parent 78cf463 commit b2a3c65

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

firmware/components/netmgr/netmgr.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,12 @@ static esp_err_t bring_up_mdns(void) {
154154
char hub_id[40];
155155
snprintf(hub_id, sizeof(hub_id), "ambisense_%02x%02x%02x%02x%02x%02x",
156156
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
157-
if (mdns_service_add("_smartghar", "_smartghar", "_tcp", 80, NULL, 0) == ESP_OK) {
157+
/* First arg = friendly instance name. Pass NULL so the service
158+
* inherits `mdns_instance_name_set("AmbiSense")` above; passing
159+
* "_smartghar" (matching the service type) leaks the raw service
160+
* label into HA's discovery card as "_smartghar [random]" instead
161+
* of the device's name — which is the bug we hit on 2026-05-07. */
162+
if (mdns_service_add(NULL, "_smartghar", "_tcp", 80, NULL, 0) == ESP_OK) {
158163
mdns_txt_item_t txt[] = {
159164
{ "hub_id", hub_id },
160165
{ "product", "ambisense" },

firmware/components/webui/webui.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,13 @@ static esp_err_t handle_v1_info(httpd_req_t *req) {
901901
cJSON_AddStringToObject(r, "unique_id", hub_id); /* alias for older integration code */
902902
char host[33] = {0}; netmgr_get_hostname(host, sizeof(host));
903903
cJSON_AddStringToObject(r, "host", host);
904+
/* hub_name — what the smartghar HA integration uses as the device
905+
* registry "name" (see custom_components/smartghar/sensor.py
906+
* SmartGharHubSensor.device_info). Without this, the integration
907+
* falls back to "SmartGhar Hub (XXXXXX)" which is ugly. We use
908+
* the same hostname-as-friendly-name convention TankSync does
909+
* (e.g. "ambisense-f6dc"). */
910+
cJSON_AddStringToObject(r, "hub_name", host);
904911
char ip[24] = {0}; netmgr_get_ip(ip, sizeof(ip));
905912
cJSON_AddStringToObject(r, "ip", ip);
906913
cJSON_AddNumberToObject(r, "uptime_s", (uint32_t)(esp_timer_get_time() / 1000000));

0 commit comments

Comments
 (0)