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:
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
|
# Registered at setup; unregistered at unload when the last
|
||||||
# participating entity goes away.
|
# participating entity goes away.
|
||||||
if self._entry.options.get(CONF_ADB_COMMAND_ENABLED, False):
|
if self._entry.options.get(CONF_ADB_COMMAND_ENABLED, False):
|
||||||
entity_id = getattr(self, "entity_id", None) or self._attr_unique_id
|
# F4: the registry key is computed once and stored on the
|
||||||
_ADB_COMMAND_TARGETS[entity_id] = self._manager
|
# 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)
|
_adb_command_service_ensure(self.hass)
|
||||||
|
|
||||||
# Discover power sensor siblings from the power switch
|
# Discover power sensor siblings from the power switch
|
||||||
@@ -231,9 +236,12 @@ class NvidiaShieldMediaPlayer(MediaPlayerEntity):
|
|||||||
for task in self._entity_tasks:
|
for task in self._entity_tasks:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
self._entity_tasks.clear()
|
self._entity_tasks.clear()
|
||||||
# P4-2a: drop this entity's service participation
|
# P4-2a: drop this entity's service participation (same key as add)
|
||||||
entity_id = getattr(self, "entity_id", None) or self._attr_unique_id
|
if (
|
||||||
if _ADB_COMMAND_TARGETS.pop(entity_id, None) is not None and self.hass:
|
(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)
|
_adb_command_service_maybe_remove(self.hass)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user