def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Denon platform.""" import denonavr # Initialize list with receivers to be started receivers = [] cache = hass.data.get(KEY_DENON_CACHE) if cache is None: cache = hass.data[KEY_DENON_CACHE] = set() # Start assignment of host and name show_all_sources = config.get(CONF_SHOW_ALL_SOURCES) # 1. option: manual setting if config.get(CONF_HOST) is not None: host = config.get(CONF_HOST) name = config.get(CONF_NAME) # Check if host not in cache, append it and save for later starting if host not in cache: cache.add(host) receivers.append( DenonDevice(denonavr.DenonAVR(host, name, show_all_sources))) _LOGGER.info("Denon receiver at host %s initialized", host) # 2. option: discovery using netdisco if discovery_info is not None: host = discovery_info.get('host') name = discovery_info.get('name') # Check if host not in cache, append it and save for later starting if host not in cache: cache.add(host) receivers.append( DenonDevice(denonavr.DenonAVR(host, name, show_all_sources))) _LOGGER.info("Denon receiver at host %s initialized", host) # 3. option: discovery using denonavr library if config.get(CONF_HOST) is None and discovery_info is None: d_receivers = denonavr.discover() # More than one receiver could be discovered by that method if d_receivers is not None: for d_receiver in d_receivers: host = d_receiver["host"] name = d_receiver["friendlyName"] # Check if host not in cache, append it and save for later # starting if host not in cache: cache.add(host) receivers.append( DenonDevice( denonavr.DenonAVR(host, name, show_all_sources))) _LOGGER.info("Denon receiver at host %s initialized", host) # Add all freshly discovered receivers if receivers: add_devices(receivers)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Denon platform.""" import denonavr # Initialize list with receivers to be started receivers = [] cache = hass.data.get(KEY_DENON_CACHE) if cache is None: cache = hass.data[KEY_DENON_CACHE] = set() # Get config option for show_all_sources and timeout show_all_sources = config.get(CONF_SHOW_ALL_SOURCES) timeout = config.get(CONF_TIMEOUT) # Get config option for additional zones zones = config.get(CONF_ZONES) if zones is not None: add_zones = {} for entry in zones: add_zones[entry[CONF_ZONE]] = entry.get(CONF_NAME) else: add_zones = None # Start assignment of host and name new_hosts = [] # 1. option: manual setting if config.get(CONF_HOST) is not None: host = config.get(CONF_HOST) name = config.get(CONF_NAME) new_hosts.append(NewHost(host=host, name=name)) # 2. option: discovery using netdisco if discovery_info is not None: host = discovery_info.get('host') name = discovery_info.get('name') new_hosts.append(NewHost(host=host, name=name)) # 3. option: discovery using denonavr library if config.get(CONF_HOST) is None and discovery_info is None: d_receivers = denonavr.discover() # More than one receiver could be discovered by that method for d_receiver in d_receivers: host = d_receiver["host"] name = d_receiver["friendlyName"] new_hosts.append(NewHost(host=host, name=name)) for entry in new_hosts: # Check if host not in cache, append it and save for later # starting if entry.host not in cache: new_device = denonavr.DenonAVR(host=entry.host, name=entry.name, show_all_inputs=show_all_sources, timeout=timeout, add_zones=add_zones) for new_zone in new_device.zones.values(): receivers.append(DenonDevice(new_zone)) cache.add(host) _LOGGER.info("Denon receiver at host %s initialized", host) # Add all freshly discovered receivers if receivers: add_entities(receivers)
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Denon platform.""" # pylint: disable=import-error import denonavr # Initialize list with receivers to be started receivers = [] cache = hass.data.get(KEY_DENON_CACHE) if cache is None: cache = hass.data[KEY_DENON_CACHE] = set() # Get config option for show_all_sources and timeout show_all_sources = config.get(CONF_SHOW_ALL_SOURCES) timeout = config.get(CONF_TIMEOUT) # Get config option for additional zones zones = config.get(CONF_ZONES) if zones is not None: add_zones = {} for entry in zones: add_zones[entry[CONF_ZONE]] = entry.get(CONF_NAME) else: add_zones = None # Start assignment of host and name new_hosts = [] # 1. option: manual setting if config.get(CONF_HOST) is not None: host = config.get(CONF_HOST) name = config.get(CONF_NAME) new_hosts.append(NewHost(host=host, name=name)) # 2. option: discovery using netdisco if discovery_info is not None: host = discovery_info.get('host') name = discovery_info.get('name') new_hosts.append(NewHost(host=host, name=name)) # 3. option: discovery using denonavr library if config.get(CONF_HOST) is None and discovery_info is None: d_receivers = denonavr.discover() # More than one receiver could be discovered by that method for d_receiver in d_receivers: host = d_receiver["host"] name = d_receiver["friendlyName"] new_hosts.append( NewHost(host=host, name=name)) for entry in new_hosts: # Check if host not in cache, append it and save for later # starting if entry.host not in cache: new_device = denonavr.DenonAVR( host=entry.host, name=entry.name, show_all_inputs=show_all_sources, timeout=timeout, add_zones=add_zones) for new_zone in new_device.zones.values(): receivers.append(DenonDevice(new_zone)) cache.add(host) _LOGGER.info("Denon receiver at host %s initialized", host) # Add all freshly discovered receivers if receivers: add_devices(receivers)