test(ha_adb_common,connection): application-label tolerance (dual quotes, empty multi-label blocks, null, absent) + label cache reuse across cycles — no duplicate pm dump (P5-1)
This commit is contained in:
1 parent
2e6dfd8981
commit
c57a2e2ff2
5 files changed
+204
-1
No files matched your search
@@ -392,6 +392,21 @@ class ShieldConnectionManager:
|
||||
"""
|
||||
return self._protocol is not None
|
||||
|
||||
async def async_protocol_device_info(self) -> tuple[str, str] | None:
|
||||
"""(device name, MAC) via the protocol client (P5-1 migration).
|
||||
|
||||
None when the transport is absent or the lookup fails — callers
|
||||
fall back to the config-entry id.
|
||||
"""
|
||||
if self._protocol is None:
|
||||
return None
|
||||
with contextlib.suppress(Exception):
|
||||
name, mac = await asyncio.wait_for(
|
||||
self._protocol.async_get_name_and_mac(), timeout=10
|
||||
)
|
||||
return name, mac
|
||||
return None
|
||||
|
||||
@property
|
||||
def adb_poller(self):
|
||||
"""The ADB poller (or None) — public accessor replacing the
|
||||
|
||||
@@ -104,6 +104,32 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
async_add_entities([NvidiaShieldMediaPlayer(hass, entry)])
|
||||
# P5-1: one-time legacy unique_id migration (t20 F3 closure)
|
||||
hass.async_create_task(_migrate_legacy_unique_id(hass, entry))
|
||||
|
||||
|
||||
async def _migrate_legacy_unique_id(hass, entry) -> None:
|
||||
"""Migrate legacy androidtv-entity-id unique_ids once (t20 F3).
|
||||
|
||||
Legacy entries carry the androidtv entity id as unique_id; the one-time
|
||||
migration moves it to the protocol MAC when the transport can resolve
|
||||
it, else to the config-entry id. After the single update_entry the
|
||||
legacy pattern no longer matches, so this never runs twice for an
|
||||
entry. No behavior change: the entry's data/options are untouched.
|
||||
"""
|
||||
legacy = entry.data.get(CONF_ANDROIDTV_ENTITY, "")
|
||||
if not legacy or entry.unique_id != legacy:
|
||||
return
|
||||
manager = getattr(entry, "runtime_data", None)
|
||||
new_id = None
|
||||
if manager is not None:
|
||||
info = await manager.async_protocol_device_info()
|
||||
if info is not None:
|
||||
_name, new_id = info
|
||||
if not new_id:
|
||||
new_id = entry.entry_id
|
||||
hass.config_entries.async_update_entry(entry, unique_id=new_id)
|
||||
_LOGGER.info("P5-1: legacy unique_id %r migrated to %r", legacy, new_id)
|
||||
|
||||
|
||||
class NvidiaShieldMediaPlayer(MediaPlayerEntity):
|
||||
|
||||
Reference in new issue
Block a user