diff --git a/Sources/HAP/Server/Device.swift b/Sources/HAP/Server/Device.swift index 354bbbd9..5d09194b 100644 --- a/Sources/HAP/Server/Device.swift +++ b/Sources/HAP/Server/Device.swift @@ -317,6 +317,16 @@ public class Device { return pairingState == .paired } + // Remove all the pairings made with this Device + // Can be used in the event of a stale configuration file + public func removeAllPairings() { + logger.debug("Removing all pairings") + let allPairingIdentifiers = configuration.pairings.keys + for identifier in allPairingIdentifiers { + remove(pairingWithIdentifier: identifier) + } + } + // Add the pairing to the internal DB and notify the change // to update the Bonjour broadcast func add(pairing: Pairing) { @@ -339,7 +349,7 @@ public class Device { configuration.pairings = [:] } persistConfig() - if pairingState == .paired { + if pairingState == .paired && configuration.pairings.isEmpty { // swiftlint:disable:next force_try try! changePairingState(.notPaired) }