public DeviceCommandInvocationCreateRequest.Builder newCommandInvocation(String commandName, String target) { try { IDeviceAssignment targetAssignment = deviceManagement.getDeviceAssignmentByToken(target); if (targetAssignment == null) { throw new SiteWhereException("Target assignment not found: " + target); } IDevice targetDevice = deviceManagement.getDeviceForAssignment(targetAssignment); List<IDeviceCommand> commands = deviceManagement.listDeviceCommands(targetDevice.getSpecificationToken(), false); IDeviceCommand match = null; for (IDeviceCommand command : commands) { if (command.getName().equals(commandName)) { match = command; } } if (match == null) { throw new SiteWhereException("Command not executed. No command found matching: " + commandName); } return new DeviceCommandInvocationCreateRequest.Builder(match.getToken(), target); } catch (SiteWhereException e) { throw new RuntimeException(e); } }
public DeviceCommandInvocationCreateRequest.Builder newCommandInvocation(String commandName, String target) { try { IDeviceAssignment targetAssignment = deviceManagement.getDeviceAssignmentByToken(target); if (targetAssignment == null) { throw new SiteWhereException("Target assignment not found: " + target); } IDevice targetDevice = deviceManagement.getDevice(targetAssignment.getDeviceId()); DeviceCommandSearchCriteria criteria = new DeviceCommandSearchCriteria(1, 0); criteria.setDeviceTypeId(targetDevice.getDeviceTypeId()); ISearchResults<IDeviceCommand> commands = deviceManagement.listDeviceCommands(criteria); IDeviceCommand match = null; for (IDeviceCommand command : commands.getResults()) { if (command.getName().equals(commandName)) { match = command; } } if (match == null) { throw new SiteWhereException("Command not executed. No command found matching: " + commandName); } return new DeviceCommandInvocationCreateRequest.Builder(match.getToken(), target); } catch (SiteWhereException e) { throw new RuntimeException(e); } }