feat:init,config_flow: YAML seed-only setup — an optional nvidia_shield block starts interactive SOURCE_IMPORT flows (parsed in async_setup), the import step guards duplicates by host/MAC-virtual unique_id and never re-seeds UI-configured hosts, protocol fields are prefill hints only (t30 U1)
This commit is contained in:
1 parent
2e70587871
commit
a6eeae86e9
2 files changed
+97
-5
No files matched your search
@@ -471,6 +471,54 @@ class NvidiaShieldConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_import(self, data):
|
||||
"""Seed an interactive flow from YAML (t30 U1, seed-only ruling).
|
||||
|
||||
The import validates the block and routes into the standard user
|
||||
flow — pairing stays interactive, exactly one visit. Duplicate
|
||||
guards: the block's host/MAC-virtual unique_id aborts when an
|
||||
entry already holds it, and a UI-configured entry with the same
|
||||
protocol/adb host is never re-seeded.
|
||||
"""
|
||||
block = dict(data or {})
|
||||
name = block.get("name") or DEFAULT_NAME
|
||||
seed_unique_id = block.get("unique_id")
|
||||
if not seed_unique_id:
|
||||
host = block.get(CONF_ADB_HOST) or block.get(CONF_PROTOCOL_HOST)
|
||||
seed_unique_id = f"yaml:{name}:{host or 'nohost'}"
|
||||
|
||||
# duplicate guards
|
||||
yhost = block.get(CONF_ADB_HOST) or block.get(CONF_PROTOCOL_HOST)
|
||||
for existing in self.hass.config_entries.async_entries():
|
||||
ehost = existing.options.get(CONF_PROTOCOL_HOST) or existing.options.get(
|
||||
CONF_ADB_HOST
|
||||
)
|
||||
if existing.unique_id == seed_unique_id or (
|
||||
yhost and ehost == yhost
|
||||
):
|
||||
_LOGGER.info(
|
||||
"nvidia_shield YAML seed for %r matches an existing "
|
||||
"entry — not re-seeded",
|
||||
name,
|
||||
)
|
||||
return self.async_abort(reason="already_configured")
|
||||
await self.async_set_unique_id(seed_unique_id)
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
# route into the standard user flow (single interactive visit)
|
||||
self._user_data = {
|
||||
"name": name,
|
||||
CONF_ADB_ENABLED: True,
|
||||
CONF_ADB_HOST: block.get(CONF_ADB_HOST, ""),
|
||||
CONF_ADB_PORT: block.get(CONF_ADB_PORT, DEFAULT_ADB_PORT),
|
||||
# protocol prefill hints ONLY (pairing stays interactive)
|
||||
CONF_PROTOCOL_HOST: block.get(CONF_PROTOCOL_HOST, ""),
|
||||
}
|
||||
self._discovered_host = self._user_data[CONF_PROTOCOL_HOST] or self._user_data[
|
||||
CONF_ADB_HOST
|
||||
]
|
||||
return await self.async_step_user(None)
|
||||
|
||||
async def async_step_reauth(self, entry_data):
|
||||
"""Device hard reset invalidated our certificates (review trigger)."""
|
||||
self._reauth_entry = self.hass.config_entries.async_get_entry(
|
||||
|
||||
Reference in new issue
Block a user