From 26e674b4c30bf2d791c638b5aaf2ddd3cd6f672e Mon Sep 17 00:00:00 2001 From: guillempages Date: Thu, 28 Nov 2019 21:14:20 +0100 Subject: [PATCH] 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. --- homeassistant/components/fritzbox_callmonitor/sensor.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/homeassistant/components/fritzbox_callmonitor/sensor.py b/homeassistant/components/fritzbox_callmonitor/sensor.py index b1d601ce382..600420db859 100644 --- a/homeassistant/components/fritzbox_callmonitor/sensor.py +++ b/homeassistant/components/fritzbox_callmonitor/sensor.py @@ -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)