Use dataclass to carry data in ping (#99803)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
b881057aa6
commit
3c455391c2
6 changed files with 28 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue