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
This commit is contained in:
J. Nick Koston 2023-09-09 09:54:40 -05:00 committed by GitHub
parent e425662494
commit bb2cdbe7bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -63,7 +63,7 @@ SSDP_SCANNER = "scanner"
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")

View file

@ -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