Allow disabling WeMo Discovery (#18079)

* WeMo - Disable Discovery - New config option

* WeMo - Disable Discovery - Change log level to debug

* WeMo - Disable Discovery - Change logging level
This commit is contained in:
Adam Belebczuk 2018-11-02 23:42:24 -04:00 committed by Aaron Bach
parent 6a5f9faa33
commit 5c99862878

View File

@ -58,12 +58,17 @@ def coerce_host_port(value):
CONF_STATIC = 'static' CONF_STATIC = 'static'
CONF_DISABLE_DISCOVERY = 'disable_discovery'
DEFAULT_DISABLE_DISCOVERY = False
CONFIG_SCHEMA = vol.Schema({ CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({ DOMAIN: vol.Schema({
vol.Optional(CONF_STATIC, default=[]): vol.Schema([ vol.Optional(CONF_STATIC, default=[]): vol.Schema([
vol.All(cv.string, coerce_host_port) vol.All(cv.string, coerce_host_port)
]) ]),
vol.Optional(CONF_DISABLE_DISCOVERY,
default=DEFAULT_DISABLE_DISCOVERY): cv.boolean
}), }),
}, extra=vol.ALLOW_EXTRA) }, extra=vol.ALLOW_EXTRA)
@ -78,7 +83,7 @@ def setup(hass, config):
def stop_wemo(event): def stop_wemo(event):
"""Shutdown Wemo subscriptions and subscription thread on exit.""" """Shutdown Wemo subscriptions and subscription thread on exit."""
_LOGGER.info("Shutting down subscriptions.") _LOGGER.debug("Shutting down subscriptions.")
SUBSCRIPTION_REGISTRY.stop() SUBSCRIPTION_REGISTRY.stop()
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_wemo) hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_wemo)
@ -136,13 +141,16 @@ def setup(hass, config):
devices.append((url, device)) devices.append((url, device))
_LOGGER.info("Scanning for WeMo devices.") disable_discovery = config.get(DOMAIN, {}).get(CONF_DISABLE_DISCOVERY)
devices.extend(
(setup_url_for_device(device), device) if not disable_discovery:
for device in pywemo.discover_devices()) _LOGGER.debug("Scanning for WeMo devices.")
devices.extend(
(setup_url_for_device(device), device)
for device in pywemo.discover_devices())
for url, device in devices: for url, device in devices:
_LOGGER.info('Adding wemo at %s:%i', device.host, device.port) _LOGGER.debug('Adding wemo at %s:%i', device.host, device.port)
discovery_info = { discovery_info = {
'model_name': device.model_name, 'model_name': device.model_name,