Search in sources :

Example 1 with CommandInfo

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;
}
Also used : CommandInfo(me.retrodaredevil.solarthing.commands.CommandInfo) PacketCollection(me.retrodaredevil.solarthing.packets.collection.PacketCollection) Instant(java.time.Instant) ImmutableRequestCommandPacket(me.retrodaredevil.solarthing.commands.packets.open.ImmutableRequestCommandPacket) PacketCollectionCreator(me.retrodaredevil.solarthing.packets.collection.PacketCollectionCreator) SolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException)

Example 2 with CommandInfo

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);
}
Also used : ImmutableAvailableCommandsPacket(me.retrodaredevil.solarthing.commands.packets.status.ImmutableAvailableCommandsPacket) CommandInfo(me.retrodaredevil.solarthing.commands.CommandInfo) AvailableCommandsPacket(me.retrodaredevil.solarthing.commands.packets.status.AvailableCommandsPacket) ImmutableAvailableCommandsPacket(me.retrodaredevil.solarthing.commands.packets.status.ImmutableAvailableCommandsPacket) Test(org.junit.jupiter.api.Test)

Example 3 with CommandInfo

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());
}
Also used : RoverModbusRequester(me.retrodaredevil.solarthing.config.request.modbus.RoverModbusRequester) CommandInfo(me.retrodaredevil.solarthing.commands.CommandInfo) ModbusDataRequester(me.retrodaredevil.solarthing.config.request.modbus.ModbusDataRequester) DataRequester(me.retrodaredevil.solarthing.config.request.DataRequester) RoverModbusRequester(me.retrodaredevil.solarthing.config.request.modbus.RoverModbusRequester) ModbusRequester(me.retrodaredevil.solarthing.config.request.modbus.ModbusRequester) HashMap(java.util.HashMap) ModbusDataRequester(me.retrodaredevil.solarthing.config.request.modbus.ModbusDataRequester) ArrayList(java.util.ArrayList)

Aggregations

CommandInfo (me.retrodaredevil.solarthing.commands.CommandInfo)3 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ImmutableRequestCommandPacket (me.retrodaredevil.solarthing.commands.packets.open.ImmutableRequestCommandPacket)1 AvailableCommandsPacket (me.retrodaredevil.solarthing.commands.packets.status.AvailableCommandsPacket)1 ImmutableAvailableCommandsPacket (me.retrodaredevil.solarthing.commands.packets.status.ImmutableAvailableCommandsPacket)1 DataRequester (me.retrodaredevil.solarthing.config.request.DataRequester)1 ModbusDataRequester (me.retrodaredevil.solarthing.config.request.modbus.ModbusDataRequester)1 ModbusRequester (me.retrodaredevil.solarthing.config.request.modbus.ModbusRequester)1 RoverModbusRequester (me.retrodaredevil.solarthing.config.request.modbus.RoverModbusRequester)1 SolarThingDatabaseException (me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException)1 PacketCollection (me.retrodaredevil.solarthing.packets.collection.PacketCollection)1 PacketCollectionCreator (me.retrodaredevil.solarthing.packets.collection.PacketCollectionCreator)1 Test (org.junit.jupiter.api.Test)1