Search in sources :

Example 16 with NumberItem

use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.

the class AbstractDynamoDBItemSerializationTest method testPercentTypeWithNumberItem.

@Test
public void testPercentTypeWithNumberItem() throws IOException {
    DynamoDBItem<?> dbitem = testStateGeneric(new PercentType(new BigDecimal(3.2)), new BigDecimal(3.2));
    // note: comes back as DecimalType instead of the original PercentType
    testAsHistoricGeneric(dbitem, new NumberItem("foo"), new DecimalType(new BigDecimal(3.2)));
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 17 with NumberItem

use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.

the class EnergenieGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    try {
        if (bindingConfig != null) {
            String[] configParts = bindingConfig.split(";");
            if (configParts.length < 2 || configParts.length > 2) {
                throw new BindingConfigParseException("energenie binding configuration must have 2 parts");
            }
            String itemType = item.toString();
            if (item instanceof SwitchItem) {
                if ((configParts[1].equals("1")) || (configParts[1].equals("2")) || (configParts[1].equals("3")) || (configParts[1].equals("4"))) {
                    BindingConfig energenieBindingConfig = new EnergenieBindingConfig(configParts[0], configParts[1], itemType);
                    addBindingConfig(item, energenieBindingConfig);
                } else {
                    throw new BindingConfigParseException("Your SwitchItem configuration does not contain channelNumbers");
                }
            } else if (item instanceof NumberItem) {
                ChannelTypeDef channelType = ChannelTypeDef.valueOf(configParts[1].trim());
                if (channelType != null) {
                    BindingConfig energenieBindingConfig = new EnergenieBindingConfig(configParts[0], configParts[1], itemType);
                    addBindingConfig(item, energenieBindingConfig);
                } else {
                    throw new BindingConfigParseException("Your NumberItem configuration does not contain channelTypes");
                }
            }
        } else {
            logger.warn("bindingConfig is NULL (item=" + item + ") -> processing bindingConfig aborted!");
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        logger.warn("bindingConfig is invalid (item=" + item + ") -> processing bindingConfig aborted!");
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) BindingConfig(org.openhab.core.binding.BindingConfig) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) SwitchItem(org.openhab.core.library.items.SwitchItem) ChannelTypeDef(org.openhab.binding.energenie.internal.EnergenieBindingConfig.ChannelTypeDef)

Example 18 with NumberItem

use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.

the class TemperatureSensorTest method testReceiveTempertureUpdate.

@Test
public void testReceiveTempertureUpdate() {
    parameterAddress = new EnoceanParameterAddress(EnoceanId.fromString(EnoceanBindingProviderMock.DEVICE_ID), Parameter.TEMPERATURE);
    provider.setParameterAddress(parameterAddress);
    binding.addBindingProvider(provider);
    provider.setItem(new NumberItem("dummie"));
    BigDecimal temperature = new BigDecimal("20.3");
    binding.valueChanged(parameterAddress, new NumberWithUnit(Unit.DEGREE_CELSIUS, temperature));
    assertEquals("Update State", new DecimalType(temperature), publisher.getUpdateState());
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) NumberWithUnit(org.opencean.core.common.values.NumberWithUnit) EnoceanParameterAddress(org.opencean.core.address.EnoceanParameterAddress) DecimalType(org.openhab.core.library.types.DecimalType) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 19 with NumberItem

use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.

the class LightwaveRfBindingFunctionalTest method testWifiLinkStatusReceived.

@Test
public void testWifiLinkStatusReceived() throws Exception {
    String message = "*!{\"trans\":452,\"mac\":\"ab:cd:ef\",\"time\":1447712274,\"type\":\"hub\",\"prod\":\"wfl\",\"fw\":\"U2.91Y\"," + "\"uptime\":1386309,\"timeZone\":0,\"lat\":52.48,\"long\":-87.89,\"duskTime\":1447690400," + "\"dawnTime\":1447659083,\"tmrs\":0,\"evns\":1,\"run\":0,\"macs\":8,\"ip\":\"192.168.0.1\",\"devs\":0}";
    List<ItemConfigAndExpectedState> itemConfigAndExpectedStates = new LinkedList<ItemConfigAndExpectedState>();
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_IP"), "serial=wifilink,type=WIFILINK_IP", new StringType("192.168.0.1")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_FIRMWARE"), "serial=wifilink,type=WIFILINK_FIRMWARE", new StringType("U2.91Y")));
    Calendar duskCal = Calendar.getInstance();
    duskCal.setTime(new Date(1447690400000L));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new DateTimeItem("WIFILINK_DUSK_TIME"), "serial=wifilink,type=WIFILINK_DUSK_TIME", new DateTimeType(duskCal)));
    Calendar dawnCal = Calendar.getInstance();
    dawnCal.setTime(new Date(1447659083000L));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new DateTimeItem("WIFILINK_DAWN_TIME"), "serial=wifilink,type=WIFILINK_DAWN_TIME", new DateTimeType(dawnCal)));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("WIFILINK_UPTIME"), "serial=wifilink,type=WIFILINK_UPTIME", new DecimalType("1386309")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_LONGITUDE"), "serial=wifilink,type=WIFILINK_LONGITUDE", new StringType("-87.89")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_LATITUDE"), "serial=wifilink,type=WIFILINK_LATITUDE", new StringType("52.48")));
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date(1447712274000L));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("TIME"), "serial=wifilink,type=UPDATETIME", new DateTimeType(cal)));
    testReceivingACommandAndVerify(itemConfigAndExpectedStates, message);
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) DateTimeType(org.openhab.core.library.types.DateTimeType) StringType(org.openhab.core.library.types.StringType) Calendar(java.util.Calendar) DecimalType(org.openhab.core.library.types.DecimalType) DateTimeItem(org.openhab.core.library.items.DateTimeItem) StringItem(org.openhab.core.library.items.StringItem) LinkedList(java.util.LinkedList) Date(java.util.Date) Test(org.junit.Test)

Example 20 with NumberItem

use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.

the class LightwaveRfGenericBindingProviderTest method testProcessBindingConfigurationForHeatingBattery.

@Test
public void testProcessBindingConfigurationForHeatingBattery() throws Exception {
    LightwaveRfGenericBindingProvider bingindProvider = new LightwaveRfGenericBindingProvider();
    bingindProvider.processBindingConfiguration(context, new NumberItem("MyBattery"), "room=3,device=4,type=HEATING_BATTERY");
    assertEquals(Arrays.asList("MyBattery"), bingindProvider.getBindingItemsForRoomDevice("3", "4"));
    assertEquals(Arrays.asList("MyBattery"), bingindProvider.getItemNames());
    assertEquals("3", bingindProvider.getRoomId("MyBattery"));
    assertEquals("4", bingindProvider.getDeviceId("MyBattery"));
    assertEquals(LightwaveRfType.HEATING_BATTERY, bingindProvider.getTypeForItemName("MyBattery"));
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) Test(org.junit.Test)

Aggregations

NumberItem (org.openhab.core.library.items.NumberItem)55 DecimalType (org.openhab.core.library.types.DecimalType)27 SwitchItem (org.openhab.core.library.items.SwitchItem)24 ContactItem (org.openhab.core.library.items.ContactItem)17 StringType (org.openhab.core.library.types.StringType)17 Test (org.junit.Test)16 DimmerItem (org.openhab.core.library.items.DimmerItem)16 RollershutterItem (org.openhab.core.library.items.RollershutterItem)15 StringItem (org.openhab.core.library.items.StringItem)15 Item (org.openhab.core.items.Item)11 PercentType (org.openhab.core.library.types.PercentType)11 DateTimeType (org.openhab.core.library.types.DateTimeType)10 Calendar (java.util.Calendar)9 DateTimeItem (org.openhab.core.library.items.DateTimeItem)9 ColorItem (org.openhab.core.library.items.ColorItem)8 State (org.openhab.core.types.State)8 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)8 BigDecimal (java.math.BigDecimal)6 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)5 HSBType (org.openhab.core.library.types.HSBType)5