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


Python WebOsClient.get_muted方法代码示例

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


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

示例1: LgWebOSDevice

# 需要导入模块: from pylgtv import WebOsClient [as 别名]
# 或者: from pylgtv.WebOsClient import get_muted [as 别名]
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,代码行数:103,代码来源:webostv.py

示例2: LgWebOSDevice

# 需要导入模块: from pylgtv import WebOsClient [as 别名]
# 或者: from pylgtv.WebOsClient import get_muted [as 别名]
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:,项目名称:,代码行数:103,代码来源:

示例3: LgWebOSDevice

# 需要导入模块: from pylgtv import WebOsClient [as 别名]
# 或者: from pylgtv.WebOsClient import get_muted [as 别名]
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,代码行数:103,代码来源:webostv.py


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