Skip to content

Commit

Permalink
Change SSDP discovery scan interval to 10 minutes (#99975)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bdraco authored Sep 9, 2023
1 parent e425662 commit bb2cdbe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/ssdp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
8 changes: 4 additions & 4 deletions tests/components/ssdp/test_init.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -447,15 +447,15 @@ 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
assert ssdp_listener.async_stop.call_count == 0

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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bb2cdbe

Please sign in to comment.