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
@@ -151,7 +151,7 @@ class FakeConfigEntries:
|
||||
def async_update_entry(self, entry, **kwargs):
|
||||
self.updating_entry_calls.append((entry, kwargs))
|
||||
for key, value in kwargs.items():
|
||||
if key in ("options", "data"):
|
||||
if key in ("options", "data", "unique_id"):
|
||||
setattr(entry, key, value)
|
||||
|
||||
def async_schedule_reload(self, entry_id):
|
||||
@@ -374,6 +374,88 @@ def _cmd_player(modules):
|
||||
return player, None, None
|
||||
|
||||
|
||||
class TestLegacyUniqueIdMigration:
|
||||
"""P5-1: one-time legacy androidtv-entity-id unique_id migration."""
|
||||
|
||||
def _entry_module(self):
|
||||
import entity_stublib
|
||||
|
||||
entity_stublib.install()
|
||||
if "nsh.media_player" not in sys.modules:
|
||||
entity_stublib.load_entity_modules()
|
||||
return sys.modules["nsh.media_player"]
|
||||
|
||||
async def test_migrates_to_entry_id_without_protocol(self, tmp_path):
|
||||
import entity_stublib
|
||||
|
||||
entity_stublib.load_entity_modules()
|
||||
modules = sys.modules["nsh.media_player"]
|
||||
from types import SimpleNamespace as MigrationEntry
|
||||
|
||||
hass = FakeHass(str(tmp_path))
|
||||
entry = MigrationEntry(
|
||||
entry_id="cfgid123",
|
||||
data={CONF_ANDROIDTV_ENTITY: "media_player.shield"},
|
||||
options={},
|
||||
title="Shield",
|
||||
unique_id="media_player.shield", # legacy
|
||||
runtime_data=None,
|
||||
)
|
||||
|
||||
await modules._migrate_legacy_unique_id(hass, entry)
|
||||
|
||||
assert entry.unique_id == "cfgid123" # config-entry id fallback
|
||||
|
||||
async def test_migrates_to_protocol_mac_when_resolvable(self, tmp_path):
|
||||
import entity_stublib
|
||||
|
||||
entity_stublib.load_entity_modules()
|
||||
modules = sys.modules["nsh.media_player"]
|
||||
from types import SimpleNamespace as MigrationEntry
|
||||
|
||||
hass = FakeHass(str(tmp_path))
|
||||
entry = MigrationEntry(
|
||||
entry_id="cfgid123",
|
||||
data={CONF_ANDROIDTV_ENTITY: "media_player.shield"},
|
||||
options={},
|
||||
title="Shield",
|
||||
unique_id="media_player.shield",
|
||||
runtime_data=None,
|
||||
)
|
||||
|
||||
class _Manager:
|
||||
async def async_protocol_device_info(self):
|
||||
return "Shield TV", "aa:bb:cc:dd:ee:ff"
|
||||
|
||||
entry.runtime_data = _Manager()
|
||||
|
||||
await modules._migrate_legacy_unique_id(hass, entry)
|
||||
|
||||
assert entry.unique_id == "aa:bb:cc:dd:ee:ff" # MAC preferred
|
||||
|
||||
async def test_never_runs_twice_for_a_migrated_entry(self, tmp_path):
|
||||
"""The legacy pattern no longer matches after the one-time move."""
|
||||
import entity_stublib
|
||||
|
||||
entity_stublib.load_entity_modules()
|
||||
modules = sys.modules["nsh.media_player"]
|
||||
from types import SimpleNamespace as MigrationEntry
|
||||
|
||||
hass = FakeHass(str(tmp_path))
|
||||
entry = MigrationEntry(
|
||||
entry_id="cfgid123",
|
||||
data={CONF_ANDROIDTV_ENTITY: "media_player.shield"},
|
||||
options={},
|
||||
title="Shield",
|
||||
unique_id="aa:bb:cc:dd:ee:ff", # already migrated
|
||||
runtime_data=None,
|
||||
)
|
||||
|
||||
await modules._migrate_legacy_unique_id(hass, entry)
|
||||
|
||||
assert hass.config_entries.updating_entry_calls == [] # untouched
|
||||
|
||||
|
||||
class TestZeroconfDiscovery:
|
||||
"""P4-1a: _androidtvremote2._tcp discovery → pre-filled user step."""
|
||||
|
||||
|
||||
Reference in new issue
Block a user