Fix SystemMonitor IP address sensor (#16394)
parent
ba63a6abc0
commit
a4aa30fc73
|
@ -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':
|
||||
|
|
Loading…
Reference in New Issue