cli icon indicating copy to clipboard operation
cli copied to clipboard

CLI banner displays .local domain in HA URLs regardless of user-provided settings

Open njbair opened this issue 1 year ago • 4 comments

I noticed today that the welcome banner in the CLI includes two URLs to Home Assistant endpoints:

  Home Assistant URL:       http://homeassistant.local:8123
  Observer URL:             http://homeassistant.local:4357

These endpoints are hard-coded to use the .local domain, as seen here in cmd/banner.go:

https://github.com/home-assistant/cli/blob/8d8c11abf3103e752705d56da916dca2f1a4fcfb/cmd/banner.go#L167-L168

In my case, these URLs were not working because I had not enabled mDNS on my network.

Enabling mDNS would fix the issue on my network, but I think it would be better if HA reported the user-configured domain where possible, then gracefully fall back to .local if no domain is available.

Can anyone think of any downsides to this approach? Would there be any interest in merging a PR to make this change? Is this info even available to the CLI, or would I have to move upstream and change the Supervisor info API?

njbair avatar Jun 19 '24 15:06 njbair

Thank you, my network is ".lan" as provided by pi-hole. So this message from "ha banner" is missleading.

githuballrutz avatar Jul 08 '24 21:07 githuballrutz

Enabling mDNS would fix the issue on my network, but I think it would be better if HA reported the user-configured domain where possible, then gracefully fall back to .local if no domain is available.

With user configured domain you mean the domain suffix as provided through DHCP?

This might be the better option here indeed. We kinda use mDNS as fallback since most folks have mDNS enabled and almost all platform support it out-of-the box. So it is a somewhat safe fallback.

I guess the question would be how many folks have a borked router/setting where the DHCP provided suffix ends up not working :thinking: :grimacing:

Also, technically if you have two instances with the same name, your DHCP might not allocate the domain name for you. But that problem also exists on mDNS so :man_shrugging: . Maybe we could even learn if that was the case from the DHCP response? :thinking:

agners avatar Sep 05 '24 07:09 agners

Hm, yeah NetworkManager actually exposes quite some information:

DHCP4.OPTION[5]:                        domain_name = lan
...
DHCP4.OPTION[8]:                        host_name = ha-virt-proxmox-dev
...
DHCP4.OPTION[12]:                       requested_domain_name = 1

I guess if we look at this information we can say with reasonably high accuracy that ha-virt-proxmox-dev.lan will work in this case.

agners avatar Sep 05 '24 07:09 agners

I think you're right that those values would work in the case of DHCP-assigned hostname.

A full solution would also have to account for cases where HA has been configured with a static IP & hostname; and also perhaps cases where DHCP is used but the DHCP server doesn't provide all those values.

It seems like this logic is already present, as the settings dashboard gives the option to use an automatic local URL or override it:

image

Maybe the same result could be of use to the CLI as well?

njbair avatar Sep 05 '24 10:09 njbair