From a634e62dfc0edf282d018b7fbc1dc1108aa28572 Mon Sep 17 00:00:00 2001 From: Josh Bendavid Date: Mon, 20 Jan 2020 10:43:20 +0100 Subject: [PATCH] Minor fixes for webostv (#30998) * restore emulation of play pause toggle * add protection to notify setup * add state check for power off to avoid switching tv back on --- .../components/webostv/media_player.py | 17 ++++++++++++++--- homeassistant/components/webostv/notify.py | 3 +++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index b7c8a416870..c523c068bcc 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -118,6 +118,9 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice): self._customize = customize self._on_script = on_script + # Assume that the TV is not paused + self._paused = False + # Assume that the TV is not muted self._muted = False self._volume = 0 @@ -290,7 +293,10 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice): @cmd async def async_turn_off(self): """Turn off media player.""" - await self._client.power_off() + + # in some situations power_off may cause the TV to switch back on + if self._state != STATE_OFF: + await self._client.power_off() async def async_turn_on(self): """Turn on the media player.""" @@ -326,8 +332,11 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice): @cmd async def async_media_play_pause(self): - """Client pause command acts as a play-pause toggle.""" - await self._client.pause() + """Simulate play pause media player.""" + if self._paused: + await self.async_media_play() + else: + await self.async_media_pause() @cmd async def async_select_source(self, source): @@ -379,11 +388,13 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice): @cmd async def async_media_play(self): """Send play command.""" + self._paused = False await self._client.play() @cmd async def async_media_pause(self): """Send media pause command to media player.""" + self._paused = True await self._client.pause() @cmd diff --git a/homeassistant/components/webostv/notify.py b/homeassistant/components/webostv/notify.py index e75fafbfe23..ece76b5ed32 100644 --- a/homeassistant/components/webostv/notify.py +++ b/homeassistant/components/webostv/notify.py @@ -16,6 +16,9 @@ _LOGGER = logging.getLogger(__name__) async def async_get_service(hass, config, discovery_info=None): """Return the notify service.""" + if discovery_info is None: + return None + host = discovery_info.get(CONF_HOST) icon_path = discovery_info.get(CONF_ICON)