From be8724a6f8e3d2612447f8ef394983961bcb59b9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 9 Oct 2021 21:00:28 -1000 Subject: [PATCH] Do all of dhcp scapy startup in the executor (#57392) --- homeassistant/components/dhcp/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/dhcp/__init__.py b/homeassistant/components/dhcp/__init__.py index 61208ac6423..3e4fd8fec01 100644 --- a/homeassistant/components/dhcp/__init__.py +++ b/homeassistant/components/dhcp/__init__.py @@ -276,6 +276,10 @@ class DHCPWatcher(WatcherBase): self._sniffer.stop() async def async_start(self): + """Start watching for dhcp packets.""" + await self.hass.async_add_executor_job(self._start) + + def _start(self): """Start watching for dhcp packets.""" # Local import because importing from scapy has side effects such as opening # sockets @@ -319,7 +323,7 @@ class DHCPWatcher(WatcherBase): conf.sniff_promisc = 0 try: - await self.hass.async_add_executor_job(_verify_l2socket_setup, FILTER) + _verify_l2socket_setup(FILTER) except (Scapy_Exception, OSError) as ex: if os.geteuid() == 0: _LOGGER.error("Cannot watch for dhcp packets: %s", ex) @@ -330,7 +334,7 @@ class DHCPWatcher(WatcherBase): return try: - await self.hass.async_add_executor_job(_verify_working_pcap, FILTER) + _verify_working_pcap(FILTER) except (Scapy_Exception, ImportError) as ex: _LOGGER.error( "Cannot watch for dhcp packets without a functional packet filter: %s",