def setup_tv(host, hass, add_devices):
    """Setup a phue bridge based on host parameter."""
    from pylgtv import WebOsClient
    from pylgtv import PyLGTVPairException

    client = WebOsClient(host)

    if not client.is_registered():
        if host in _CONFIGURING:
            # Try to pair.
            try:
                client.register()
            except PyLGTVPairException:
                _LOGGER.warning(
                    'Connected to LG WebOS TV at %s but not paired.', host)
                return
            except OSError:
                _LOGGER.error('Unable to connect to host %s.', host)
                return
        else:
            # Not registered, request configuration.
            _LOGGER.warning('LG WebOS TV at %s needs to be paired.', host)
            request_configuration(host, hass, add_devices)
            return

    # If we came here and configuring this host, mark as done.
    if client.is_registered() and host in _CONFIGURING:
        request_id = _CONFIGURING.pop(host)
        configurator = get_component('configurator')
        configurator.request_done(request_id)

    add_devices([LgWebOSDevice(host)])
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/components/media_player/webostv.py/setup_tv/original