diff --git a/homeassistant/components/ping/__init__.py b/homeassistant/components/ping/__init__.py index 26dd8113231..df1f7ebc9e5 100644 --- a/homeassistant/components/ping/__init__.py +++ b/homeassistant/components/ping/__init__.py @@ -4,7 +4,7 @@ from __future__ import annotations from dataclasses import dataclass import logging -from icmplib import SocketPermissionError, ping as icmp_ping +from icmplib import SocketPermissionError, async_ping from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv @@ -30,19 +30,19 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: await async_setup_reload_service(hass, DOMAIN, PLATFORMS) hass.data[DOMAIN] = PingDomainData( - privileged=await hass.async_add_executor_job(_can_use_icmp_lib_with_privilege), + privileged=await _can_use_icmp_lib_with_privilege(), ) return True -def _can_use_icmp_lib_with_privilege() -> None | bool: +async def _can_use_icmp_lib_with_privilege() -> None | bool: """Verify we can create a raw socket.""" try: - icmp_ping("127.0.0.1", count=0, timeout=0, privileged=True) + await async_ping("127.0.0.1", count=0, timeout=0, privileged=True) except SocketPermissionError: try: - icmp_ping("127.0.0.1", count=0, timeout=0, privileged=False) + await async_ping("127.0.0.1", count=0, timeout=0, privileged=False) except SocketPermissionError: _LOGGER.debug( "Cannot use icmplib because privileges are insufficient to create the" diff --git a/tests/components/ping/test_binary_sensor.py b/tests/components/ping/test_binary_sensor.py index 3389534483f..b9bdc917e70 100644 --- a/tests/components/ping/test_binary_sensor.py +++ b/tests/components/ping/test_binary_sensor.py @@ -14,7 +14,7 @@ from tests.common import get_fixture_path @pytest.fixture def mock_ping() -> None: """Mock icmplib.ping.""" - with patch("homeassistant.components.ping.icmp_ping"): + with patch("homeassistant.components.ping.async_ping"): yield