Search in sources :

Example 36 with SwitchItem

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

the class LightwaveRfGenericBindingProviderTest method testRealLifeConfigurationForHeatingBattery.

@Test
public void testRealLifeConfigurationForHeatingBattery() throws Exception {
    LightwaveRfGenericBindingProvider bingindProvider = new LightwaveRfGenericBindingProvider();
    bingindProvider.processBindingConfiguration(context, new NumberItem("MyBattery"), "room=3,device=4,type=HEATING_BATTERY");
    bingindProvider.processBindingConfiguration(context, new NumberItem("MyCurrentTemp"), "room=3,device=4,type=HEATING_CURRENT_TEMP");
    bingindProvider.processBindingConfiguration(context, new DimmerItem("MyDimmer"), "room=1,device=2,type=DIMMER");
    bingindProvider.processBindingConfiguration(context, new SwitchItem("MySwitch"), "room=3,device=3,type=SWITCH");
    List<String> expectedNames = Arrays.asList("MyBattery", "MyDimmer", "MySwitch", "MyCurrentTemp");
    Collection<String> itemNames = bingindProvider.getItemNames();
    assertTrue(expectedNames.size() == itemNames.size() && expectedNames.containsAll(itemNames));
    assertEquals(Arrays.asList("MySwitch"), bingindProvider.getBindingItemsForRoomDevice("3", "3"));
    assertEquals("3", bingindProvider.getRoomId("MySwitch"));
    assertEquals("3", bingindProvider.getDeviceId("MySwitch"));
    assertEquals(LightwaveRfType.SWITCH, bingindProvider.getTypeForItemName("MySwitch"));
    assertEquals(Arrays.asList("MyDimmer"), bingindProvider.getBindingItemsForRoomDevice("1", "2"));
    assertEquals("1", bingindProvider.getRoomId("MyDimmer"));
    assertEquals("2", bingindProvider.getDeviceId("MyDimmer"));
    assertEquals(LightwaveRfType.DIMMER, bingindProvider.getTypeForItemName("MyDimmer"));
    assertEquals(Arrays.asList("MyBattery", "MyCurrentTemp"), bingindProvider.getBindingItemsForRoomDevice("3", "4"));
    assertEquals("3", bingindProvider.getRoomId("MyBattery"));
    assertEquals("4", bingindProvider.getDeviceId("MyBattery"));
    assertEquals(LightwaveRfType.HEATING_BATTERY, bingindProvider.getTypeForItemName("MyBattery"));
    assertEquals("3", bingindProvider.getRoomId("MyCurrentTemp"));
    assertEquals("4", bingindProvider.getDeviceId("MyCurrentTemp"));
    assertEquals(LightwaveRfType.HEATING_CURRENT_TEMP, bingindProvider.getTypeForItemName("MyCurrentTemp"));
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) DimmerItem(org.openhab.core.library.items.DimmerItem) SwitchItem(org.openhab.core.library.items.SwitchItem) Test(org.junit.Test)

Example 37 with SwitchItem

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

the class MqttItemConfigTest method canParseMultipleConfigs.

@Test
public void canParseMultipleConfigs() throws BindingConfigParseException {
    MqttItemConfig c = new MqttItemConfig(new SwitchItem("myItem"), ">[mybroker:/mytopic:command:ON:1],>[mybroker:/mytopic:command:OFF:0],<[mybroker:/myHome/doorbell:state:XSLT(doorbell.xslt)], <[mybroker:/myHome/doorbell:command:ON], <[mybroker:/myHome/doorbell:state:XSLT(doorbell.xslt)]");
    assertEquals(2, c.getMessagePublishers().size());
    assertEquals(3, c.getMessageSubscribers().size());
}
Also used : SwitchItem(org.openhab.core.library.items.SwitchItem) Test(org.junit.Test)

Example 38 with SwitchItem

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

the class MqttItemConfigTest method canParseOutboundConfig.

@Test
public void canParseOutboundConfig() throws BindingConfigParseException {
    MqttItemConfig c = new MqttItemConfig(new SwitchItem("myItem"), ">[mybroker:/mytopic:command:ON:1]");
    assertEquals(1, c.getMessagePublishers().size());
    assertEquals(0, c.getMessageSubscribers().size());
}
Also used : SwitchItem(org.openhab.core.library.items.SwitchItem) Test(org.junit.Test)

Example 39 with SwitchItem

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

the class Unit method updateItem.

@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
    int status = properties.getState();
    logger.debug("Unit state {}", status);
    int level = prevLevel;
    String display = "Off";
    if (status == UNIT_ON) {
        level = 100;
        display = "On";
    } else if ((status >= UNIT_SCENE_A) && (status <= UNIT_SCENE_L)) {
        level = 100;
        display = String.format("Scene %c", status - UNIT_SCENE_A + 'A');
    } else if ((status >= UNIT_DIM_1) && (status <= UNIT_DIM_9)) {
        display = String.format("Dim %d", level);
    } else if ((status >= UNIT_BRIGHTEN_1) && (status <= UNIT_BRIGHTEN_9)) {
        display = String.format("Brighten %d", level);
    } else if ((status >= UNIT_LEVEL_0) && (status <= UNIT_LEVEL_100)) {
        level = status - UNIT_LEVEL_0;
        display = String.format("Level %d", level);
    }
    if (item instanceof DimmerItem) {
        logger.debug("updating percent type {}", level);
        publisher.postUpdate(item.getName(), new PercentType(level));
    } else if (item instanceof SwitchItem) {
        logger.debug("updating switch type {}", level > 0 ? OnOffType.ON : OnOffType.OFF);
        publisher.postUpdate(item.getName(), level > 0 ? OnOffType.ON : OnOffType.OFF);
    } else if (item instanceof StringItem) {
        logger.debug("updating string type {}", display);
        publisher.postUpdate(item.getName(), new StringType(display));
    }
}
Also used : StringType(org.openhab.core.library.types.StringType) DimmerItem(org.openhab.core.library.items.DimmerItem) PercentType(org.openhab.core.library.types.PercentType) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 40 with SwitchItem

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

the class PLCLogoBinding method createState.

private State createState(Item item, Object value) {
    DecimalType number = null;
    if (value instanceof Number) {
        number = new DecimalType(value.toString());
    }
    State state = null;
    if (item instanceof StringType) {
        state = new StringType((String) value);
    } else if (item instanceof NumberItem) {
        if (number != null) {
            return number;
        } else if (value instanceof String) {
            state = new DecimalType(((String) value).replaceAll("[^\\d|.]", ""));
        }
    } else if (item instanceof SwitchItem && (number != null)) {
        state = (number.intValue() > 0) ? OnOffType.ON : OnOffType.OFF;
    } else if (item instanceof ContactItem && (number != null)) {
        state = (number.intValue() > 0) ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
    }
    return state;
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) State(org.openhab.core.types.State) ContactItem(org.openhab.core.library.items.ContactItem) DecimalType(org.openhab.core.library.types.DecimalType) SwitchItem(org.openhab.core.library.items.SwitchItem)

Aggregations

SwitchItem (org.openhab.core.library.items.SwitchItem)55 NumberItem (org.openhab.core.library.items.NumberItem)25 DimmerItem (org.openhab.core.library.items.DimmerItem)21 Test (org.junit.Test)18 ContactItem (org.openhab.core.library.items.ContactItem)17 Item (org.openhab.core.items.Item)15 RollershutterItem (org.openhab.core.library.items.RollershutterItem)15 DecimalType (org.openhab.core.library.types.DecimalType)15 ColorItem (org.openhab.core.library.items.ColorItem)12 StringItem (org.openhab.core.library.items.StringItem)12 PercentType (org.openhab.core.library.types.PercentType)11 StringType (org.openhab.core.library.types.StringType)10 State (org.openhab.core.types.State)8 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)8 DateTimeItem (org.openhab.core.library.items.DateTimeItem)7 DateTimeType (org.openhab.core.library.types.DateTimeType)7 Calendar (java.util.Calendar)6 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)5 HSBType (org.openhab.core.library.types.HSBType)5 SappBindingConfigContactItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem)4