def setup_platform(hass, config, add_entities, discovery_info=None):
    'Set up the Samsung TV platform.'
    known_devices = hass.data.get(KNOWN_DEVICES_KEY)
    if (known_devices is None):
        known_devices = set()
        hass.data[KNOWN_DEVICES_KEY] = known_devices
    uuid = None
    if (config.get(CONF_HOST) is not None):
        host = config.get(CONF_HOST)
        port = config.get(CONF_PORT)
        name = config.get(CONF_NAME)
        mac = config.get(CONF_MAC)
        timeout = config.get(CONF_TIMEOUT)
    elif (discovery_info is not None):
        tv_name = discovery_info.get('name')
        model = discovery_info.get('model_name')
        host = discovery_info.get('host')
        name = '{} ({})'.format(tv_name, model)
        port = DEFAULT_PORT
        timeout = DEFAULT_TIMEOUT
        mac = None
        udn = discovery_info.get('udn')
        if (udn and udn.startswith('uuid:')):
            uuid = udn[len('uuid:'):]
    else:
        _LOGGER.warning('Cannot determine device')
        return
    ip_addr = socket.gethostbyname(host)
    if (ip_addr not in known_devices):
        known_devices.add(ip_addr)
        add_entities([SamsungTVDevice(host, port, name, timeout, mac, uuid)])
        _LOGGER.info("Samsung TV %s:%d added as '%s'", host, port, name)
    else:
        _LOGGER.info('Ignoring duplicate Samsung TV %s:%d', host, port)
Set up the Samsung TV platform.
def setup_platform(hass, config, add_entities, discovery_info=None):
    
    known_devices = hass.data.get(KNOWN_DEVICES_KEY)
    if (known_devices is None):
        known_devices = set()
        hass.data[KNOWN_DEVICES_KEY] = known_devices
    uuid = None
    if (config.get(CONF_HOST) is not None):
        host = config.get(CONF_HOST)
        port = config.get(CONF_PORT)
        name = config.get(CONF_NAME)
        mac = config.get(CONF_MAC)
        timeout = config.get(CONF_TIMEOUT)
    elif (discovery_info is not None):
        tv_name = discovery_info.get('name')
        model = discovery_info.get('model_name')
        host = discovery_info.get('host')
        name = '{} ({})'.format(tv_name, model)
        port = DEFAULT_PORT
        timeout = DEFAULT_TIMEOUT
        mac = None
        udn = discovery_info.get('udn')
        if (udn and udn.startswith('uuid:')):
            uuid = udn[len('uuid:'):]
    else:
        _LOGGER.warning('Cannot determine device')
        return
    ip_addr = socket.gethostbyname(host)
    if (ip_addr not in known_devices):
        known_devices.add(ip_addr)
        add_entities([SamsungTVDevice(host, port, name, timeout, mac, uuid)])
        _LOGGER.info("Samsung TV %s:%d added as '%s'", host, port, name)
    else:
        _LOGGER.info('Ignoring duplicate Samsung TV %s:%d', host, port)