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"));
}
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());
}
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());
}
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));
}
}
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;
}
Aggregations