public async void RefreshServices()
        {
            IsBusy = true;
            DetectedServices.Clear();
            try
            {
                IList <IService> services = await _microbit.GetServicesAsync();

                foreach (IService service in services)
                {
                    IMicrobitServiceProvider microbitServiceProvider =
                        IdToServiceProviderMappingProvider.ServiceProvider(service);
                    if (microbitServiceProvider != null)
                    {
                        DetectedServices.Add(microbitServiceProvider);
                    }
                }
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert("Exception", e.Message, "Ok");
            }
            finally
            {
                IsBusy = false;
            }
        }
        public DeviceServicesViewModel(IDevice device)
        {
            _microbit    = device;
            _bluetoothLe = CrossBluetoothLE.Current;
            _adapter     = _bluetoothLe.Adapter;

            _adapter.DeviceConnected      += HandleConnectionStateChanged;
            _adapter.DeviceDisconnected   += HandleConnectionStateChanged;
            _adapter.DeviceConnectionLost += HandleConnectionStateChanged;

            ToggleConnectionCommand = new Command(
                () =>
            {
                if (_microbit.State == DeviceState.Connected)
                {
                    Disconnect();
                }
                else if (_microbit.State == DeviceState.Disconnected)
                {
                    Connect();
                }
            },
                () => !IsBusy);

            ServicesCommand = new Command(async() =>
            {
                DetectedServices.Clear();
                IList <IService> services = await _microbit.GetServicesAsync();
                foreach (IService service in services)
                {
                    IMicrobitServiceProvider microbitServiceProvider = IdToServiceProviderMappingProvider.ServiceProvider(service);
                    if (microbitServiceProvider != null)
                    {
                        DetectedServices.Add(microbitServiceProvider);
                    }
                }
            }, () => !IsBusy
                                          );

            DetectedServices = new ObservableCollection <IMicrobitServiceProvider>();
        }