diff --git a/homeassistant/components/rflink/__init__.py b/homeassistant/components/rflink/__init__.py index 3cff3beed3c..68783c3426a 100644 --- a/homeassistant/components/rflink/__init__.py +++ b/homeassistant/components/rflink/__init__.py @@ -203,25 +203,28 @@ async def async_setup(hass, config): # TCP port when host configured, otherwise serial port port = config[DOMAIN][CONF_PORT] - # TCP KEEPALIVE will be enabled if value > 0 - keepalive_idle_timer = config[DOMAIN][CONF_KEEPALIVE_IDLE] - if keepalive_idle_timer < 0: - _LOGGER.error( - "A bogus TCP Keepalive IDLE timer was provided (%d secs), " - "default value will be used. " - "Recommended values: 60-3600 (seconds)", - keepalive_idle_timer, - ) - keepalive_idle_timer = DEFAULT_TCP_KEEPALIVE_IDLE_TIMER - elif keepalive_idle_timer == 0: - keepalive_idle_timer = None - elif keepalive_idle_timer <= 30: - _LOGGER.warning( - "A very short TCP Keepalive IDLE timer was provided (%d secs), " - "and may produce unexpected disconnections from RFlink device." - " Recommended values: 60-3600 (seconds)", - keepalive_idle_timer, - ) + keepalive_idle_timer = None + # TCP KeepAlive only if this is TCP based connection (not serial) + if host is not None: + # TCP KEEPALIVE will be enabled if value > 0 + keepalive_idle_timer = config[DOMAIN][CONF_KEEPALIVE_IDLE] + if keepalive_idle_timer < 0: + _LOGGER.error( + "A bogus TCP Keepalive IDLE timer was provided (%d secs), " + "it will be disabled. " + "Recommended values: 60-3600 (seconds)", + keepalive_idle_timer, + ) + keepalive_idle_timer = None + elif keepalive_idle_timer == 0: + keepalive_idle_timer = None + elif keepalive_idle_timer <= 30: + _LOGGER.warning( + "A very short TCP Keepalive IDLE timer was provided (%d secs) " + "and may produce unexpected disconnections from RFlink device." + " Recommended values: 60-3600 (seconds)", + keepalive_idle_timer, + ) @callback def reconnect(exc=None):