def setup_tv(host, name, customize, 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, name, customize, 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, name, customize)])
def setup_tv(host, mac, name, customize, config, hass, add_devices): """Set up a LG WebOS TV based on host parameter.""" from pylgtv import WebOsClient from pylgtv import PyLGTVPairException from websockets.exceptions import ConnectionClosed client = WebOsClient(host, config) if not client.is_registered(): if host in _CONFIGURING: # Try to pair. try: client.register() except PyLGTVPairException: _LOGGER.warning("Connected to LG webOS TV %s but not paired", host) return except (OSError, ConnectionClosed, TypeError, asyncio.TimeoutError): _LOGGER.error("Unable to connect to host %s", host) return else: # Not registered, request configuration. _LOGGER.warning("LG webOS TV %s needs to be paired", host) request_configuration(host, mac, name, customize, config, 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, mac, name, customize, config)], True)
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 ConnectionRefusedError: _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)])
def setup_tv(host, mac, name, customize, config, hass, add_devices): """Set up a LG WebOS TV based on host parameter.""" from pylgtv import WebOsClient from pylgtv import PyLGTVPairException from websockets.exceptions import ConnectionClosed client = WebOsClient(host, config) if not client.is_registered(): if host in _CONFIGURING: # Try to pair. try: client.register() except PyLGTVPairException: _LOGGER.warning( "Connected to LG webOS TV %s but not paired", host) return except (OSError, ConnectionClosed, TypeError, asyncio.TimeoutError): _LOGGER.error("Unable to connect to host %s", host) return else: # Not registered, request configuration. _LOGGER.warning("LG webOS TV %s needs to be paired", host) request_configuration( host, mac, name, customize, config, 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, mac, name, customize, config)], True)
def setup_tv(host, name, customize, config, timeout, hass, add_entities, turn_on_action): """Set up a LG WebOS TV based on host parameter.""" client = WebOsClient(host, config, timeout) if not client.is_registered(): if host in _CONFIGURING: # Try to pair. try: client.register() except PyLGTVPairException: _LOGGER.warning("Connected to LG webOS TV %s but not paired", host) return except (OSError, ConnectionClosed, asyncio.TimeoutError): _LOGGER.error("Unable to connect to host %s", host) return else: # Not registered, request configuration. _LOGGER.warning("LG webOS TV %s needs to be paired", host) request_configuration( host, name, customize, config, timeout, hass, add_entities, turn_on_action, ) 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 = hass.components.configurator configurator.request_done(request_id) add_entities( [ LgWebOSDevice(host, name, customize, config, timeout, hass, turn_on_action) ], True, )
def get_service(hass, config, discovery_info=None): """Return the notify service.""" from pylgtv import WebOsClient from pylgtv import PyLGTVPairException path = hass.config.path(config.get(CONF_FILENAME)) client = WebOsClient(config.get(CONF_HOST), key_file_path=path) if not client.is_registered(): try: client.register() except PyLGTVPairException: _LOGGER.error("Pairing with TV failed") return None except OSError: _LOGGER.error("TV unreachable") return None return LgWebOSNotificationService(client, config.get(CONF_ICON))