Skip to content

Commit

Permalink
Binary sensor ping fixed for hassio (home-assistant#8573)
Browse files Browse the repository at this point in the history
* Add support for multiple ping utilities.

* Added support for differing flavours of ping included with
different distributions (specifically alpine linux for hassio's
homeassistant).

* Updated as per comments in PR
  • Loading branch information
gollo authored and fabaff committed Jul 22, 2017
1 parent b4f392b commit 1807b45
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion homeassistant/components/binary_sensor/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
PING_MATCHER = re.compile(
r'(?P<min>\d+.\d+)\/(?P<avg>\d+.\d+)\/(?P<max>\d+.\d+)\/(?P<mdev>\d+.\d+)')

PING_MATCHER_BUSYBOX = re.compile(
r'(?P<min>\d+.\d+)\/(?P<avg>\d+.\d+)\/(?P<max>\d+.\d+)')

WIN32_PING_MATCHER = re.compile(
r'(?P<min>\d+)ms.+(?P<max>\d+)ms.+(?P<avg>\d+)ms')

Expand Down Expand Up @@ -126,7 +129,14 @@ def ping(self):
'avg': rtt_avg,
'max': rtt_max,
'mdev': ''}

if 'max/' not in str(out):
match = PING_MATCHER_BUSYBOX.search(str(out).split('\n')[-1])
rtt_min, rtt_avg, rtt_max = match.groups()
return {
'min': rtt_min,
'avg': rtt_avg,
'max': rtt_max,
'mdev': ''}
match = PING_MATCHER.search(str(out).split('\n')[-1])
rtt_min, rtt_avg, rtt_max, rtt_mdev = match.groups()
return {
Expand Down

0 comments on commit 1807b45

Please sign in to comment.