applyReplacementChannelSet

suspend fun applyReplacementChannelSet(channelSet: ChannelSet, radioController: RadioController, radioConfigRepository: RadioConfigRepository, writeDelay: Duration = CHANNEL_REPLACEMENT_WRITE_DELAY, delayFn: suspend (Duration) -> Unit = { delay(it) }): Config.LoRaConfig?(source)

Applies an imported ChannelSet as an authoritative replacement to the radio and local cache.

Reads the current LoRa config and channel set from radioConfigRepository's flows (avoiding the StateFlow placeholder window), builds the authoritative replacement list via getChannelReplacementList, enqueues each channel write to the radio via radioController, pauses between writes so the radio can persist and reconfigure each slot, then atomically replaces the local cached settings.

setLocalChannel returns once the packet is enqueued, not after firmware ACK. The pacing avoids enqueueing a complete channel replacement plus LoRa reconfiguration faster than real hardware can materialize the later channel slots. If the sequence is interrupted after one or more successful writes, the local cache is reconciled to the successfully enqueued channel settings before the original cancellation or failure continues.

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

Does NOT handle LoRa config — callers are responsible for comparing and sending lora_config if present.

Return

The device's current LoRa config snapshot used by callers to compare against an imported LoRa config.

Parameters

channelSet

The imported ChannelSet to apply as a replacement.

radioController

The RadioController used to enqueue channel writes.

radioConfigRepository

The RadioConfigRepository providing the current channel flow and cache.

writeDelay

Delay after each channel write. Exposed for fast unit tests.

delayFn

Delay implementation. Exposed for fast unit tests.