Search in sources :

Example 1 with ImmutableRequestFlagPacket

use of me.retrodaredevil.solarthing.commands.packets.open.ImmutableRequestFlagPacket in project solarthing by wildmountainfarms.

the class FlagCommandChatBotHandler method setFlag.

private void setFlag(MessageSender messageSender, String flagName) {
    TimeRange timeRange = TimeRange.createAfter(Instant.now());
    FlagData data = new FlagData(flagName, new TimeRangeActivePeriod(timeRange));
    RequestFlagPacket requestFlagPacket = new ImmutableRequestFlagPacket(data);
    PacketCollectionCreator creator = commandHelper.getCommandManager().makeCreator(sourceId, zoneId, null, requestFlagPacket, PacketCollectionIdGenerator.Defaults.UNIQUE_GENERATOR);
    // TODO We should check if the flag being requested is already active.
    executorService.execute(() -> {
        PacketCollection packetCollection = creator.create(Instant.now());
        boolean success = false;
        try {
            database.getOpenDatabase().uploadPacketCollection(packetCollection, null);
            success = true;
        } catch (SolarThingDatabaseException e) {
            LOGGER.error("Could not upload request flag packet", e);
        }
        if (success) {
            messageSender.sendMessage("Successfully requested flag: '" + flagName + "' to be set.");
        } else {
            messageSender.sendMessage("Was unable to request flag set. See logs for details or try again.");
        }
    });
}
Also used : TimeRange(me.retrodaredevil.solarthing.util.TimeRange) FlagData(me.retrodaredevil.solarthing.type.alter.flag.FlagData) PacketCollection(me.retrodaredevil.solarthing.packets.collection.PacketCollection) TimeRangeActivePeriod(me.retrodaredevil.solarthing.type.alter.flag.TimeRangeActivePeriod) ImmutableRequestFlagPacket(me.retrodaredevil.solarthing.commands.packets.open.ImmutableRequestFlagPacket) RequestFlagPacket(me.retrodaredevil.solarthing.commands.packets.open.RequestFlagPacket) ImmutableRequestFlagPacket(me.retrodaredevil.solarthing.commands.packets.open.ImmutableRequestFlagPacket) PacketCollectionCreator(me.retrodaredevil.solarthing.packets.collection.PacketCollectionCreator) SolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException)

Aggregations

ImmutableRequestFlagPacket (me.retrodaredevil.solarthing.commands.packets.open.ImmutableRequestFlagPacket)1 RequestFlagPacket (me.retrodaredevil.solarthing.commands.packets.open.RequestFlagPacket)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 FlagData (me.retrodaredevil.solarthing.type.alter.flag.FlagData)1 TimeRangeActivePeriod (me.retrodaredevil.solarthing.type.alter.flag.TimeRangeActivePeriod)1 TimeRange (me.retrodaredevil.solarthing.util.TimeRange)1