Search in sources :

Example 46 with Type

use of org.openhab.core.types.Type in project openhab1-addons by openhab.

the class OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig method convertReadValueToType.

@Override
public Type convertReadValueToType(String pvReadValue) {
    Type lvType = super.convertReadValueToType(pvReadValue);
    // Must be Number Tyoe
    DecimalType lvDecimalType = (DecimalType) lvType;
    // MinWarningValue
    if (ivMaxWarningValue != null && lvDecimalType.toBigDecimal().compareTo(ivMaxWarningValue) == 1) {
        return OnOffType.ON;
    } else if (ivMinWarningValue != null && lvDecimalType.toBigDecimal().compareTo(ivMinWarningValue) == -1) {
        return OnOffType.ON;
    } else {
        return OnOffType.OFF;
    }
}
Also used : Type(org.openhab.core.types.Type) UnDefType(org.openhab.core.types.UnDefType) OnOffType(org.openhab.core.library.types.OnOffType) DecimalType(org.openhab.core.library.types.DecimalType) DecimalType(org.openhab.core.library.types.DecimalType)

Example 47 with Type

use of org.openhab.core.types.Type 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)

Example 48 with Type

use of org.openhab.core.types.Type in project openhab1-addons by openhab.

the class TestSHCMessage method testGenericVersionMax.

/**
     * test data for the generic messages version: 255.255.255-255 TODO: Hash
     * parsing isn't working with the max hash value of 4294967295
     */
@Test
public void testGenericVersionMax() {
    String message = " PKT:SID=10;PC=165;MT=8;MGID=0;MID=1;MD=FFFFFF000000FF;5f552ffb";
    SHCMessage shcMessage = new SHCMessage(message, packet);
    List<Type> values = shcMessage.getData().getOpenHABTypes();
    assertEquals("Major", 255, ((DecimalType) values.get(0)).intValue());
    assertEquals("Minor", 255, ((DecimalType) values.get(1)).intValue());
    assertEquals("Patch", 255, ((DecimalType) values.get(2)).intValue());
    assertEquals("Hash", 255, ((DecimalType) values.get(3)).intValue());
}
Also used : Type(org.openhab.core.types.Type) OnOffType(org.openhab.core.library.types.OnOffType) DecimalType(org.openhab.core.library.types.DecimalType) SHCMessage(org.openhab.binding.smarthomatic.internal.SHCMessage) Test(org.junit.Test)

Example 49 with Type

use of org.openhab.core.types.Type in project openhab1-addons by openhab.

the class TestSHCMessage method testDimmerColorTyp.

/**
     * test data is: Dimmer Color: 13 (typ)
     */
@Test
public void testDimmerColorTyp() {
    String message = " PKT:SID=12;PC=203;MT=8;MGID=60;MID=10;MD=340000000003;3b0b8922";
    SHCMessage shcMessage = new SHCMessage(message, packet);
    List<Type> values = shcMessage.getData().getOpenHABTypes();
    assertEquals(13, ((DecimalType) values.get(0)).intValue());
}
Also used : Type(org.openhab.core.types.Type) OnOffType(org.openhab.core.library.types.OnOffType) DecimalType(org.openhab.core.library.types.DecimalType) SHCMessage(org.openhab.binding.smarthomatic.internal.SHCMessage) Test(org.junit.Test)

Example 50 with Type

use of org.openhab.core.types.Type in project openhab1-addons by openhab.

the class TestSHCMessage method testDimmerColorAnimationTyp.

/**
     * test data is: Dimmer Color Animation: (typ)
     */
@Test
public void testDimmerColorAnimationTyp() {
    String message = "PKT:SID=12;PC=9417;MT=10;MGID=60;MID=11;MD=1230418000000000000000000000000000;68ddbb91";
    SHCMessage shcMessage = new SHCMessage(message, packet);
    List<Type> values = shcMessage.getData().getOpenHABTypes();
    assertEquals("Repeat", 1, ((DecimalType) values.get(0)).intValue());
    assertEquals("AutoReverse", OnOffType.OFF, (values.get(1)));
    assertEquals("Time0", 8, ((DecimalType) values.get(2)).intValue());
    assertEquals("Color0", 48, ((DecimalType) values.get(3)).intValue());
    assertEquals("Time1", 8, ((DecimalType) values.get(4)).intValue());
    assertEquals("Color1", 12, ((DecimalType) values.get(5)).intValue());
}
Also used : Type(org.openhab.core.types.Type) OnOffType(org.openhab.core.library.types.OnOffType) DecimalType(org.openhab.core.library.types.DecimalType) SHCMessage(org.openhab.binding.smarthomatic.internal.SHCMessage) Test(org.junit.Test)

Aggregations

Type (org.openhab.core.types.Type)72 DecimalType (org.openhab.core.library.types.DecimalType)69 OnOffType (org.openhab.core.library.types.OnOffType)68 Test (org.junit.Test)60 SHCMessage (org.openhab.binding.smarthomatic.internal.SHCMessage)40 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)27 StringType (org.openhab.core.library.types.StringType)27 DateTimeType (org.openhab.core.library.types.DateTimeType)26 HSBType (org.openhab.core.library.types.HSBType)26 OpenClosedType (org.openhab.core.library.types.OpenClosedType)26 PercentType (org.openhab.core.library.types.PercentType)26 StopMoveType (org.openhab.core.library.types.StopMoveType)26 UpDownType (org.openhab.core.library.types.UpDownType)26 DPT (tuwien.auto.calimero.dptxlator.DPT)20 Command (org.openhab.core.types.Command)2 UnDefType (org.openhab.core.types.UnDefType)2 Calendar (java.util.Calendar)1 Locale (java.util.Locale)1 StringTokenizer (java.util.StringTokenizer)1 IllegalClassException (org.apache.commons.lang.IllegalClassException)1