(SessionDevice session, Bus bus, List<String> ids,
boolean sessionMayBeDefault)
throws CommandExecutionException {
List<String> idsCopy = new ArrayList<String>(ids);
try {
DeviceGroup deviceGroup
= CommandUtil.findDeviceGroup(session, bus, ids);
Device device = null;
if (deviceGroup instanceof SingleDeviceGroup) {
return ((SingleDeviceGroup) deviceGroup).getDevice();
}
// Special case: although devices have addresses and therefore
// an address must be specified, the address may be omitted
// if session can be used as default.
if (ids.size() == 0) {
if (sessionMayBeDefault
&& deviceGroup.getName().equals("SESSION")) {
device = session;
} else {
throw new CommandExecutionException
(Command.ERROR_LIST_TOO_SHORT);
}
}
// Device may be known already if default session was addressed.
if (device == null) {
device = deviceGroup.getDevice(consumeNumber(ids));
}
if (device == null) {
throw new CommandExecutionException
(Command.ERROR_UNSUPPORTED_DEVICE);
}