fix(media_player): store the computed adb_command participant key on the entity — completes the F4 add/remove key symmetry in the lifecycle hooks

This commit is contained in:
James Mackay committed 2026-10-08 11:22:23 +01:00
1 parent f03ef1f531
commit 17648f43c9
1 file changed
+13 -5
@@ -192,8 +192,13 @@ class NvidiaShieldMediaPlayer(MediaPlayerEntity):
# Registered at setup; unregistered at unload when the last
# participating entity goes away.
if self._entry.options.get(CONF_ADB_COMMAND_ENABLED, False):
entity_id = getattr(self, "entity_id", None) or self._attr_unique_id
_ADB_COMMAND_TARGETS[entity_id] = self._manager
# F4: the registry key is computed once and stored on the
# entity, so add/remove always agree even when entity_id is
# assigned by HA core after the first read.
self._adb_command_key = (
getattr(self, "entity_id", None) or self._attr_unique_id
)
_ADB_COMMAND_TARGETS[self._adb_command_key] = self._manager
_adb_command_service_ensure(self.hass)
# Discover power sensor siblings from the power switch
@@ -231,9 +236,12 @@ class NvidiaShieldMediaPlayer(MediaPlayerEntity):
for task in self._entity_tasks:
task.cancel()
self._entity_tasks.clear()
# P4-2a: drop this entity's service participation
entity_id = getattr(self, "entity_id", None) or self._attr_unique_id
if _ADB_COMMAND_TARGETS.pop(entity_id, None) is not None and self.hass:
# P4-2a: drop this entity's service participation (same key as add)
if (
(key := getattr(self, "_adb_command_key", None)) is not None
and _ADB_COMMAND_TARGETS.pop(key, None) is not None
and self.hass
):
_adb_command_service_maybe_remove(self.hass)