mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
parent
6453ea4e61
commit
e968b1a0f4
@ -11,6 +11,8 @@ from homeassistant.helpers.entity import Entity
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DEPENDENCIES = ['upnp']
|
||||||
|
|
||||||
BYTES_RECEIVED = 1
|
BYTES_RECEIVED = 1
|
||||||
BYTES_SENT = 2
|
BYTES_SENT = 2
|
||||||
PACKETS_RECEIVED = 3
|
PACKETS_RECEIVED = 3
|
||||||
@ -25,12 +27,16 @@ SENSOR_TYPES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass, config, add_devices, discovery_info=None):
|
async def async_setup_platform(hass, config, async_add_devices,
|
||||||
|
discovery_info=None):
|
||||||
"""Set up the IGD sensors."""
|
"""Set up the IGD sensors."""
|
||||||
|
if discovery_info is None:
|
||||||
|
return
|
||||||
|
|
||||||
device = hass.data[DATA_UPNP]
|
device = hass.data[DATA_UPNP]
|
||||||
service = device.find_first_service(CIC_SERVICE)
|
service = device.find_first_service(CIC_SERVICE)
|
||||||
unit = discovery_info['unit']
|
unit = discovery_info['unit']
|
||||||
add_devices([
|
async_add_devices([
|
||||||
IGDSensor(service, t, unit if SENSOR_TYPES[t][1] else '#')
|
IGDSensor(service, t, unit if SENSOR_TYPES[t][1] else '#')
|
||||||
for t in SENSOR_TYPES], True)
|
for t in SENSOR_TYPES], True)
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ CONFIG_SCHEMA = vol.Schema({
|
|||||||
DOMAIN: vol.Schema({
|
DOMAIN: vol.Schema({
|
||||||
vol.Optional(CONF_ENABLE_PORT_MAPPING, default=True): cv.boolean,
|
vol.Optional(CONF_ENABLE_PORT_MAPPING, default=True): cv.boolean,
|
||||||
vol.Optional(CONF_UNITS, default="MBytes"): vol.In(UNITS),
|
vol.Optional(CONF_UNITS, default="MBytes"): vol.In(UNITS),
|
||||||
vol.Optional(CONF_LOCAL_IP): ip_address,
|
vol.Optional(CONF_LOCAL_IP): vol.All(ip_address, cv.string),
|
||||||
vol.Optional(CONF_PORTS):
|
vol.Optional(CONF_PORTS):
|
||||||
vol.Schema({vol.Any(CONF_HASS, cv.positive_int): cv.positive_int})
|
vol.Schema({vol.Any(CONF_HASS, cv.positive_int): cv.positive_int})
|
||||||
}),
|
}),
|
||||||
@ -62,9 +62,7 @@ async def async_setup(hass, config):
|
|||||||
config = config[DOMAIN]
|
config = config[DOMAIN]
|
||||||
host = config.get(CONF_LOCAL_IP)
|
host = config.get(CONF_LOCAL_IP)
|
||||||
|
|
||||||
if host is not None:
|
if host is None:
|
||||||
host = str(host)
|
|
||||||
else:
|
|
||||||
host = get_local_ip()
|
host = get_local_ip()
|
||||||
|
|
||||||
if host == '127.0.0.1':
|
if host == '127.0.0.1':
|
||||||
@ -90,10 +88,8 @@ async def async_setup(hass, config):
|
|||||||
service = device.find_first_service(IP_SERVICE)
|
service = device.find_first_service(IP_SERVICE)
|
||||||
if _service['serviceType'] == CIC_SERVICE:
|
if _service['serviceType'] == CIC_SERVICE:
|
||||||
unit = config.get(CONF_UNITS)
|
unit = config.get(CONF_UNITS)
|
||||||
discovery.load_platform(hass, 'sensor',
|
hass.async_add_job(discovery.async_load_platform(
|
||||||
DOMAIN,
|
hass, 'sensor', DOMAIN, {'unit': unit}, config))
|
||||||
{'unit': unit},
|
|
||||||
config)
|
|
||||||
except UpnpSoapError as error:
|
except UpnpSoapError as error:
|
||||||
_LOGGER.error(error)
|
_LOGGER.error(error)
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user