use of me.retrodaredevil.solarthing.commands.CommandInfo in project solarthing by wildmountainfarms.
the class CommandChatBotHandler method handleMessage.
@Override
public boolean handleMessage(Message message, MessageSender messageSender) {
AvailableCommand best = commandHelper.getBestCommand(message, message.getText());
if (best == null) {
return false;
}
CommandInfo info = best.getCommandInfo();
messageSender.sendMessage("Sending command: " + info.getDisplayName());
PacketCollectionCreator creator = commandHelper.getCommandManager().makeCreator(sourceId, zoneId, InstanceTargetPackets.create(Collections.singleton(best.getFragmentId())), new ImmutableRequestCommandPacket(info.getName()), PacketCollectionIdGenerator.Defaults.UNIQUE_GENERATOR);
Instant now = Instant.now();
PacketCollection packetCollection = creator.create(now);
executorService.execute(() -> {
try {
database.getOpenDatabase().uploadPacketCollection(packetCollection, null);
LOGGER.info("Uploaded command request document");
} catch (SolarThingDatabaseException e) {
LOGGER.error("Error while uploading document.", e);
messageSender.sendMessage("Failed to upload command: " + info.getDisplayName());
}
});
return true;
}
use of me.retrodaredevil.solarthing.commands.CommandInfo in project solarthing by wildmountainfarms.
the class CommandStatusPacketTest method test.
@Test
void test() throws JsonProcessingException {
AvailableCommandsPacket packet = new ImmutableAvailableCommandsPacket(Collections.singletonList(new CommandInfo("asdf", "Asdf", "Cool")));
assertEquals("asdf", packet.getCommandInfoList().get(0).getName());
assertEquals(1, packet.getCommandInfoList().size());
PacketTestUtil.testJson(packet, AvailableCommandsPacket.class);
PacketTestUtil.testJson(packet, CommandStatusPacket.class);
}
use of me.retrodaredevil.solarthing.commands.CommandInfo in project solarthing by wildmountainfarms.
the class RoverMain method doRover.
private static int doRover(RoverProgramOptions options, AnalyticsManager analyticsManager, List<DataRequester> dataRequesterList) throws Exception {
RoverModbusRequester roverModbusRequester = new RoverModbusRequester(options.isSendErrorPackets(), options.isBulkRequest(), // attach the given rover modbus environment to all commands
options.getCommandInfoList().stream().map(CommandInfo::getName).collect(Collectors.toList()), null, null);
Map<Integer, ModbusRequester> deviceMap = new HashMap<>();
deviceMap.put(options.getModbusAddress(), roverModbusRequester);
ModbusDataRequester dataRequester = new ModbusDataRequester(options.getIOBundleFile(), deviceMap, null, null);
List<DataRequester> list = new ArrayList<>(dataRequesterList);
list.add(dataRequester);
return RequestMain.startRequestProgram(options, analyticsManager, list, options.getPeriod(), options.getMinimumWait());
}
Aggregations