Cleanup of state handling in webostv (#30416)

* cleanup unnecessary manipulation of state variables

* update unit test
This commit is contained in:
Josh Bendavid 2020-01-02 20:46:32 -05:00 committed by Martin Hjelmare
parent 4bf15a07a3
commit 4c6e10a988
2 changed files with 6 additions and 19 deletions

View file

@ -30,8 +30,7 @@ from homeassistant.const import (
CONF_NAME,
ENTITY_MATCH_ALL,
STATE_OFF,
STATE_PAUSED,
STATE_PLAYING,
STATE_ON,
)
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.script import Script
@ -121,8 +120,6 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
# 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
@ -172,7 +169,7 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
if self._current_source_id == "":
self._state = STATE_OFF
else:
self._state = STATE_PLAYING
self._state = STATE_ON
self.update_sources()
@ -325,16 +322,12 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
@cmd
async def async_mute_volume(self, mute):
"""Send mute command."""
self._muted = mute
await self._client.set_mute(mute)
@cmd
async def async_media_play_pause(self):
"""Simulate play pause media player."""
if self._playing:
await self.media_pause()
else:
await self.media_play()
"""Client pause command acts as a play-pause toggle."""
await self._client.pause()
@cmd
async def async_select_source(self, source):
@ -343,12 +336,9 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
if source_dict is None:
_LOGGER.warning("Source %s not found for %s", source, self.name)
return
self._current_source_id = source_dict["id"]
if source_dict.get("title"):
self._current_source = source_dict["title"]
await self._client.launch_app(source_dict["id"])
elif source_dict.get("label"):
self._current_source = source_dict["label"]
await self._client.set_input(source_dict["id"])
@cmd
@ -389,15 +379,11 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
@cmd
async def async_media_play(self):
"""Send play command."""
self._playing = True
self._state = STATE_PLAYING
await self._client.play()
@cmd
async def async_media_pause(self):
"""Send media pause command to media player."""
self._playing = False
self._state = STATE_PAUSED
await self._client.pause()
@cmd

View file

@ -21,6 +21,7 @@ from homeassistant.const import (
CONF_HOST,
CONF_NAME,
SERVICE_VOLUME_MUTE,
STATE_ON,
)
from homeassistant.setup import async_setup_component
@ -78,7 +79,7 @@ async def test_select_source_with_empty_source_list(hass, client):
await hass.services.async_call(media_player.DOMAIN, SERVICE_SELECT_SOURCE, data)
await hass.async_block_till_done()
assert hass.states.is_state(ENTITY_ID, "playing")
assert hass.states.is_state(ENTITY_ID, STATE_ON)
client.launch_app.assert_not_called()
client.set_input.assert_not_called()