fix(config_flow): no_state_source fires only when none of the three sources is present — ADB-only standalone is valid; strings/docs name all three (F2)
This commit is contained in:
1 parent
3b8e97fe5b
commit
ce90f59f8e
5 files changed
+54
-6
No files matched your search
@@ -79,6 +79,11 @@ TiviMate (`ar.tvplayer.tv`) is the documented no-session case: it publishes
|
||||
no MediaSession on Shield Android 11 (RESEARCH_SHIELD R2), so tiers 6–7 plus
|
||||
the audio hint are what keep it visible.
|
||||
|
||||
**Standalone setup** accepts any one of the three state sources — the Android
|
||||
TV Remote entity, the Nvidia Remote Protocol (PIN pairing), or ADB
|
||||
media-session mode (ADB enabled + host). The `no_state_source` form error
|
||||
fires only when none of the three is present; ADB-only setups are valid.
|
||||
|
||||
### Migration from mediasession2mqtt + universal-player glue
|
||||
|
||||
The `mediasession2mqtt` bridge sensors and the universal media player YAML
|
||||
|
||||
@@ -128,15 +128,24 @@ class NvidiaShieldConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self._reauth_entry = None
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Step 1: Basic setup."""
|
||||
"""Step 1: Basic setup.
|
||||
|
||||
Standalone setup (Phase 3): any one of the three state sources is
|
||||
enough — the Android TV Remote entity, the Nvidia Remote Protocol
|
||||
(pairing), or ADB media-session mode (CONF_ADB_ENABLED). The
|
||||
``no_state_source`` error fires only when none of them is present.
|
||||
"""
|
||||
errors = {}
|
||||
|
||||
if user_input is not None:
|
||||
# Standalone setup (Phase 3): the external androidtv media_player
|
||||
# is optional — the protocol push can be the only state source.
|
||||
androidtv_entity = user_input.get(CONF_ANDROIDTV_ENTITY)
|
||||
|
||||
if not androidtv_entity and not user_input.get(CONF_PROTOCOL_ENABLED):
|
||||
has_source = (
|
||||
bool(androidtv_entity)
|
||||
or bool(user_input.get(CONF_PROTOCOL_ENABLED))
|
||||
or bool(user_input.get(CONF_ADB_ENABLED))
|
||||
)
|
||||
if not has_source:
|
||||
errors["base"] = "no_state_source"
|
||||
sel = _build_selectors()
|
||||
return self.async_show_form(
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
"protocol_no_host": "Could not determine the Shield's IP address. Set the Protocol Host or ADB Host field.",
|
||||
"protocol_invalid_code": "Pairing has not started or the code is empty. Click Submit to retry.",
|
||||
"protocol_pair_failed": "The Shield rejected that pairing code. Click Submit to try again.",
|
||||
"no_state_source": "No state source selected. Link the Android TV Remote entity or enable the Nvidia Remote Protocol pairing \u2014 the integration needs at least one source of power/app state."
|
||||
"no_state_source": "No state source selected. Provide at least one of: the Android TV Remote entity, the Nvidia Remote Protocol pairing, or ADB media-session mode (enable ADB and set the ADB Host)."
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "This Shield entity is already configured.",
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
"protocol_no_host": "Could not determine the Shield's IP address. Set the Protocol Host or ADB Host field.",
|
||||
"protocol_invalid_code": "Pairing has not started or the code is empty. Click Submit to retry.",
|
||||
"protocol_pair_failed": "The Shield rejected that pairing code. Click Submit to try again.",
|
||||
"no_state_source": "No state source selected. Link the Android TV Remote entity or enable the Nvidia Remote Protocol pairing \u2014 the integration needs at least one source of power/app state."
|
||||
"no_state_source": "No state source selected. Provide at least one of: the Android TV Remote entity, the Nvidia Remote Protocol pairing, or ADB media-session mode (enable ADB and set the ADB Host)."
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "This Shield entity is already configured.",
|
||||
|
||||
@@ -256,6 +256,40 @@ class TestStandaloneValidation:
|
||||
assert CONF_ANDROIDTV_ENTITY not in result["data"]
|
||||
|
||||
|
||||
class TestAdbOnlyStandalone:
|
||||
async def test_adb_only_standalone_is_valid(self, tmp_path):
|
||||
"""F2: ADB media-session mode is a third accepted state source."""
|
||||
module = _form_module()
|
||||
flow = module.NvidiaShieldConfigFlow()
|
||||
flow.hass = FakeHass(str(tmp_path))
|
||||
|
||||
result = await flow.async_step_user(
|
||||
_user_input(
|
||||
**{
|
||||
CONF_ANDROIDTV_ENTITY: "",
|
||||
CONF_PROTOCOL_ENABLED: False,
|
||||
"adb_enabled": True,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
# routed into ADB pairing — no no_state_source error
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "adb_pair"
|
||||
assert result["errors"] == {}
|
||||
|
||||
async def test_error_still_fires_with_no_source_at_all(self, tmp_path):
|
||||
module = _form_module()
|
||||
flow = module.NvidiaShieldConfigFlow()
|
||||
flow.hass = FakeHass(str(tmp_path))
|
||||
|
||||
result = await flow.async_step_user(
|
||||
_user_input(**{CONF_ANDROIDTV_ENTITY: "", "adb_enabled": False})
|
||||
)
|
||||
|
||||
assert result["errors"] == {"base": "no_state_source"}
|
||||
|
||||
|
||||
class TestMigrationKeepsOrAllowsAbsence:
|
||||
async def test_v1_to_v2_keeps_the_androidtv_field(self, tmp_path):
|
||||
module = _entry_module()
|
||||
|
||||
Reference in new issue
Block a user