 
     internal let queue: DispatchQueue
 
+    fileprivate var didRestoreState =       false
     fileprivate var knownPeripheralUUIDs:   [UUID]
     fileprivate var deviceForUUID:          [UUID : BLEDevice] = [:]
     fileprivate var alreadyDiscoveredUUIDs: Set<UUID> = []


extension BLEDiscoveryManager: CBCentralManagerDelegate {
    public func centralManager(_ central: CBCentralManager, willRestoreState state: [String : Any]) {
        NuimoSwift.DDLogDebug("BLEDiscoveryManager willRestoreState with state \(central.state.rawValue) on queue \(DispatchQueue.currentQueueLabel)")
        guard let centralManager = centralManager else {
            queue.async { self.centralManager(central, willRestoreState: state) }

        }

        if centralManager.state.rawValue >= CBCentralManagerState.poweredOff.rawValue {
            if !didRestoreState {
                self.centralManager(central, willRestoreState: [:])
            }

            // Update all devices with a freshly retrieved peripheral from central manager for those which have an invalidated peripheral
            centralManager.retrievePeripherals(withIdentifiers: Array(deviceForUUID.keys)).forEach {
                guard let device = self.deviceForUUID[$0.identifier], device.peripheral == nil else { return }
