import Foundation import CoreBluetooth enum DeviceState { case bluetoothDisabled case bluetoothEnabled case scanning case connecting(device: CBPeripheral) case discoveringServices(device: CBPeripheral) case discoveringCharacteristic(device: CBPeripheral) case configured(device: CBPeripheral, characteristic: CBCharacteristic) case disconnected var text: String { switch self { case .bluetoothDisabled: return "Bluetooth is disabled" case .bluetoothEnabled: return "Bluetooth enabled" case .scanning: return "Scanning..." case .connecting(let device): guard let name = device.name else { return "Connecting..." } return "Connecting to \(name)..." case .discoveringServices: return "Discovering service..." case .discoveringCharacteristic: return "Discovering characteristic..." case .configured(let device, _): guard let name = device.name else { return "Connected" } return name case .disconnected: return "Not connected" } } } extension DeviceState: CustomStringConvertible { var description: String { switch self { case .bluetoothDisabled: return "Bluetooth disabled" case .bluetoothEnabled: return "Bluetooth enabled" case .scanning: return "Searching for device" case .connecting: return "Connecting to device" case .discoveringServices: return "Discovering services" case .discoveringCharacteristic: return "Discovering characteristics" case .configured: return "Connected" case .disconnected: return "Disconnected" } } } extension DeviceState: Equatable { }