use of org.openhab.core.library.items.DimmerItem 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.DimmerItem in project openhab1-addons by openhab.
the class LightwaveRfGenericBindingProviderTest method testProcessBindingConfigurationForDimmer.
@Test
public void testProcessBindingConfigurationForDimmer() throws Exception {
LightwaveRfGenericBindingProvider bingindProvider = new LightwaveRfGenericBindingProvider();
bingindProvider.processBindingConfiguration(context, new DimmerItem("MyDimmer"), "room=1,device=2,type=DIMMER");
assertEquals(Arrays.asList("MyDimmer"), bingindProvider.getBindingItemsForRoomDevice("1", "2"));
assertEquals(Arrays.asList("MyDimmer"), bingindProvider.getItemNames());
assertEquals("1", bingindProvider.getRoomId("MyDimmer"));
assertEquals("2", bingindProvider.getDeviceId("MyDimmer"));
assertEquals(LightwaveRfType.DIMMER, bingindProvider.getTypeForItemName("MyDimmer"));
assertEquals(LightwaveRfItemDirection.IN_AND_OUT, bingindProvider.getDirection("MySwitch"));
}
use of org.openhab.core.library.items.DimmerItem 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.DimmerItem in project openhab1-addons by openhab.
the class SappBinding method updateState.
/**
* updates item repository for a single item
*/
private void updateState(String pnmasId, SappAddressType sappAddressType, int addressToUpdate, int newState, SappBindingProvider provider) {
logger.debug("Updating {} {} with new value {}", sappAddressType, addressToUpdate, newState);
for (String itemName : provider.getItemNames()) {
try {
Item item = itemRegistry.getItem(itemName);
if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
SappBindingConfigSwitchItem sappBindingConfigSwitchItem = (SappBindingConfigSwitchItem) provider.getBindingConfig(itemName);
if (!sappBindingConfigSwitchItem.isPollerSuspender()) {
SappAddressOnOffStatus statusAddress = sappBindingConfigSwitchItem.getStatus();
if (statusAddress.getAddressType() == sappAddressType && statusAddress.getPnmasId().equals(pnmasId) && addressToUpdate == statusAddress.getAddress()) {
logger.debug("found binding to update {}", sappBindingConfigSwitchItem);
int result = SappBindingConfigUtils.maskWithSubAddress(statusAddress.getSubAddress(), newState);
State stateToSet = result == statusAddress.getOnValue() ? OnOffType.ON : OnOffType.OFF;
if (!stateToSet.equals(item.getState())) {
eventPublisher.postUpdate(itemName, stateToSet);
}
}
}
} else if (item instanceof ContactItem) {
SappBindingConfigContactItem sappBindingConfigContactItem = (SappBindingConfigContactItem) provider.getBindingConfig(itemName);
SappAddressOpenClosedStatus statusAddress = sappBindingConfigContactItem.getStatus();
if (statusAddress.getAddressType() == sappAddressType && statusAddress.getPnmasId().equals(pnmasId) && addressToUpdate == statusAddress.getAddress()) {
logger.debug("found binding to update {}", sappBindingConfigContactItem);
int result = SappBindingConfigUtils.maskWithSubAddress(statusAddress.getSubAddress(), newState);
State stateToSet = result == statusAddress.getOpenValue() ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
if (!stateToSet.equals(item.getState())) {
eventPublisher.postUpdate(itemName, stateToSet);
}
}
} else if (item instanceof NumberItem) {
SappBindingConfigNumberItem sappBindingConfigNumberItem = (SappBindingConfigNumberItem) provider.getBindingConfig(itemName);
SappAddressDecimal address = sappBindingConfigNumberItem.getStatus();
if (address.getAddressType() == sappAddressType && address.getPnmasId().equals(pnmasId) && addressToUpdate == address.getAddress()) {
logger.debug("found binding to update {}", sappBindingConfigNumberItem);
int result = SappBindingConfigUtils.maskWithSubAddress(address.getSubAddress(), newState);
State stateToSet = new DecimalType(address.scaledValue(result, address.getSubAddress()));
if (!stateToSet.equals(item.getState())) {
eventPublisher.postUpdate(itemName, stateToSet);
}
}
} else if (item instanceof RollershutterItem) {
SappBindingConfigRollershutterItem sappBindingConfigRollershutterItem = (SappBindingConfigRollershutterItem) provider.getBindingConfig(itemName);
SappAddressRollershutterStatus statusAddress = sappBindingConfigRollershutterItem.getStatus();
if (statusAddress.getAddressType() == sappAddressType && statusAddress.getPnmasId().equals(pnmasId) && addressToUpdate == statusAddress.getAddress()) {
logger.debug("found binding to update {}", sappBindingConfigRollershutterItem);
int result = SappBindingConfigUtils.maskWithSubAddress(statusAddress.getSubAddress(), newState);
State stateToSet = result == statusAddress.getOpenValue() ? PercentType.HUNDRED : (result == statusAddress.getClosedValue() ? PercentType.ZERO : PercentType.valueOf("50"));
if (!stateToSet.equals(item.getState())) {
eventPublisher.postUpdate(itemName, stateToSet);
}
}
} else if (item instanceof DimmerItem) {
SappBindingConfigDimmerItem sappBindingConfigDimmerItem = (SappBindingConfigDimmerItem) provider.getBindingConfig(itemName);
SappAddressDimmer statusAddress = sappBindingConfigDimmerItem.getStatus();
if (statusAddress.getAddressType() == sappAddressType && statusAddress.getPnmasId().equals(pnmasId) && addressToUpdate == statusAddress.getAddress()) {
logger.debug("found binding to update {}", sappBindingConfigDimmerItem);
int result = statusAddress.scaledValue(SappBindingConfigUtils.maskWithSubAddress(statusAddress.getSubAddress(), newState), statusAddress.getSubAddress()).round(new MathContext(0, RoundingMode.HALF_EVEN)).intValue();
State stateToSet;
if (result <= PercentType.ZERO.intValue()) {
stateToSet = PercentType.ZERO;
} else if (result >= PercentType.HUNDRED.intValue()) {
stateToSet = PercentType.HUNDRED;
} else {
stateToSet = PercentType.valueOf(String.valueOf(result));
}
if (!stateToSet.equals(item.getState())) {
eventPublisher.postUpdate(itemName, stateToSet);
}
}
} else {
logger.error("unimplemented item type: {}", item.getClass().getSimpleName());
}
} catch (ItemNotFoundException e) {
logger.error("Item {} not found", itemName);
}
}
}
use of org.openhab.core.library.items.DimmerItem in project openhab1-addons by openhab.
the class SappBinding method queryAndSendActualState.
/**
* reads state from device and updates item repository
*/
private void queryAndSendActualState(SappBindingProvider provider, String itemName) {
logger.debug("querying and sending item {}", itemName);
try {
Item item = itemRegistry.getItem(itemName);
if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
SappBindingConfigSwitchItem sappBindingConfigSwitchItem = (SappBindingConfigSwitchItem) provider.getBindingConfig(itemName);
SappAddressOnOffStatus statusAddress = sappBindingConfigSwitchItem.getStatus();
if (!sappBindingConfigSwitchItem.isPollerSuspender()) {
updateOnOffItem(provider, statusAddress, itemName, item);
}
} else if (item instanceof ContactItem) {
SappBindingConfigContactItem sappBindingConfigContactItem = (SappBindingConfigContactItem) provider.getBindingConfig(itemName);
SappAddressOpenClosedStatus statusAddress = sappBindingConfigContactItem.getStatus();
updateOpenClosedItem(provider, statusAddress, itemName, item);
} else if (item instanceof NumberItem) {
SappBindingConfigNumberItem sappBindingConfigNumberItem = (SappBindingConfigNumberItem) provider.getBindingConfig(itemName);
SappAddressDecimal statusAddress = sappBindingConfigNumberItem.getStatus();
updateDecimalItem(provider, statusAddress, itemName, item);
} else if (item instanceof RollershutterItem) {
SappBindingConfigRollershutterItem sappBindingConfigRollershutterItem = (SappBindingConfigRollershutterItem) provider.getBindingConfig(itemName);
SappAddressRollershutterStatus statusAddress = sappBindingConfigRollershutterItem.getStatus();
updateRollershutterItem(provider, statusAddress, itemName, item);
} else if (item instanceof DimmerItem) {
SappBindingConfigDimmerItem sappBindingConfigDimmerItem = (SappBindingConfigDimmerItem) provider.getBindingConfig(itemName);
SappAddressDimmer statusAddress = sappBindingConfigDimmerItem.getStatus();
updateDimmerItem(provider, statusAddress, itemName, item);
} else {
logger.error("unimplemented item type: {}", item.getClass().getSimpleName());
}
} catch (ItemNotFoundException e) {
logger.error("Item {} not found", itemName);
}
}
Aggregations