File tree Expand file tree Collapse file tree 1 file changed +21
-5
lines changed
custom_components/vserver_ssh_stats Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -70,12 +70,28 @@ async def _get_discovered_hosts(self) -> list[str]:
7070 """Return a list of hosts with an open SSH port."""
7171 if self ._discovered_host :
7272 return [self ._discovered_host ]
73- network = guess_local_network ()
73+
74+ networks : list [str ] = []
7475 try :
75- return await discover_ssh_hosts (network )
76- except OSError :
77- # If discovery fails, fall back to manual entry
78- return []
76+ # Try to use Home Assistant's network helper to get all local
77+ # IPv4 addresses (this includes the host network when running
78+ # inside the supervised container).
79+ from homeassistant .helpers .network import async_get_ipv4_addresses
80+
81+ addresses = await async_get_ipv4_addresses (self .hass , include_loopback = False )
82+ networks = [f"{ addr } /24" for addr in addresses ]
83+ except Exception : # pragma: no cover - helper not available
84+ networks = [guess_local_network ()]
85+
86+ hosts : set [str ] = set ()
87+ for network in networks :
88+ try :
89+ hosts .update (await discover_ssh_hosts (network ))
90+ except OSError :
91+ # If discovery for a network fails, skip it and continue
92+ continue
93+
94+ return sorted (hosts )
7995
8096 def _build_schema (self , hosts : list [str ]) -> vol .Schema :
8197 """Create the data schema for the form using *hosts* if provided."""
You can’t perform that action at this time.
0 commit comments