Fix SystemMonitor IP address sensor (#16394)
This commit is contained in:
parent
ba63a6abc0
commit
a4aa30fc73
1 changed files with 7 additions and 4 deletions
|
@ -6,6 +6,7 @@ https://home-assistant.io/components/sensor.systemmonitor/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import socket
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -61,9 +62,9 @@ IO_COUNTER = {
|
||||||
'packets_in': 3,
|
'packets_in': 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
IF_ADDRS = {
|
IF_ADDRS_FAMILY = {
|
||||||
'ipv4_address': 0,
|
'ipv4_address': socket.AF_INET,
|
||||||
'ipv6_address': 1,
|
'ipv6_address': socket.AF_INET6,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -165,7 +166,9 @@ class SystemMonitorSensor(Entity):
|
||||||
elif self.type == 'ipv4_address' or self.type == 'ipv6_address':
|
elif self.type == 'ipv4_address' or self.type == 'ipv6_address':
|
||||||
addresses = psutil.net_if_addrs()
|
addresses = psutil.net_if_addrs()
|
||||||
if self.argument in addresses:
|
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:
|
else:
|
||||||
self._state = None
|
self._state = None
|
||||||
elif self.type == 'last_boot':
|
elif self.type == 'last_boot':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue