mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 00:37:13 +00:00
Cleanup of state handling in webostv (#30416)
* cleanup unnecessary manipulation of state variables * update unit test
This commit is contained in:
parent
4bf15a07a3
commit
4c6e10a988
@ -30,8 +30,7 @@ from homeassistant.const import (
|
|||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
ENTITY_MATCH_ALL,
|
ENTITY_MATCH_ALL,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_PAUSED,
|
STATE_ON,
|
||||||
STATE_PLAYING,
|
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.script import Script
|
from homeassistant.helpers.script import Script
|
||||||
@ -121,8 +120,6 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
|
|||||||
|
|
||||||
# Assume that the TV is not muted
|
# Assume that the TV is not muted
|
||||||
self._muted = False
|
self._muted = False
|
||||||
# Assume that the TV is in Play mode
|
|
||||||
self._playing = True
|
|
||||||
self._volume = 0
|
self._volume = 0
|
||||||
self._current_source = None
|
self._current_source = None
|
||||||
self._current_source_id = None
|
self._current_source_id = None
|
||||||
@ -172,7 +169,7 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
|
|||||||
if self._current_source_id == "":
|
if self._current_source_id == "":
|
||||||
self._state = STATE_OFF
|
self._state = STATE_OFF
|
||||||
else:
|
else:
|
||||||
self._state = STATE_PLAYING
|
self._state = STATE_ON
|
||||||
|
|
||||||
self.update_sources()
|
self.update_sources()
|
||||||
|
|
||||||
@ -325,16 +322,12 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
|
|||||||
@cmd
|
@cmd
|
||||||
async def async_mute_volume(self, mute):
|
async def async_mute_volume(self, mute):
|
||||||
"""Send mute command."""
|
"""Send mute command."""
|
||||||
self._muted = mute
|
|
||||||
await self._client.set_mute(mute)
|
await self._client.set_mute(mute)
|
||||||
|
|
||||||
@cmd
|
@cmd
|
||||||
async def async_media_play_pause(self):
|
async def async_media_play_pause(self):
|
||||||
"""Simulate play pause media player."""
|
"""Client pause command acts as a play-pause toggle."""
|
||||||
if self._playing:
|
await self._client.pause()
|
||||||
await self.media_pause()
|
|
||||||
else:
|
|
||||||
await self.media_play()
|
|
||||||
|
|
||||||
@cmd
|
@cmd
|
||||||
async def async_select_source(self, source):
|
async def async_select_source(self, source):
|
||||||
@ -343,12 +336,9 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
|
|||||||
if source_dict is None:
|
if source_dict is None:
|
||||||
_LOGGER.warning("Source %s not found for %s", source, self.name)
|
_LOGGER.warning("Source %s not found for %s", source, self.name)
|
||||||
return
|
return
|
||||||
self._current_source_id = source_dict["id"]
|
|
||||||
if source_dict.get("title"):
|
if source_dict.get("title"):
|
||||||
self._current_source = source_dict["title"]
|
|
||||||
await self._client.launch_app(source_dict["id"])
|
await self._client.launch_app(source_dict["id"])
|
||||||
elif source_dict.get("label"):
|
elif source_dict.get("label"):
|
||||||
self._current_source = source_dict["label"]
|
|
||||||
await self._client.set_input(source_dict["id"])
|
await self._client.set_input(source_dict["id"])
|
||||||
|
|
||||||
@cmd
|
@cmd
|
||||||
@ -389,15 +379,11 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
|
|||||||
@cmd
|
@cmd
|
||||||
async def async_media_play(self):
|
async def async_media_play(self):
|
||||||
"""Send play command."""
|
"""Send play command."""
|
||||||
self._playing = True
|
|
||||||
self._state = STATE_PLAYING
|
|
||||||
await self._client.play()
|
await self._client.play()
|
||||||
|
|
||||||
@cmd
|
@cmd
|
||||||
async def async_media_pause(self):
|
async def async_media_pause(self):
|
||||||
"""Send media pause command to media player."""
|
"""Send media pause command to media player."""
|
||||||
self._playing = False
|
|
||||||
self._state = STATE_PAUSED
|
|
||||||
await self._client.pause()
|
await self._client.pause()
|
||||||
|
|
||||||
@cmd
|
@cmd
|
||||||
|
@ -21,6 +21,7 @@ from homeassistant.const import (
|
|||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
SERVICE_VOLUME_MUTE,
|
SERVICE_VOLUME_MUTE,
|
||||||
|
STATE_ON,
|
||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
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.services.async_call(media_player.DOMAIN, SERVICE_SELECT_SOURCE, data)
|
||||||
await hass.async_block_till_done()
|
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.launch_app.assert_not_called()
|
||||||
client.set_input.assert_not_called()
|
client.set_input.assert_not_called()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user