mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Resolve hosts for fritzbox_callmonitor (#28761)
* Resolve hosts for fritzbox_callmonitor If the configuration supplied "host" is not an IP address, try resolving it * always use gethostbyname Instead of just checking whether it is an IP and if it isn't try to resolve; just resolve it; IPs will be returned unchanged, and hostnames will be resolved. * Catch error if the hostname cannot be resolved * Don't fallback to default host If the hostname cannot be resolved; don't try to fallback; just print the error message. * Fail setup if hostname cannot be resolved If the hostname cannot be resolved, log an error and stop the setup; no entities will be then created.
This commit is contained in:
parent
daed314585
commit
26e674b4c3
@ -60,6 +60,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up Fritz!Box call monitor sensor platform."""
|
||||
name = config.get(CONF_NAME)
|
||||
host = config.get(CONF_HOST)
|
||||
# Try to resolve a hostname; if it is already an IP, it will be returned as-is
|
||||
try:
|
||||
host = socket.gethostbyname(host)
|
||||
except socket.error:
|
||||
_LOGGER.error("Could not resolve hostname %s", host)
|
||||
return
|
||||
port = config.get(CONF_PORT)
|
||||
username = config.get(CONF_USERNAME)
|
||||
password = config.get(CONF_PASSWORD)
|
||||
|
Loading…
x
Reference in New Issue
Block a user