mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
optimize remote calls and apps on webostv media_player (#7191)
* - changed updater to only do updated if they succed and handle calls when tv is off better by only doing 1 remote call - show all sources instead of only connected, to fix source selection when unit is powered off - fixed sources so they can launch apps and select sources * fixed lint errors * show all sources and apps if no custom options are defined in the conf * fixed indentation for lint * set _current_source when state is off and fixed timeout exception
This commit is contained in:
parent
955e3e0542
commit
8df5de2bb8
@ -173,34 +173,55 @@ class LgWebOSDevice(MediaPlayerDevice):
|
||||
"""Retrieve the latest data."""
|
||||
from websockets.exceptions import ConnectionClosed
|
||||
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 = {}
|
||||
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
|
||||
|
||||
custom_sources = self._customize.get(CONF_SOURCES, [])
|
||||
if self._state is not STATE_OFF:
|
||||
self._muted = self._client.get_muted()
|
||||
self._volume = self._client.get_volume()
|
||||
|
||||
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 (app['id'] in custom_sources or
|
||||
any(word in app['title'] for word in custom_sources) or
|
||||
any(word in app['id'] for word in custom_sources)):
|
||||
self._source_list[app['title']] = app
|
||||
self._source_list = {}
|
||||
self._app_list = {}
|
||||
conf_sources = self._customize.get(CONF_SOURCES, [])
|
||||
|
||||
for source in self._client.get_inputs():
|
||||
if not source['connected']:
|
||||
continue
|
||||
app = self._app_list[source['appId']]
|
||||
self._source_list[app['title']] = app
|
||||
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):
|
||||
@ -296,9 +317,14 @@ class LgWebOSDevice(MediaPlayerDevice):
|
||||
|
||||
def select_source(self, source):
|
||||
"""Select input source."""
|
||||
self._current_source_id = self._source_list[source]['id']
|
||||
self._current_source = self._source_list[source]['title']
|
||||
self._client.launch_app(self._source_list[source]['id'])
|
||||
if self._source_list.get(source).get('title'):
|
||||
self._current_source_id = self._source_list[source]['id']
|
||||
self._current_source = self._source_list[source]['title']
|
||||
self._client.launch_app(self._source_list[source]['id'])
|
||||
elif self._source_list.get(source).get('label'):
|
||||
self._current_source_id = self._source_list[source]['id']
|
||||
self._current_source = self._source_list[source]['label']
|
||||
self._client.set_input(self._source_list[source]['id'])
|
||||
|
||||
def media_play(self):
|
||||
"""Send play command."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user