UPnP code cleanup (#14235)

* missing async calls

* lint

* cleanup
This commit is contained in:
Diogo Gomes 2018-05-02 14:15:30 +01:00 committed by Paulus Schoutsen
parent 6453ea4e61
commit e968b1a0f4
2 changed files with 12 additions and 10 deletions

View file

@ -11,6 +11,8 @@ from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['upnp']
BYTES_RECEIVED = 1
BYTES_SENT = 2
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."""
if discovery_info is None:
return
device = hass.data[DATA_UPNP]
service = device.find_first_service(CIC_SERVICE)
unit = discovery_info['unit']
add_devices([
async_add_devices([
IGDSensor(service, t, unit if SENSOR_TYPES[t][1] else '#')
for t in SENSOR_TYPES], True)

View file

@ -50,7 +50,7 @@ CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Optional(CONF_ENABLE_PORT_MAPPING, default=True): cv.boolean,
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.Schema({vol.Any(CONF_HASS, cv.positive_int): cv.positive_int})
}),
@ -62,9 +62,7 @@ async def async_setup(hass, config):
config = config[DOMAIN]
host = config.get(CONF_LOCAL_IP)
if host is not None:
host = str(host)
else:
if host is None:
host = get_local_ip()
if host == '127.0.0.1':
@ -90,10 +88,8 @@ async def async_setup(hass, config):
service = device.find_first_service(IP_SERVICE)
if _service['serviceType'] == CIC_SERVICE:
unit = config.get(CONF_UNITS)
discovery.load_platform(hass, 'sensor',
DOMAIN,
{'unit': unit},
config)
hass.async_add_job(discovery.async_load_platform(
hass, 'sensor', DOMAIN, {'unit': unit}, config))
except UpnpSoapError as error:
_LOGGER.error(error)
return False