original_docstring: Get the source ip for a target ip.
docstring: Get the source ip for a target ip.
docstring_tokens: Get the source ip for a target ip .
code: async def async_get_source_ip(
      hass: HomeAssistant, target_ip: str = PUBLIC_TARGET_IP
  ) -> str:
      """Get the source ip for a target ip."""
      adapters = await async_get_adapters(hass)
      all_ipv4s = []
      for adapter in adapters:
          if adapter["enabled"] and (ipv4s := adapter["ipv4"]):
              all_ipv4s.extend([ipv4["address"] for ipv4 in ipv4s])
  
      source_ip = util.async_get_source_ip(target_ip)
      return source_ip if source_ip in all_ipv4s else all_ipv4s[0]
code_tokens: async def async_get_source_ip ( hass : HomeAssistant , target_ip : str = PUBLIC_TARGET_IP ) -> str : adapters = await async_get_adapters ( hass ) all_ipv4s = [ ] for adapter in adapters : if adapter [ "enabled" ] and ( ipv4s := adapter [ "ipv4" ] ) : all_ipv4s . extend ( [ ipv4 [ "address" ] for ipv4 in ipv4s ] ) source_ip = util . async_get_source_ip ( target_ip ) return source_ip if source_ip in all_ipv4s else all_ipv4s [ 0 ]
short_docstring: Get the source ip for a target ip.
short_docstring_tokens: Get the source ip for a target ip .
comment: """Get the source ip for a target ip."""