Fix SystemMonitor IP address sensor (#16394)

pull/16382/merge
Rene Nulsch 2018-09-04 08:46:04 +02:00 committed by Fabian Affolter
parent ba63a6abc0
commit a4aa30fc73
1 changed files with 7 additions and 4 deletions

View File

@ -6,6 +6,7 @@ https://home-assistant.io/components/sensor.systemmonitor/
"""
import logging
import os
import socket
import voluptuous as vol
@ -61,9 +62,9 @@ IO_COUNTER = {
'packets_in': 3,
}
IF_ADDRS = {
'ipv4_address': 0,
'ipv6_address': 1,
IF_ADDRS_FAMILY = {
'ipv4_address': socket.AF_INET,
'ipv6_address': socket.AF_INET6,
}
@ -165,7 +166,9 @@ class SystemMonitorSensor(Entity):
elif self.type == 'ipv4_address' or self.type == 'ipv6_address':
addresses = psutil.net_if_addrs()
if self.argument in addresses:
self._state = addresses[self.argument][IF_ADDRS[self.type]][1]
for addr in addresses[self.argument]:
if addr.family == IF_ADDRS_FAMILY[self.type]:
self._state = addr.address
else:
self._state = None
elif self.type == 'last_boot':