Search in sources :

Example 1 with SHCHeader

use of org.openhab.binding.smarthomatic.internal.SHCMessage.SHCHeader in project openhab1-addons by openhab.

the class SmarthomaticBinding method eventOccured.

@Override
public void eventOccured(String message) {
    StringTokenizer strTok = new StringTokenizer(message, "\n");
    String data = null;
    // check incoming data
    int i = 0;
    while (strTok.hasMoreTokens()) {
        String s = strTok.nextToken();
        if (s.contains(SHCMessage.DATA_FLAG)) {
            data = s;
            logger.debug("<BaseStation data>[{}]: {}", i, data);
        }
    }
    if (data != null) {
        SHCMessage shcMessage = new SHCMessage(data, packet);
        SHCHeader shcHeader = shcMessage.getHeader();
        logger.debug("BaseStation SenderID: {} MsgType: {} MsgGroupID: {} MsgID: {} MsgData: {}", shcHeader.getSenderID(), shcHeader.getMessageType(), shcHeader.getMessageGroupID(), shcHeader.getMessageID(), shcHeader.getMessageData());
        SHCData info = shcMessage.getData();
        if (info != null) {
            logger.debug(info.toString());
        }
        // Message-Header
        for (SmarthomaticBindingProvider provider : this.providers) {
            for (String itemName : provider.getItemNames()) {
                if (shcHeader.getSenderID() == provider.getDeviceId(itemName) && shcHeader.getMessageGroupID() == provider.getMessageGroupId(itemName) && shcHeader.getMessageID() == provider.getMessageId(itemName)) {
                    Type type = shcMessage.openHABStateFromSHCMessage(provider.getItem(itemName)).get(provider.getMessagePartId(itemName));
                    String transformed = processTransformation(provider.getConfigParam(itemName, "transformation"), type.toString());
                    if (type instanceof DecimalType) {
                        type = DecimalType.valueOf(transformed);
                    }
                    if (isDataTypeSupported(provider.getItem(itemName), type)) {
                        eventPublisher.postUpdate(itemName, (State) type);
                    }
                }
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Type(org.openhab.core.types.Type) DecimalType(org.openhab.core.library.types.DecimalType) SHCHeader(org.openhab.binding.smarthomatic.internal.SHCMessage.SHCHeader) DecimalType(org.openhab.core.library.types.DecimalType) SHCData(org.openhab.binding.smarthomatic.internal.SHCMessage.SHCData) SmarthomaticBindingProvider(org.openhab.binding.smarthomatic.SmarthomaticBindingProvider)

Aggregations

StringTokenizer (java.util.StringTokenizer)1 SmarthomaticBindingProvider (org.openhab.binding.smarthomatic.SmarthomaticBindingProvider)1 SHCData (org.openhab.binding.smarthomatic.internal.SHCMessage.SHCData)1 SHCHeader (org.openhab.binding.smarthomatic.internal.SHCMessage.SHCHeader)1 DecimalType (org.openhab.core.library.types.DecimalType)1 Type (org.openhab.core.types.Type)1