当前位置: 首页>>代码示例>>Python>>正文


Python pylgtv.WebOsClient类代码示例

本文整理汇总了Python中pylgtv.WebOsClient的典型用法代码示例。如果您正苦于以下问题:Python WebOsClient类的具体用法?Python WebOsClient怎么用?Python WebOsClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WebOsClient类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_tv

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)])
开发者ID:Bart274,项目名称:home-assistant,代码行数:32,代码来源:webostv.py

示例2: get_service

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)
开发者ID:1lann,项目名称:home-assistant,代码行数:27,代码来源:webostv.py

示例3: setup_tv

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)
开发者ID:Khabi,项目名称:home-assistant,代码行数:35,代码来源:webostv.py

示例4: get_service

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)
开发者ID:DavidLP,项目名称:home-assistant,代码行数:17,代码来源:webostv.py

示例5: get_service

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)
开发者ID:arjenfvellinga,项目名称:home-assistant,代码行数:18,代码来源:webostv.py

示例6: __init__

    def __init__(self, host, name, customize, config, timeout,
                 hass, on_action):
        """Initialize the webos device."""
        from pylgtv import WebOsClient
        self._client = WebOsClient(host, config, timeout)
        self._on_script = Script(hass, on_action) if on_action else None
        self._customize = customize

        self._name = name
        # Assume that the TV is not muted
        self._muted = False
        # Assume that the TV is in Play mode
        self._playing = True
        self._volume = 0
        self._current_source = None
        self._current_source_id = None
        self._state = STATE_UNKNOWN
        self._source_list = {}
        self._app_list = {}
开发者ID:JiShangShiDai,项目名称:home-assistant,代码行数:19,代码来源:webostv.py

示例7: __init__

    def __init__(self, host, name, customize):
        """Initialize the webos device."""
        from pylgtv import WebOsClient
        self._client = WebOsClient(host)
        self._customize = customize

        self._name = name
        # Assume that the TV is not muted
        self._muted = False
        # Assume that the TV is in Play mode
        self._playing = True
        self._volume = 0
        self._current_source = None
        self._current_source_id = None
        self._source_list = None
        self._state = STATE_UNKNOWN
        self._app_list = None

        self.update()
开发者ID:Bart274,项目名称:home-assistant,代码行数:19,代码来源:webostv.py

示例8: __init__

    def __init__(self, host, mac, name, customize, config):
        """Initialize the webos device."""
        from pylgtv import WebOsClient
        from wakeonlan import wol
        self._client = WebOsClient(host, config)
        self._wol = wol
        self._mac = mac
        self._customize = customize

        self._name = name
        # Assume that the TV is not muted
        self._muted = False
        # Assume that the TV is in Play mode
        self._playing = True
        self._volume = 0
        self._current_source = None
        self._current_source_id = None
        self._state = STATE_UNKNOWN
        self._source_list = {}
        self._app_list = {}
开发者ID:Khabi,项目名称:home-assistant,代码行数:20,代码来源:webostv.py

示例9: LgWebOSDevice

class LgWebOSDevice(MediaPlayerDevice):
    """Representation of a LG WebOS TV."""

    def __init__(self, host, name, customize, config, timeout,
                 hass, on_action):
        """Initialize the webos device."""
        from pylgtv import WebOsClient
        self._client = WebOsClient(host, config, timeout)
        self._on_script = Script(hass, on_action) if on_action else None
        self._customize = customize

        self._name = name
        # Assume that the TV is not muted
        self._muted = False
        # Assume that the TV is in Play mode
        self._playing = True
        self._volume = 0
        self._current_source = None
        self._current_source_id = None
        self._state = STATE_UNKNOWN
        self._source_list = {}
        self._app_list = {}
        self._channel = None

    @util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
    def update(self):
        """Retrieve the latest data."""
        from websockets.exceptions import ConnectionClosed
        try:
            current_input = self._client.get_input()
            if current_input is not None:
                self._current_source_id = current_input
                if self._state in (STATE_UNKNOWN, STATE_OFF):
                    self._state = STATE_PLAYING
            else:
                self._state = STATE_OFF
                self._current_source = None
                self._current_source_id = None
                self._channel = None

            if self._state is not STATE_OFF:
                self._muted = self._client.get_muted()
                self._volume = self._client.get_volume()
                self._channel = self._client.get_current_channel()

                self._source_list = {}
                self._app_list = {}
                conf_sources = self._customize.get(CONF_SOURCES, [])

                for app in self._client.get_apps():
                    self._app_list[app['id']] = app
                    if app['id'] == self._current_source_id:
                        self._current_source = app['title']
                        self._source_list[app['title']] = app
                    elif (not conf_sources or
                          app['id'] in conf_sources or
                          any(word in app['title']
                              for word in conf_sources) or
                          any(word in app['id']
                              for word in conf_sources)):
                        self._source_list[app['title']] = app

                for source in self._client.get_inputs():
                    if source['id'] == self._current_source_id:
                        self._current_source = source['label']
                        self._source_list[source['label']] = source
                    elif (not conf_sources or
                          source['label'] in conf_sources or
                          any(source['label'].find(word) != -1
                              for word in conf_sources)):
                        self._source_list[source['label']] = source
        except (OSError, ConnectionClosed, TypeError,
                asyncio.TimeoutError):
            self._state = STATE_OFF
            self._current_source = None
            self._current_source_id = None
            self._channel = None

    @property
    def name(self):
        """Return the name of the device."""
        return self._name

    @property
    def state(self):
        """Return the state of the device."""
        return self._state

    @property
    def is_volume_muted(self):
        """Boolean if volume is currently muted."""
        return self._muted

    @property
    def volume_level(self):
        """Volume level of the media player (0..1)."""
        return self._volume / 100.0

    @property
    def source(self):
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例10: WebOsClient

from pylgtv import WebOsClient

webos_client = WebOsClient('192.168.0.112')
#webos_client.launch_app('netflix')

for app in webos_client.get_apps():
    print(app)
开发者ID:prajoshpremdas,项目名称:pylgtv,代码行数:7,代码来源:example.py

示例11: LgWebOSDevice

class LgWebOSDevice(MediaPlayerDevice):
    """Representation of a LG WebOS TV."""

    # pylint: disable=too-many-public-methods
    def __init__(self, host, name, customize):
        """Initialize the webos device."""
        from pylgtv import WebOsClient
        self._client = WebOsClient(host)
        self._customize = customize

        self._name = name
        # Assume that the TV is not muted
        self._muted = False
        # Assume that the TV is in Play mode
        self._playing = True
        self._volume = 0
        self._current_source = None
        self._current_source_id = None
        self._source_list = None
        self._state = STATE_UNKNOWN
        self._app_list = None

        self.update()

    @util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
    def update(self):
        """Retrieve the latest data."""
        try:
            self._state = STATE_PLAYING
            self._muted = self._client.get_muted()
            self._volume = self._client.get_volume()
            self._current_source_id = self._client.get_input()
            self._source_list = {}
            self._app_list = {}

            custom_sources = []
            for source in self._customize.get(CONF_SOURCES, []):
                app_id = WEBOS_APPS_SHORT.get(source, None)
                if app_id:
                    custom_sources.append(app_id)
                else:
                    custom_sources.append(source)

            for app in self._client.get_apps():
                self._app_list[app['id']] = app
                if app['id'] == self._current_source_id:
                    self._current_source = app['title']
                    self._source_list[app['title']] = app
                if app['id'] in custom_sources:
                    self._source_list[app['title']] = app

            for source in self._client.get_inputs():
                if not source['connected']:
                    continue
                app = self._app_list[source['appId']]
                self._source_list[app['title']] = app

        except OSError:
            self._state = STATE_OFF

    @property
    def name(self):
        """Return the name of the device."""
        return self._name

    @property
    def state(self):
        """Return the state of the device."""
        return self._state

    @property
    def is_volume_muted(self):
        """Boolean if volume is currently muted."""
        return self._muted

    @property
    def volume_level(self):
        """Volume level of the media player (0..1)."""
        return self._volume / 100.0

    @property
    def source(self):
        """Return the current input source."""
        return self._current_source

    @property
    def source_list(self):
        """List of available input sources."""
        return sorted(self._source_list.keys())

    @property
    def media_content_type(self):
        """Content type of current playing media."""
        return MEDIA_TYPE_CHANNEL

    @property
    def media_image_url(self):
        """Image url of current playing media."""
        if self._current_source_id in self._app_list:
            return self._app_list[self._current_source_id]['largeIcon']
#.........这里部分代码省略.........
开发者ID:Bart274,项目名称:home-assistant,代码行数:101,代码来源:webostv.py

示例12: LgWebOSDevice

class LgWebOSDevice(MediaPlayerDevice):
    """Representation of a LG WebOS TV."""

    def __init__(self, host, mac, name, customize, config):
        """Initialize the webos device."""
        from pylgtv import WebOsClient
        from wakeonlan import wol
        self._client = WebOsClient(host, config)
        self._wol = wol
        self._mac = mac
        self._customize = customize

        self._name = name
        # Assume that the TV is not muted
        self._muted = False
        # Assume that the TV is in Play mode
        self._playing = True
        self._volume = 0
        self._current_source = None
        self._current_source_id = None
        self._state = STATE_UNKNOWN
        self._source_list = {}
        self._app_list = {}

    @util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
    def update(self):
        """Retrieve the latest data."""
        from websockets.exceptions import ConnectionClosed
        try:
            current_input = self._client.get_input()
            if current_input is not None:
                self._current_source_id = current_input
                if self._state in (STATE_UNKNOWN, STATE_OFF):
                    self._state = STATE_PLAYING
            else:
                self._state = STATE_OFF
                self._current_source = None
                self._current_source_id = None

            if self._state is not STATE_OFF:
                self._muted = self._client.get_muted()
                self._volume = self._client.get_volume()

                self._source_list = {}
                self._app_list = {}
                conf_sources = self._customize.get(CONF_SOURCES, [])

                for app in self._client.get_apps():
                    self._app_list[app['id']] = app
                    if conf_sources:
                        if app['id'] == self._current_source_id:
                            self._current_source = app['title']
                            self._source_list[app['title']] = app
                        elif (app['id'] in conf_sources or
                              any(word in app['title']
                                  for word in conf_sources) or
                              any(word in app['id']
                                  for word in conf_sources)):
                            self._source_list[app['title']] = app
                    else:
                        self._current_source = app['title']
                        self._source_list[app['title']] = app

                for source in self._client.get_inputs():
                    if conf_sources:
                        if source['id'] == self._current_source_id:
                            self._source_list[source['label']] = source
                        elif (source['label'] in conf_sources or
                              any(source['label'].find(word) != -1
                                  for word in conf_sources)):
                            self._source_list[source['label']] = source
                    else:
                        self._source_list[source['label']] = source
        except (OSError, ConnectionClosed, TypeError,
                asyncio.TimeoutError):
            self._state = STATE_OFF
            self._current_source = None
            self._current_source_id = None

    @property
    def name(self):
        """Return the name of the device."""
        return self._name

    @property
    def state(self):
        """Return the state of the device."""
        return self._state

    @property
    def is_volume_muted(self):
        """Boolean if volume is currently muted."""
        return self._muted

    @property
    def volume_level(self):
        """Volume level of the media player (0..1)."""
        return self._volume / 100.0

    @property
#.........这里部分代码省略.........
开发者ID:Khabi,项目名称:home-assistant,代码行数:101,代码来源:webostv.py


注:本文中的pylgtv.WebOsClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。