Use dataclass to carry data in ping (#99803)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Jan-Philipp Benecke 2023-10-20 23:46:33 +02:00 committed by GitHub
parent b881057aa6
commit 3c455391c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 11 deletions

View file

@ -23,7 +23,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import DOMAIN, ICMP_TIMEOUT, PING_PRIVS, PING_TIMEOUT
from . import PingDomainData
from .const import DOMAIN, ICMP_TIMEOUT, PING_TIMEOUT
_LOGGER = logging.getLogger(__name__)
@ -70,10 +71,13 @@ async def async_setup_platform(
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the Ping Binary sensor."""
data: PingDomainData = hass.data[DOMAIN]
host: str = config[CONF_HOST]
count: int = config[CONF_PING_COUNT]
name: str = config.get(CONF_NAME, f"{DEFAULT_NAME} {host}")
privileged: bool | None = hass.data[DOMAIN][PING_PRIVS]
privileged: bool | None = data.privileged
ping_cls: type[PingDataSubProcess | PingDataICMPLib]
if privileged is None:
ping_cls = PingDataSubProcess