Remove Windows workarounds from ping (#64069)

This commit is contained in:
Erik Montnemery 2022-01-13 20:43:00 +01:00 committed by GitHub
parent abce453b5c
commit 0fa4f616ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 31 deletions

View file

@ -6,7 +6,6 @@ from contextlib import suppress
from datetime import timedelta
import logging
import re
import sys
from typing import Any
from icmplib import NameLookupError, async_ping
@ -205,25 +204,15 @@ class PingDataSubProcess(PingData):
def __init__(self, hass, host, count, privileged) -> None:
"""Initialize the data object."""
super().__init__(hass, host, count)
if sys.platform == "win32":
self._ping_cmd = [
"ping",
"-n",
str(self._count),
"-w",
"1000",
self._ip_address,
]
else:
self._ping_cmd = [
"ping",
"-n",
"-q",
"-c",
str(self._count),
"-W1",
self._ip_address,
]
self._ping_cmd = [
"ping",
"-n",
"-q",
"-c",
str(self._count),
"-W1",
self._ip_address,
]
async def async_ping(self):
"""Send ICMP echo request and return details if success."""
@ -261,12 +250,6 @@ class PingDataSubProcess(PingData):
pinger.returncode,
)
if sys.platform == "win32":
match = WIN32_PING_MATCHER.search(
str(out_data).rsplit("\n", maxsplit=1)[-1]
)
rtt_min, rtt_avg, rtt_max = match.groups()
return {"min": rtt_min, "avg": rtt_avg, "max": rtt_max, "mdev": ""}
if "max/" not in str(out_data):
match = PING_MATCHER_BUSYBOX.search(
str(out_data).rsplit("\n", maxsplit=1)[-1]

View file

@ -6,7 +6,6 @@ from collections.abc import Awaitable, Callable
from datetime import timedelta
import logging
import subprocess
import sys
from icmplib import async_multiping
import voluptuous as vol
@ -50,10 +49,7 @@ class HostSubProcess:
self.ip_address = ip_address
self.dev_id = dev_id
self._count = config[CONF_PING_COUNT]
if sys.platform == "win32":
self._ping_cmd = ["ping", "-n", "1", "-w", "1000", ip_address]
else:
self._ping_cmd = ["ping", "-n", "-q", "-c1", "-W1", ip_address]
self._ping_cmd = ["ping", "-n", "-q", "-c1", "-W1", ip_address]
def ping(self):
"""Send an ICMP echo request and return True if success."""