From 4222027602031217a499782fd5e3bcbb0fef97ca Mon Sep 17 00:00:00 2001 From: James Mackay Date: Thu, 8 Oct 2026 11:03:54 +0100 Subject: [PATCH] feat(const,config_flow): option-gated adb_command service switch (default off) + curated app directory consts + README service/security notes (P4-2) --- .../nvidia_shield/config_flow.py | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/custom_components/nvidia_shield/config_flow.py b/custom_components/nvidia_shield/config_flow.py index 339989f..963513b 100644 --- a/custom_components/nvidia_shield/config_flow.py +++ b/custom_components/nvidia_shield/config_flow.py @@ -13,6 +13,7 @@ from .adb_session import ensure_adb_key from .connection import ShieldConnectionManager from .const import ( ATTR_MEDIA_DAG_INPUT_MAP, + CONF_ADB_COMMAND_ENABLED, CONF_ADB_ENABLED, CONF_ADB_HOST, CONF_ADB_PORT, @@ -279,14 +280,22 @@ class NvidiaShieldConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): for entry in self._async_current_entries(): if getattr(entry, "unique_id", None) != mac: continue - # Known device — update hosts on IP change (core pattern) - options = { - **entry.options, - CONF_PROTOCOL_HOST: host, - CONF_ADB_HOST: host, - } - if options != entry.options: - self.hass.config_entries.async_update_entry(entry, options=options) + # Known device — update hosts only on a real IP change + # (core androidtv_remote pattern, simplified): an explicitly + # configured host that moved to the discovery address. + protocol_host = entry.options.get(CONF_PROTOCOL_HOST, "") + adb_host = entry.options.get(CONF_ADB_HOST, "") + if (protocol_host and protocol_host != host) or ( + adb_host and adb_host != host + ): + self.hass.config_entries.async_update_entry( + entry, + options={ + **entry.options, + CONF_PROTOCOL_HOST: host, + CONF_ADB_HOST: host, + }, + ) self.hass.config_entries.async_schedule_reload(entry.entry_id) return self.async_abort(reason="already_configured") self._abort_if_unique_id_configured() @@ -524,6 +533,10 @@ class NvidiaShieldOptionsFlow(config_entries.OptionsFlow): recv_key = vol.Optional(CONF_RECEIVER_ENTITY, default=recv) schema_dict[recv_key] = sel["receiver"] + # P4-2a: the raw adb_command service is opt-in (default off) + current_flag = self._options.get(CONF_ADB_COMMAND_ENABLED, False) + schema_dict[vol.Optional(CONF_ADB_COMMAND_ENABLED, default=current_flag)] = bool + # Receiver input — dropdown from DAG if receiver is set, text otherwise current_input = self._options.get(CONF_RECEIVER_INPUT, "") receiver = self._options.get(CONF_RECEIVER_ENTITY)