Commit ffdca6f7 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Fix getDevicesById() (#9646)

If the user specified a non-exact device id, it was producing
an exception whereby we were trying to listen to the
`getAllConnectedDevies()` stream twice.
parent 744c9126
......@@ -53,7 +53,7 @@ class DeviceManager {
bool get hasSpecifiedAllDevices => _specifiedDeviceId == 'all';
Stream<Device> getDevicesById(String deviceId) async* {
final Stream<Device> devices = getAllConnectedDevices();
final List<Device> devices = await getAllConnectedDevices().toList();
deviceId = deviceId.toLowerCase();
bool exactlyMatchesDeviceId(Device device) =>
device.id.toLowerCase() == deviceId ||
......@@ -62,15 +62,15 @@ class DeviceManager {
device.id.toLowerCase().startsWith(deviceId) ||
device.name.toLowerCase().startsWith(deviceId);
final Device exactMatch = await devices.firstWhere(
exactlyMatchesDeviceId, defaultValue: () => null);
final Device exactMatch = devices.firstWhere(
exactlyMatchesDeviceId, orElse: () => null);
if (exactMatch != null) {
yield exactMatch;
return;
}
// Match on a id or name starting with [deviceId].
await for (Device device in devices.where(startsWithDeviceId))
for (Device device in devices.where(startsWithDeviceId))
yield device;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment