Search in sources :

Example 1 with Type

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

the class SonosBinding method processVariableMap.

@SuppressWarnings("rawtypes")
public void processVariableMap(RemoteDevice device, Map<String, StateVariableValue> values) {
    if (device != null && values != null) {
        SonosZonePlayer associatedPlayer = sonosZonePlayerCache.getByDevice(device);
        if (associatedPlayer == null) {
            logger.debug("There is no Sonos Player defined matching the device {}", device);
            return;
        }
        for (String stateVariable : values.keySet()) {
            // find all the CommandTypes that are defined for each
            // StateVariable
            List<SonosCommandType> supportedCommands = SonosCommandType.getCommandByVariable(stateVariable);
            StateVariableValue status = values.get(stateVariable);
            for (SonosCommandType sonosCommandType : supportedCommands) {
                // create a new State based on the type of Sonos Command and
                // the status value in the map
                Type newState = null;
                try {
                    newState = createStateForType((Class<? extends State>) sonosCommandType.getTypeClass(), status.getValue().toString());
                } catch (BindingConfigParseException e) {
                    logger.error("Error parsing a value {} to a state variable of type {}", status.toString(), sonosCommandType.getTypeClass().toString());
                }
                for (SonosBindingProvider provider : providers) {
                    List<String> qualifiedItems = provider.getItemNames(sonosZonePlayerCache.getByDevice(device).getId(), sonosCommandType.getSonosCommand());
                    List<String> qualifiedItemsByUDN = provider.getItemNames(sonosZonePlayerCache.getByDevice(device).getUdn().getIdentifierString(), sonosCommandType.getSonosCommand());
                    for (String item : qualifiedItemsByUDN) {
                        if (!qualifiedItems.contains(item)) {
                            qualifiedItems.add(item);
                        }
                    }
                    for (String anItem : qualifiedItems) {
                        // get the openHAB commands attached to each Item at
                        // this given Provider
                        List<Command> commands = provider.getCommands(anItem, sonosCommandType.getSonosCommand());
                        if (provider.getAcceptedDataTypes(anItem).contains(sonosCommandType.getTypeClass())) {
                            if (newState != null) {
                                eventPublisher.postUpdate(anItem, (State) newState);
                            } else {
                                throw new IllegalClassException("Cannot process update for the command of type " + sonosCommandType.toString());
                            }
                        } else {
                            logger.warn("Cannot cast {} to an accepted state type for item {}", sonosCommandType.getTypeClass().toString(), anItem);
                        }
                    }
                }
            }
        }
    }
}
Also used : StateVariableValue(org.teleal.cling.model.state.StateVariableValue) SonosCommandType(org.openhab.binding.sonos.SonosCommandType) IllegalClassException(org.apache.commons.lang.IllegalClassException) StringType(org.openhab.core.library.types.StringType) SonosCommandType(org.openhab.binding.sonos.SonosCommandType) OnOffType(org.openhab.core.library.types.OnOffType) UDAServiceType(org.teleal.cling.model.types.UDAServiceType) Type(org.openhab.core.types.Type) DecimalType(org.openhab.core.library.types.DecimalType) SonosBindingProvider(org.openhab.binding.sonos.SonosBindingProvider) Command(org.openhab.core.types.Command) State(org.openhab.core.types.State) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 2 with Type

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

the class KNXCoreTypeMapperTest method testTypeMappingB1_Controlled.

/**
     * Convenience method: testing KNXCoretypeMapper for type “Datapoint Types B1 Controlled"
     *
     * @throws KNXFormatException
     */
private void testTypeMappingB1_Controlled(DPT dpt, String valueLow, String valueHigh) throws KNXFormatException {
    testToTypeClass(dpt, DecimalType.class);
    // Use a too short byte array
    assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DecimalType.class));
    Type type = testToType(dpt, new byte[] { 0 }, DecimalType.class);
    testToDPTValue(dpt, type, "0 " + valueLow);
    type = testToType(dpt, new byte[] { 1 }, DecimalType.class);
    testToDPTValue(dpt, type, "0 " + valueHigh);
    type = testToType(dpt, new byte[] { 2 }, DecimalType.class);
    testToDPTValue(dpt, type, "1 " + valueLow);
    type = testToType(dpt, new byte[] { 3 }, DecimalType.class);
    testToDPTValue(dpt, type, "1 " + valueHigh);
    type = testToType(dpt, new byte[] { (byte) 0xFF }, DecimalType.class);
    testToDPTValue(dpt, type, "1 " + valueHigh);
    // Use a too long byte array expecting that additional bytes will be ignored
    type = testToType(dpt, new byte[] { (byte) 0xFF, 0 }, DecimalType.class);
    testToDPTValue(dpt, type, "1 " + valueHigh);
}
Also used : OpenClosedType(org.openhab.core.library.types.OpenClosedType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) StringType(org.openhab.core.library.types.StringType) OnOffType(org.openhab.core.library.types.OnOffType) DateTimeType(org.openhab.core.library.types.DateTimeType) Type(org.openhab.core.types.Type) DecimalType(org.openhab.core.library.types.DecimalType) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType) StopMoveType(org.openhab.core.library.types.StopMoveType) DecimalType(org.openhab.core.library.types.DecimalType)

Example 3 with Type

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

the class KNXCoreTypeMapperTest method testTypeMappingDate_11_001.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType() for type “Time" KNX ID: 11.001 DPT_DATE
     *
     * Test correct year evaluation according KNX spec.
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMappingDate_11_001() throws KNXFormatException {
    DPT dpt = DPTXlatorDate.DPT_DATE;
    testToTypeClass(dpt, DateTimeType.class);
    // Use a too short byte array
    assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DateTimeType.class));
    // Use a too long byte array expecting that additional bytes will be ignored
    Type type = testToType(dpt, new byte[] { 0x01, 0x01, 0x00, (byte) 0xFF }, DateTimeType.class);
    testToDPTValue(dpt, type, "2000-01-01");
    type = testToType(dpt, new byte[] { 0x01, 0x01, 0x00 }, DateTimeType.class);
    testToDPTValue(dpt, type, "2000-01-01");
    type = testToType(dpt, new byte[] { 0x01, 0x01, 99 }, DateTimeType.class);
    testToDPTValue(dpt, type, "1999-01-01");
    type = testToType(dpt, new byte[] { 0x01, 0x01, 90 }, DateTimeType.class);
    testToDPTValue(dpt, type, "1990-01-01");
    type = testToType(dpt, new byte[] { 0x01, 0x01, 89 }, DateTimeType.class);
    testToDPTValue(dpt, type, "2089-01-01");
    // Test roll over (which is actually not in the KNX spec)
    type = testToType(dpt, new byte[] { 31, 0x02, 0x00 }, DateTimeType.class);
    testToDPTValue(dpt, type, "2000-03-02");
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) OpenClosedType(org.openhab.core.library.types.OpenClosedType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) StringType(org.openhab.core.library.types.StringType) OnOffType(org.openhab.core.library.types.OnOffType) DateTimeType(org.openhab.core.library.types.DateTimeType) Type(org.openhab.core.types.Type) DecimalType(org.openhab.core.library.types.DecimalType) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType) StopMoveType(org.openhab.core.library.types.StopMoveType) DPT(tuwien.auto.calimero.dptxlator.DPT) Test(org.junit.Test)

Example 4 with Type

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

the class KNXCoreTypeMapperTest method testTypeMappingB1.

/**
     * Convenience method: testing KNXCoretypeMapper for type “Datapoint Types B1"
     *
     * @throws KNXFormatException
     */
private void testTypeMappingB1(DPT dpt, Class<? extends Type> expectedClass, String valueLow, String valueHigh) throws KNXFormatException {
    testToTypeClass(dpt, expectedClass);
    // Use a too short byte array
    assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, expectedClass));
    Type type = testToType(dpt, new byte[] { 0 }, expectedClass);
    testToDPTValue(dpt, type, valueLow);
    type = testToType(dpt, new byte[] { 1 }, expectedClass);
    testToDPTValue(dpt, type, valueHigh);
    type = testToType(dpt, new byte[] { 2 }, expectedClass);
    testToDPTValue(dpt, type, valueLow);
    type = testToType(dpt, new byte[] { 3 }, expectedClass);
    testToDPTValue(dpt, type, valueHigh);
    type = testToType(dpt, new byte[] { (byte) 0xFF }, expectedClass);
    testToDPTValue(dpt, type, valueHigh);
    // Use a too long byte array expecting that additional bytes will be ignored
    type = testToType(dpt, new byte[] { (byte) 0xFF, 0 }, expectedClass);
    testToDPTValue(dpt, type, valueHigh);
}
Also used : OpenClosedType(org.openhab.core.library.types.OpenClosedType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) StringType(org.openhab.core.library.types.StringType) OnOffType(org.openhab.core.library.types.OnOffType) DateTimeType(org.openhab.core.library.types.DateTimeType) Type(org.openhab.core.types.Type) DecimalType(org.openhab.core.library.types.DecimalType) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType) StopMoveType(org.openhab.core.library.types.StopMoveType)

Example 5 with Type

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

the class KNXCoreTypeMapperTest method testTypeMapping8BitUnsigned_5_006.

/**
     * KNXCoreTypeMapper tests method typeMapper.toType() for type “8-Bit Unsigned Value" KNX ID: 5.006 DPT_TARRIF
     *
     * @throws KNXFormatException
     */
@Test
public void testTypeMapping8BitUnsigned_5_006() throws KNXFormatException {
    DPT dpt = DPTXlator8BitUnsigned.DPT_TARIFF;
    testToTypeClass(dpt, DecimalType.class);
    // Use a too short byte array
    assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DecimalType.class));
    Type type = testToType(dpt, new byte[] { 0 }, DecimalType.class);
    testToDPTValue(dpt, type, "0");
    type = testToType(dpt, new byte[] { (byte) 0xFF }, DecimalType.class);
    testToDPTValue(dpt, type, "255");
    // Use a too long byte array expecting that additional bytes will be ignored
    type = testToType(dpt, new byte[] { (byte) 0xFF, 0 }, DecimalType.class);
    testToDPTValue(dpt, type, "255");
}
Also used : OpenClosedType(org.openhab.core.library.types.OpenClosedType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) StringType(org.openhab.core.library.types.StringType) OnOffType(org.openhab.core.library.types.OnOffType) DateTimeType(org.openhab.core.library.types.DateTimeType) Type(org.openhab.core.types.Type) DecimalType(org.openhab.core.library.types.DecimalType) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType) StopMoveType(org.openhab.core.library.types.StopMoveType) DPT(tuwien.auto.calimero.dptxlator.DPT) DecimalType(org.openhab.core.library.types.DecimalType) 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