mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Fix webostv restored supported features turn on (#66318)
* Fix webostv restored supported features turn on * Remove ternary operator expression
This commit is contained in:
parent
7a40ae13a4
commit
89b20b9133
@ -326,7 +326,10 @@ class LgWebOSMediaPlayerEntity(RestoreEntity, MediaPlayerEntity):
|
|||||||
def supported_features(self) -> int:
|
def supported_features(self) -> int:
|
||||||
"""Flag media player features that are supported."""
|
"""Flag media player features that are supported."""
|
||||||
if self.state == STATE_OFF and self._supported_features is not None:
|
if self.state == STATE_OFF and self._supported_features is not None:
|
||||||
return self._supported_features
|
if self._wrapper.turn_on:
|
||||||
|
return self._supported_features | SUPPORT_TURN_ON
|
||||||
|
|
||||||
|
return self._supported_features & ~SUPPORT_TURN_ON
|
||||||
|
|
||||||
supported = SUPPORT_WEBOSTV
|
supported = SUPPORT_WEBOSTV
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ from homeassistant.const import (
|
|||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import State
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import device_registry
|
from homeassistant.helpers import device_registry
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
@ -67,7 +68,7 @@ from homeassistant.util import dt
|
|||||||
from . import setup_webostv
|
from . import setup_webostv
|
||||||
from .const import CHANNEL_2, ENTITY_ID, TV_NAME
|
from .const import CHANNEL_2, ENTITY_ID, TV_NAME
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed, mock_restore_cache
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -562,14 +563,27 @@ async def test_cached_supported_features(hass, client, monkeypatch):
|
|||||||
"""Test test supported features."""
|
"""Test test supported features."""
|
||||||
monkeypatch.setattr(client, "is_on", False)
|
monkeypatch.setattr(client, "is_on", False)
|
||||||
monkeypatch.setattr(client, "sound_output", None)
|
monkeypatch.setattr(client, "sound_output", None)
|
||||||
|
supported = SUPPORT_WEBOSTV | SUPPORT_WEBOSTV_VOLUME | SUPPORT_TURN_ON
|
||||||
|
mock_restore_cache(
|
||||||
|
hass,
|
||||||
|
[
|
||||||
|
State(
|
||||||
|
ENTITY_ID,
|
||||||
|
STATE_OFF,
|
||||||
|
attributes={
|
||||||
|
ATTR_SUPPORTED_FEATURES: supported,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
await client.mock_state_update()
|
await client.mock_state_update()
|
||||||
|
|
||||||
# TV off, support volume mute, step, set
|
# TV off, restored state supports mute, step
|
||||||
supported = SUPPORT_WEBOSTV | SUPPORT_WEBOSTV_VOLUME | SUPPORT_VOLUME_SET
|
# validate SUPPORT_TURN_ON is not cached
|
||||||
attrs = hass.states.get(ENTITY_ID).attributes
|
attrs = hass.states.get(ENTITY_ID).attributes
|
||||||
|
|
||||||
assert attrs[ATTR_SUPPORTED_FEATURES] == supported
|
assert attrs[ATTR_SUPPORTED_FEATURES] == supported & ~SUPPORT_TURN_ON
|
||||||
|
|
||||||
# TV on, support volume mute, step
|
# TV on, support volume mute, step
|
||||||
monkeypatch.setattr(client, "is_on", True)
|
monkeypatch.setattr(client, "is_on", True)
|
||||||
@ -601,7 +615,7 @@ async def test_cached_supported_features(hass, client, monkeypatch):
|
|||||||
|
|
||||||
assert attrs[ATTR_SUPPORTED_FEATURES] == supported
|
assert attrs[ATTR_SUPPORTED_FEATURES] == supported
|
||||||
|
|
||||||
# TV off, support volume mute, step, step, set
|
# TV off, support volume mute, step, set
|
||||||
monkeypatch.setattr(client, "is_on", False)
|
monkeypatch.setattr(client, "is_on", False)
|
||||||
monkeypatch.setattr(client, "sound_output", None)
|
monkeypatch.setattr(client, "sound_output", None)
|
||||||
await client.mock_state_update()
|
await client.mock_state_update()
|
||||||
@ -610,3 +624,31 @@ async def test_cached_supported_features(hass, client, monkeypatch):
|
|||||||
attrs = hass.states.get(ENTITY_ID).attributes
|
attrs = hass.states.get(ENTITY_ID).attributes
|
||||||
|
|
||||||
assert attrs[ATTR_SUPPORTED_FEATURES] == supported
|
assert attrs[ATTR_SUPPORTED_FEATURES] == supported
|
||||||
|
|
||||||
|
# Test support turn on is updated on cached state
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
automation.DOMAIN,
|
||||||
|
{
|
||||||
|
automation.DOMAIN: [
|
||||||
|
{
|
||||||
|
"trigger": {
|
||||||
|
"platform": "webostv.turn_on",
|
||||||
|
"entity_id": ENTITY_ID,
|
||||||
|
},
|
||||||
|
"action": {
|
||||||
|
"service": "test.automation",
|
||||||
|
"data_template": {
|
||||||
|
"some": ENTITY_ID,
|
||||||
|
"id": "{{ trigger.id }}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await client.mock_state_update()
|
||||||
|
|
||||||
|
attrs = hass.states.get(ENTITY_ID).attributes
|
||||||
|
|
||||||
|
assert attrs[ATTR_SUPPORTED_FEATURES] == supported | SUPPORT_TURN_ON
|
||||||
|
Loading…
x
Reference in New Issue
Block a user