Exemplo n.º 1
2
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)

    try:
        client.register()
    except PyLGTVPairException:
        _LOGGER.error("Pairing with TV failed")
        return None
    except OSError:
        _LOGGER.error("TV unreachable")
        return None

    return LgWebOSNotificationService(client)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)])
Exemplo n.º 4
0
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)])
Exemplo n.º 5
0
def get_service(hass, config):
    """Return the notify service."""
    if not validate_config({DOMAIN: config}, {DOMAIN: [CONF_HOST, CONF_NAME]},
                           _LOGGER):
        return None

    host = config.get(CONF_HOST, None)

    if not host:
        _LOGGER.error('No host provided.')
        return None

    from pylgtv import WebOsClient
    from pylgtv import PyLGTVPairException

    client = WebOsClient(host)

    try:
        client.register()
    except PyLGTVPairException:
        _LOGGER.error('Pairing failed.')
        return None
    except ConnectionRefusedError:
        _LOGGER.error('Host unreachable.')
        return None

    return LgWebOSNotificationService(client)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
def get_service(hass, config):
    """Return the notify service."""
    if not validate_config({DOMAIN: config}, {DOMAIN: [CONF_HOST, CONF_NAME]},
                           _LOGGER):
        return None

    host = config.get(CONF_HOST, None)

    if not host:
        _LOGGER.error('No host provided.')
        return None

    from pylgtv import WebOsClient
    from pylgtv import PyLGTVPairException

    client = WebOsClient(host)

    try:
        client.register()
    except PyLGTVPairException:
        _LOGGER.error('Pairing failed.')
        return None
    except OSError:
        _LOGGER.error('Host unreachable.')
        return None

    return LgWebOSNotificationService(client)
Exemplo n.º 8
0
    def cmd(self, cmd):
        if "denon" in cmd:
            d = denonavr.DenonAVR(app_cfg['denon']['ip'])
            d.update()

            if cmd == "denon_input_digital":
                d.input_func = app_cfg['denon']['digital_in']
            elif cmd == "denon_power_off":
                d.power_off()
            elif cmd == "denon_power_on":
                d.power_on()
            elif cmd == "denon_vol_down":
                d.volume_down()
            elif cmd == "denon_vol_mute":
                d.mute(True)  #FIXME
            elif cmd == "denon_vol_up":
                d.volume_up()
            else:
                return '{"response":"invalid_cmd"}'

            return '{"response":"ok"}'

        elif "lg" in cmd:
            w = WebOsClient(app_cfg['lg']['ip'])
            w.register()

            if "lg_arr_" in cmd:
                w.request(
                    "com.webos.service.networkinput/getPointerInputSocket")
                ws = websocket.WebSocket()
                ws.connect(w.last_response['payload']['socketPath'])
                if cmd == "lg_arr_down":
                    ws.send('type:button\nname:DOWN\n\n')
                elif cmd == "lg_arr_up":
                    ws.send('type:button\nname:UP\n\n')
                elif cmd == "lg_arr_left":
                    ws.send('type:button\nname:LEFT\n\n')
                elif cmd == "lg_arr_right":
                    ws.send('type:button\nname:RIGHT\n\n')
                elif cmd == "lg_arr_ok":
                    ws.send('type:button\nname:ENTER\n\n')
                elif cmd == "lg_arr_back":
                    ws.send('type:button\nname:BACK\n\n')
            elif cmd == "lg_cmd_pause":
                w.pause()
            elif cmd == "lg_input_netflix":
                w.launch_app(app_cfg['lg']['netflix'])
            elif cmd == "lg_input_ps4":
                w.set_input(app_cfg['lg']['ps4'])
            elif cmd == "lg_power_on":
                send_magic_packet(app_cfg['lg']['mac'])
            elif cmd == "lg_power_off":
                w.power_off()
            else:
                return '{"response":"invalid_cmd"}'

            return '{"response":"ok"}'

        else:
            return '{"response":"invalid_cmd"}'
Exemplo n.º 9
0
def get_service(hass, config):
    """Return the notify service."""
    from pylgtv import WebOsClient
    from pylgtv import PyLGTVPairException

    client = WebOsClient(config.get(CONF_HOST))

    try:
        client.register()
    except PyLGTVPairException:
        _LOGGER.error("Pairing with TV failed")
        return None
    except OSError:
        _LOGGER.error("TV unreachable")
        return None

    return LgWebOSNotificationService(client)
Exemplo n.º 10
0
def get_service(hass, config):
    """Return the notify service."""
    from pylgtv import WebOsClient
    from pylgtv import PyLGTVPairException

    client = WebOsClient(config.get(CONF_HOST))

    try:
        client.register()
    except PyLGTVPairException:
        _LOGGER.error('Pairing failed.')
        return None
    except OSError:
        _LOGGER.error('Host unreachable.')
        return None

    return LgWebOSNotificationService(client)
Exemplo n.º 11
0
def get_service(hass, config, discovery_info=None):
    """Return the notify service."""
    from pylgtv import WebOsClient
    from pylgtv import PyLGTVPairException

    client = WebOsClient(config.get(CONF_HOST))

    try:
        client.register()
    except PyLGTVPairException:
        _LOGGER.error("Pairing with TV failed")
        return None
    except OSError:
        _LOGGER.error("TV unreachable")
        return None

    return LgWebOSNotificationService(client)
Exemplo n.º 12
0
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,
    )
Exemplo n.º 13
0
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))