fix(media_player): the adb_command participant registry key is computed once at registration and stored on the entity — add/remove always match (F4)
This commit is contained in:
1 parent
c44c2c2170
commit
b37a14b920
5 files changed
+147
-60
No files matched your search
@@ -31,6 +31,7 @@ ENTITIES_STUB_NAMES = (
|
||||
"nsh.power",
|
||||
"nsh.jellyfin",
|
||||
"nsh.media_player",
|
||||
"nsh.diagnostics",
|
||||
"nsh.remote",
|
||||
)
|
||||
|
||||
@@ -206,12 +207,12 @@ def load_entity_modules() -> dict:
|
||||
install()
|
||||
from conftest import _SHIELD_DIR, _load_module
|
||||
|
||||
for name in ("helpers", "power", "jellyfin", "media_player", "remote"):
|
||||
for name in ("helpers", "power", "jellyfin", "media_player", "remote", "diagnostics"):
|
||||
if f"nsh.{name}" not in sys.modules:
|
||||
_load_module(f"nsh.{name}", _SHIELD_DIR / f"{name}.py")
|
||||
return {
|
||||
name: sys.modules[f"nsh.{name}"]
|
||||
for name in ("power", "jellyfin", "media_player", "remote")
|
||||
for name in ("power", "jellyfin", "media_player", "remote", "diagnostics")
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -724,6 +724,47 @@ class TestAdbCommandService:
|
||||
assert not player.hass.services.has_service("nvidia_shield", "adb_command")
|
||||
|
||||
|
||||
class TestServiceRegistryKey:
|
||||
"""F4: the participant key is computed once — add/remove always match."""
|
||||
|
||||
async def test_late_entity_id_assignment_still_removes(self, modules):
|
||||
import entity_stublib
|
||||
from nsh.media_player import (
|
||||
_ADB_COMMAND_TARGETS,
|
||||
_adb_command_service_ensure,
|
||||
_adb_command_service_maybe_remove,
|
||||
)
|
||||
|
||||
mods = load_entity_modules()
|
||||
player, _s, _i = make_player(mods)
|
||||
player._entry.options["adb_command_enabled"] = True
|
||||
player._attr_unique_id = "uid_late"
|
||||
# no entity_id yet at registration (HA core assigns it right after)
|
||||
player.hass = entity_stublib.FakeHass()
|
||||
player.hass.services = FakeServices()
|
||||
if hasattr(player, "_adb_command_key"):
|
||||
del player._adb_command_key # start clean
|
||||
|
||||
# add path — the key is computed once from unique_id
|
||||
key = (
|
||||
getattr(player, "entity_id", None) or player._attr_unique_id
|
||||
)
|
||||
player._adb_command_key = key
|
||||
_ADB_COMMAND_TARGETS[key] = player._manager
|
||||
_adb_command_service_ensure(player.hass)
|
||||
assert "uid_late" in _ADB_COMMAND_TARGETS
|
||||
|
||||
# HA core assigned the entity_id afterwards — removal must still match
|
||||
player.entity_id = "media_player.shield_test"
|
||||
_adb_command_service_maybe_remove(player.hass)
|
||||
assert "uid_late" in _ADB_COMMAND_TARGETS # service stays until unload
|
||||
|
||||
# removal uses the stored key (does not consult the new entity_id)
|
||||
_ADB_COMMAND_TARGETS.pop(player._adb_command_key)
|
||||
_adb_command_service_maybe_remove(player.hass)
|
||||
assert not player.hass.services.has_service("nvidia_shield", "adb_command")
|
||||
|
||||
|
||||
class TestEntryDiagnostics:
|
||||
"""P4-2b: redacted entry diagnostics with store + transport health."""
|
||||
|
||||
@@ -746,7 +787,7 @@ class TestEntryDiagnostics:
|
||||
manager.store.set("awake", True)
|
||||
entry.runtime_data = manager
|
||||
|
||||
from nsh.media_player import async_get_config_entry_diagnostics
|
||||
from nsh.diagnostics import async_get_config_entry_diagnostics
|
||||
|
||||
payload = await async_get_config_entry_diagnostics(None, entry)
|
||||
|
||||
|
||||
Reference in new issue
Block a user