importChannelSet

suspend fun importChannelSet(channelSet: ChannelSet, radioController: RadioController, radioConfigRepository: RadioConfigRepository)(source)

Imports a ChannelSet as an authoritative REPLACE: writes every channel and — when present and actually different — the imported LoRa config, all inside one RadioController.editLocalSettings transaction, then replaces the local channel cache.

Reads the current LoRa config and channel set from radioConfigRepository's flows (avoiding the StateFlow placeholder window) and builds the shared authoritative replacement plan. The edit-settings transaction defers disk persistence, radio reload/reconfiguration, and reboot until the closing commit, so channels + LoRa land in a single reboot with no per-slot reconfigure to pace against. (Firmware still writes each set_channel into its in-memory channel table as it arrives — the transaction is not a full staging of channel state — but the expensive persist/reload path runs once at commit.) Writing LoRa inside the same session mirrors InstallProfileUseCase and is why the old pre/post settle delays are gone: the begin/commit boundary is the settle.

The local caches are commit-shaped: transactional channel writes deliberately do not mirror per slot (see AdminControllerImpl.EditSettingsSession.setChannel), while transactional setConfig stages its LoRa projection until commit acceptance. This function replaces the cached channel list only after the edit session succeeds, so an import that fails at a transaction boundary leaves both channel and LoRa cache state describing the last committed device configuration. The post-commit RadioConfigRepository.updateChannelSet call updates the normalized settings and imported LoRa config together; an import without LoRa preserves the cached LoRa config. Cancellation during editLocalSettings can leave a committed transaction without running the cache replacement, so the cache lags the device until the next config read. Cancellation after the edit returns does not skip replacement because that final cache update runs under NonCancellable.

Imported settings are normalized before any write or bounds check, so blank placeholder secondaries and semantic duplicates never reach the radio or the local cache.

Parameters

channelSet

The imported ChannelSet to apply as a replacement. Its lora_config, if present and different from the device's current LoRa config, is written inside the same transaction.

radioController

The RadioController used to run the edit transaction.

radioConfigRepository

The RadioConfigRepository providing the current channel/LoRa flows and cache.