feat(media_player): app_id/app_name prefer the androidtv entity, fall back to the protocol current_app push when absent/unavailable; manifest androidtvremote2 floor aligned to >=0.2.0 (P3-1b,c)

This commit is contained in:
James Mackay committed 2026-10-08 10:28:56 +01:00
1 parent d35b61078d
commit 34d09e9f70
3 files changed
+59 -6

No files matched your search

+38
View File
@@ -342,6 +342,44 @@ class TestRemoteEntity:
assert protocol.key_calls == []
class TestAppFallback:
async def test_app_id_prefers_the_androidtv_entity(self, modules):
player, _s, _i = make_player(modules)
player._androidtv_entity = "media_player.atv"
from types import SimpleNamespace as FakeState
state = FakeState(attributes={"app_id": "com.plex.hdx", "app_name": "Plex"})
states = FakeState(states=FakeState(
get=lambda eid: state if eid == "media_player.atv" else None
))
player.hass = states
player._read = lambda eid: state if eid == "media_player.atv" else None
assert player.app_id == "com.plex.hdx"
assert player.app_name == "Plex"
async def test_app_falls_back_to_protocol_current_app(self, modules):
player, _s, _i = make_player(modules)
player._androidtv_entity = "" # standalone setup (P3-1)
player._manager._on_current_app("com.netflix.ninja")
await asyncio.sleep(0.05) # drain the call_soon_threadsafe push
assert player.app_id == "com.netflix.ninja"
assert player.app_name == "com.netflix.ninja" # package is truth; map later
async def test_app_unavailable_entity_falls_back(self, modules):
player, _s, _i = make_player(modules)
player._androidtv_entity = "media_player.atv"
from types import SimpleNamespace as FakeState
player.hass = FakeState(states=FakeState(get=lambda eid: None)) # entity gone
player._read = lambda eid: None
player._manager._on_current_app("com.google.android.youtube.tv")
await asyncio.sleep(0.05)
assert player.app_id == "com.google.android.youtube.tv"
class TestVolumeAndPowerLadder:
async def test_volume_readout_from_protocol_push(self, modules):
player, served, _intents = make_player(modules)