|
2 | 2 | import asyncio |
3 | 3 | import faulthandler |
4 | 4 | import os |
| 5 | +import socket |
5 | 6 | import sys |
6 | 7 | from typing import Optional, Any |
| 8 | +from urllib.parse import urlparse |
7 | 9 |
|
8 | 10 | import yaml |
9 | 11 |
|
@@ -55,6 +57,20 @@ def get_name_server(raw_name_server: str): |
55 | 57 | return name_server_without_empty |
56 | 58 |
|
57 | 59 |
|
| 60 | +def log_hostname_resolution(label: str, url: str) -> None: |
| 61 | + if not url: |
| 62 | + return |
| 63 | + hostname = urlparse(url).hostname |
| 64 | + if not hostname: |
| 65 | + log(None, f'Error: could not extract hostname from {label}: {url}') |
| 66 | + return |
| 67 | + try: |
| 68 | + ip = socket.gethostbyname(hostname) |
| 69 | + log(None, f'{label} hostname {hostname} resolves to {ip}') |
| 70 | + except socket.gaierror as e: |
| 71 | + log(None, f'Error: could not resolve {label} hostname {hostname}: {e}') |
| 72 | + |
| 73 | + |
58 | 74 | def get_cache_dir(raw_cache_dir: str) -> Optional[str]: |
59 | 75 | if not raw_cache_dir: |
60 | 76 | log(None, 'No cache directory configured.') |
@@ -127,6 +143,8 @@ def main(): |
127 | 143 | 'voice': config.TTS_VOICE, |
128 | 144 | 'debug_print': config.TTS_DEBUG_PRINT, |
129 | 145 | } |
| 146 | + log_hostname_resolution('HA_BASE_URL', config.HA_BASE_URL) |
| 147 | + log_hostname_resolution('HA_WEBSOCKET_URL', config.HA_WEBSOCKET_URL) |
130 | 148 | ha_config = ha.HaConfig(config.HA_BASE_URL, config.HA_WEBSOCKET_URL, config.HA_TOKEN, tts_config_from_env, config.HA_WEBHOOK_ID, cache_dir) |
131 | 149 | if ha_config.tts_config['debug_print']: |
132 | 150 | asyncio.run(ha.print_tts_providers(ha_config)) |
|
0 commit comments