From 17648f43c981466c26a2a59f7045a03faf77f27e Mon Sep 17 00:00:00 2001 From: James Mackay Date: Thu, 8 Oct 2026 11:22:23 +0100 Subject: [PATCH] =?UTF-8?q?fix(media=5Fplayer):=20store=20the=20computed?= =?UTF-8?q?=20adb=5Fcommand=20participant=20key=20on=20the=20entity=20?= =?UTF-8?q?=E2=80=94=20completes=20the=20F4=20add/remove=20key=20symmetry?= =?UTF-8?q?=20in=20the=20lifecycle=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nvidia_shield/media_player.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/custom_components/nvidia_shield/media_player.py b/custom_components/nvidia_shield/media_player.py index 8396b9d..9a8ee94 100644 --- a/custom_components/nvidia_shield/media_player.py +++ b/custom_components/nvidia_shield/media_player.py @@ -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)