diff --git a/homeassistant/components/rflink/__init__.py b/homeassistant/components/rflink/__init__.py index 116b24642134bef2717d53c74e715c558cae76f8..6bedea3ecd924bdb821d4e64bbf3b1046a2067e5 100644 --- a/homeassistant/components/rflink/__init__.py +++ b/homeassistant/components/rflink/__init__.py @@ -44,12 +44,14 @@ CONF_IGNORE_DEVICES = "ignore_devices" CONF_RECONNECT_INTERVAL = "reconnect_interval" CONF_SIGNAL_REPETITIONS = "signal_repetitions" CONF_WAIT_FOR_ACK = "wait_for_ack" +CONF_KEEPALIVE_IDLE = "tcp_keepalive_idle_timer" DATA_DEVICE_REGISTER = "rflink_device_register" DATA_ENTITY_LOOKUP = "rflink_entity_lookup" DATA_ENTITY_GROUP_LOOKUP = "rflink_entity_group_only_lookup" DEFAULT_RECONNECT_INTERVAL = 10 DEFAULT_SIGNAL_REPETITIONS = 1 +DEFAULT_TCP_KEEPALIVE_IDLE_TIMER = 3600 CONNECTION_TIMEOUT = 10 EVENT_BUTTON_PRESSED = "button_pressed" @@ -85,6 +87,9 @@ CONFIG_SCHEMA = vol.Schema( vol.Required(CONF_PORT): vol.Any(cv.port, cv.string), vol.Optional(CONF_HOST): cv.string, vol.Optional(CONF_WAIT_FOR_ACK, default=True): cv.boolean, + vol.Optional( + CONF_KEEPALIVE_IDLE, default=DEFAULT_TCP_KEEPALIVE_IDLE_TIMER + ): int, vol.Optional( CONF_RECONNECT_INTERVAL, default=DEFAULT_RECONNECT_INTERVAL ): int, @@ -199,6 +204,26 @@ 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, + ) + @callback def reconnect(exc=None): """Schedule reconnect after connection has been unexpectedly lost.""" @@ -223,6 +248,7 @@ async def async_setup(hass, config): connection = create_rflink_connection( port=port, host=host, + keepalive=keepalive_idle_timer, event_callback=event_callback, disconnect_callback=reconnect, loop=hass.loop, diff --git a/homeassistant/components/rflink/manifest.json b/homeassistant/components/rflink/manifest.json index cdcfe97c21918d853eff343c0d77313b997fa737..f3854a139f2d46fae7b7fe7ef3155c8ea9b6c6b4 100644 --- a/homeassistant/components/rflink/manifest.json +++ b/homeassistant/components/rflink/manifest.json @@ -2,6 +2,6 @@ "domain": "rflink", "name": "RFLink", "documentation": "https://www.home-assistant.io/integrations/rflink", - "requirements": ["rflink==0.0.55"], + "requirements": ["rflink==0.0.58"], "codeowners": [] } diff --git a/requirements_all.txt b/requirements_all.txt index 4dbee8b0a65e3d8276b5a0de336ee0397108c114..f13cd23f0c7ddaf3936bd546b34ac248e3ae0a89 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1943,7 +1943,7 @@ restrictedpython==5.1 rfk101py==0.0.1 # homeassistant.components.rflink -rflink==0.0.55 +rflink==0.0.58 # homeassistant.components.ring ring_doorbell==0.6.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 88e8dffff1cef94c6c65d7a95b6e529a61662e46..95642b36891b5b00e3aafce8d055cac708d9620a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -989,7 +989,7 @@ regenmaschine==3.0.0 restrictedpython==5.1 # homeassistant.components.rflink -rflink==0.0.55 +rflink==0.0.58 # homeassistant.components.ring ring_doorbell==0.6.2