private async Task <IEnumerable <Device> > FetchDevicesAsync(Config config, CancellationToken cancellationToken)
        {
            var connections = await this.apiClient.Value.FetchConnectionsAsync(cancellationToken);

            // We can potentially see duplicate devices (if the user set their config file that way). Ignore them.
            var devices = config.Devices.DistinctBy(x => x.DeviceID).Select(device =>
            {
                var deviceObj = new Device(device.DeviceID, device.Name);
                if (connections.DeviceConnections.TryGetValue(device.DeviceID, out var connectionData))
                {
                    if (connectionData.Connected && connectionData.Address != null)
                    {
                        deviceObj.SetConnected(SyncthingAddressParser.Parse(connectionData.Address));
                    }
                    if (connectionData.Paused)
                    {
                        deviceObj.SetPaused();
                    }
                }
                return(deviceObj);
            });

            cancellationToken.ThrowIfCancellationRequested();

            return(devices);
        }
        private void EventDeviceConnected(object sender, EventWatcher.DeviceConnectedEventArgs e)
        {
            if (!this.devices.TryGetValue(e.DeviceId, out var device))
            {
                logger.Warn("Unexpected device connected: {0}, address {1}. It wasn't fetched when we fetched our config", e.DeviceId, e.Address);
                return; // Not expecting this device! It wasn't in the config...
            }

            device.SetConnected(SyncthingAddressParser.Parse(e.Address));

            this.OnDeviceConnected(device);
        }