From bb2cdbe7bca61171cb3163eaea18cbbc2e99a262 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 9 Sep 2023 09:54:40 -0500 Subject: [PATCH] Change SSDP discovery scan interval to 10 minutes (#99975) * Change SSDP discovery scan interval to 10 minutes The first version used a scan interval of 1 minute which we increased to 2 minutes because it generated too much traffic. We kept it at 2 minutes because Sonos historicly needed to get SSDP discovery to stay alive. This is no longer the case as Sonos has multiple ways to keep from going unavailable: - mDNS support was added - We now listen for SSDP alive and good bye all the time - Each incoming packet from the device keeps it alive now - We probe when we think the device might be offline This means it should no longer be necessary to have such a frequent scan which is a drag on all devices on the network since its multicast * adjust tests --- homeassistant/components/ssdp/__init__.py | 2 +- tests/components/ssdp/test_init.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/ssdp/__init__.py b/homeassistant/components/ssdp/__init__.py index 986eabf4e8280..aaffc5a157afa 100644 --- a/homeassistant/components/ssdp/__init__.py +++ b/homeassistant/components/ssdp/__init__.py @@ -63,7 +63,7 @@ UPNP_SERVER = "server" UPNP_SERVER_MIN_PORT = 40000 UPNP_SERVER_MAX_PORT = 40100 -SCAN_INTERVAL = timedelta(minutes=2) +SCAN_INTERVAL = timedelta(minutes=10) IPV4_BROADCAST = IPv4Address("255.255.255.255") diff --git a/tests/components/ssdp/test_init.py b/tests/components/ssdp/test_init.py index ed5241a42ad26..324136c011b22 100644 --- a/tests/components/ssdp/test_init.py +++ b/tests/components/ssdp/test_init.py @@ -1,5 +1,5 @@ """Test the SSDP integration.""" -from datetime import datetime, timedelta +from datetime import datetime from ipaddress import IPv4Address from unittest.mock import ANY, AsyncMock, patch @@ -447,7 +447,7 @@ async def test_start_stop_scanner(mock_source_set, hass: HomeAssistant) -> None: hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED) await hass.async_block_till_done() - async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=200)) + async_fire_time_changed(hass, dt_util.utcnow() + ssdp.SCAN_INTERVAL) await hass.async_block_till_done() assert ssdp_listener.async_start.call_count == 1 assert ssdp_listener.async_search.call_count == 4 @@ -455,7 +455,7 @@ async def test_start_stop_scanner(mock_source_set, hass: HomeAssistant) -> None: hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP) await hass.async_block_till_done() - async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=200)) + async_fire_time_changed(hass, dt_util.utcnow() + ssdp.SCAN_INTERVAL) await hass.async_block_till_done() assert ssdp_listener.async_start.call_count == 1 assert ssdp_listener.async_search.call_count == 4 @@ -785,7 +785,7 @@ async def test_ipv4_does_additional_search_for_sonos( hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED) await hass.async_block_till_done() - async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=200)) + async_fire_time_changed(hass, dt_util.utcnow() + ssdp.SCAN_INTERVAL) await hass.async_block_till_done() assert ssdp_listener.async_search.call_count == 6