<commit_before>//
// Created by <NAME> on 2019-03-04.
// Copyright (c) 2019 Particle. All rights reserved.
//

import Foundation

class StepOfferToSwitchToControlPanel: Gen3SetupStep {

    internal var device: ParticleDevice?

    override func start() {
        guard let context = self.context else {
            return
        }

        if context.targetDevice.isSetupDone! && context.targetDevice.isClaimed! {
            if let device = device {
                context.delegate.gen3SetupDidRequestToSwitchToControlPanel(self, device: device)
            } else {
                self.getDevice()
            }
        } else {
            self.stepCompleted()
        }
    }

    override func reset() {
        self.device = nil;
    }

    func getDevice() {
        guard let context = self.context else {
            return
        }

        ParticleCloud.sharedInstance().getDevice(context.targetDevice.deviceId!) { [weak self, weak context] device, error in
            guard let self = self, let context = context, !context.canceled else {
                return
            }

            if (error == nil) {
                self.device = device
                self.start()
            } else {
                self.fail(withReason: .FailedToGetDeviceInfo)
            }
        }
    }

    func setSwitchToControlPanel(switchToCP: Bool) -> Gen3SetupFlowError? {
        self.stepCompleted()

        return nil
    }
}
<commit_msg>show an error when trying to setup previously unclaimed xenons<commit_after>//
// Created by <NAME> on 2019-03-04.
// Copyright (c) 2019 Particle. All rights reserved.
//

import Foundation

class StepOfferToSwitchToControlPanel: Gen3SetupStep {

    internal var device: ParticleDevice?

    override func start() {
        guard let context = self.context else {
            return
        }

        if context.targetDevice.isSetupDone! && context.targetDevice.isClaimed! {
            if let device = device {
                context.delegate.gen3SetupDidRequestToSwitchToControlPanel(self, device: device)
            } else {
                self.getDevice()
            }
        } else {
            guard context.targetDevice.type != .xenon && context.targetDevice.type != .xSeries else {

                self.fail(withReason: .XennonNotSupportedError)
                //drop connection with current peripheral

                if let connection = context.targetDevice!.transceiver!.connection {
                    context.targetDevice!.transceiver = nil
                    context.targetDevice = nil
                    context.bluetoothManager.dropConnection(with: connection)
                }

                let _ = context.stepDelegate.rewindTo(self, step: StepGetTargetDeviceInfo.self, runStep: true)
                context.paused = false

                return
            }

            self.stepCompleted()
        }
    }

    override func reset() {
        self.device = nil;
    }

    func getDevice() {
        guard let context = self.context else {
            return
        }

        ParticleCloud.sharedInstance().getDevice(context.targetDevice.deviceId!) { [weak self, weak context] device, error in
            guard let self = self, let context = context, !context.canceled else {
                return
            }

            if (error == nil) {
                self.device = device
                self.start()
            } else {
                self.fail(withReason: .FailedToGetDeviceInfo)
            }
        }
    }

    func setSwitchToControlPanel(switchToCP: Bool) -> Gen3SetupFlowError? {
        self.stepCompleted()

        return nil
    }
}

{'fraction_non_alphanumeric': 0.08479212253829321, 'fraction_numerical': 0.008205689277899343, 'mean_word_length': 1.6889705882352941, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3830824', 'n_tokens_mistral': 981, 'n_tokens_neox': 909, 'n_words': 225}