mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Reduce ssdp context switches into the executor (#42045)
* Reduce ssdp context switches into the executor * no self use
This commit is contained in:
parent
c4821bfa74
commit
6c1078d1ca
@ -1,6 +1,7 @@
|
|||||||
"""The SSDP integration."""
|
"""The SSDP integration."""
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
@ -50,6 +51,12 @@ async def async_setup(hass, config):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def _run_ssdp_scans():
|
||||||
|
_LOGGER.debug("Scanning")
|
||||||
|
# Run 3 times as packets can get lost
|
||||||
|
return itertools.chain.from_iterable([ssdp.scan() for _ in range(3)])
|
||||||
|
|
||||||
|
|
||||||
class Scanner:
|
class Scanner:
|
||||||
"""Class to manage SSDP scanning."""
|
"""Class to manage SSDP scanning."""
|
||||||
|
|
||||||
@ -62,11 +69,9 @@ class Scanner:
|
|||||||
|
|
||||||
async def async_scan(self, _):
|
async def async_scan(self, _):
|
||||||
"""Scan for new entries."""
|
"""Scan for new entries."""
|
||||||
_LOGGER.debug("Scanning")
|
entries = await self.hass.async_add_executor_job(_run_ssdp_scans)
|
||||||
# Run 3 times as packets can get lost
|
|
||||||
for _ in range(3):
|
await self._process_entries(entries)
|
||||||
entries = await self.hass.async_add_executor_job(ssdp.scan)
|
|
||||||
await self._process_entries(entries)
|
|
||||||
|
|
||||||
# We clear the cache after each run. We track discovered entries
|
# We clear the cache after each run. We track discovered entries
|
||||||
# so will never need a description twice.
|
# so will never need a description twice.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user