Search in sources :

Example 1 with ItemStateData

use of org.creek.mailcontrol.model.data.ItemStateData in project openhab1-addons by openhab.

the class ItemStateRequestProcessor method getItemState.

public ItemStateData getItemState(String itemId) throws ServiceException {
    ItemRegistry itemRegistry = getItemRegistry();
    ItemStateData itemState = null;
    try {
        Item item = itemRegistry.getItem(itemId);
        StateTransformable state = getState(item);
        itemState = new ItemStateData(System.currentTimeMillis(), itemId, state);
    } catch (ItemNotFoundException ex) {
        logger.info(itemId + " not found", ex);
    }
    return itemState;
}
Also used : Item(org.openhab.core.items.Item) StateTransformable(org.creek.mailcontrol.model.data.StateTransformable) ItemStateData(org.creek.mailcontrol.model.data.ItemStateData) ItemRegistry(org.openhab.core.items.ItemRegistry) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Example 2 with ItemStateData

use of org.creek.mailcontrol.model.data.ItemStateData in project openhab1-addons by openhab.

the class ItemStateRequestProcessor method getItemStates.

public List<ItemStateData> getItemStates() throws ServiceException {
    List<ItemStateData> itemStates = new ArrayList<ItemStateData>();
    ItemRegistry itemRegistry = getItemRegistry();
    for (Item item : itemRegistry.getItems()) {
        logger.debug("Item: " + item.getName() + " " + item.getState());
        StateTransformable state = getState(item);
        ItemStateData itemState = new ItemStateData(System.currentTimeMillis(), item.getName(), state);
        itemStates.add(itemState);
    }
    return itemStates;
}
Also used : Item(org.openhab.core.items.Item) StateTransformable(org.creek.mailcontrol.model.data.StateTransformable) ArrayList(java.util.ArrayList) ItemStateData(org.creek.mailcontrol.model.data.ItemStateData) ItemRegistry(org.openhab.core.items.ItemRegistry)

Example 3 with ItemStateData

use of org.creek.mailcontrol.model.data.ItemStateData in project openhab1-addons by openhab.

the class MessagesProcessor method processReceivedMessages.

public void processReceivedMessages(Set<Object> messages) throws TransformException, ServiceException {
    logger.debug("Processing messages");
    for (Object msg : messages) {
        if (msg instanceof String) {
            logger.debug("Message: " + msg);
            GenericMessage message = requestTransformer.transform((String) msg);
            logger.debug("Processing message: " + message);
            if (message.getMessageType() == ITEM_COMMAND_REQUEST_MESSAGE) {
                ItemCommandData itemCommand = (ItemCommandData) ((ItemCommandRequestMessage) message).getItemCommand();
                itemCommandProcessor.processItemCommand(itemCommand);
            } else if (message.getMessageType() == ITEM_STATE_REQUEST_MESSAGE) {
                ItemStateRequestMessage itemStateRequestMessage = (ItemStateRequestMessage) message;
                ItemStateData itemState = itemStateRequestProcessor.getItemState(itemStateRequestMessage.getItemId());
                messagesSender.sendMessage(message, itemState);
            } else if (message.getMessageType() == ITEMS_STATE_REQUEST_MESSAGE) {
                List<ItemStateData> itemStates = itemStateRequestProcessor.getItemStates();
                messagesSender.sendMessage(message, itemStates);
            }
        }
    }
}
Also used : GenericMessage(org.creek.mailcontrol.model.message.GenericMessage) ItemStateRequestMessage(org.creek.mailcontrol.model.message.ItemStateRequestMessage) ItemStateData(org.creek.mailcontrol.model.data.ItemStateData) ItemCommandData(org.creek.mailcontrol.model.data.ItemCommandData)

Aggregations

ItemStateData (org.creek.mailcontrol.model.data.ItemStateData)3 StateTransformable (org.creek.mailcontrol.model.data.StateTransformable)2 Item (org.openhab.core.items.Item)2 ItemRegistry (org.openhab.core.items.ItemRegistry)2 ArrayList (java.util.ArrayList)1 ItemCommandData (org.creek.mailcontrol.model.data.ItemCommandData)1 GenericMessage (org.creek.mailcontrol.model.message.GenericMessage)1 ItemStateRequestMessage (org.creek.mailcontrol.model.message.ItemStateRequestMessage)1 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)1