Search in sources :

Example 16 with DimmerItem

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

the class AudioZone method updateItem.

@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
    int num = 0;
    String str = "";
    int source = new Integer(properties.getSource());
    switch(config.getObjectType()) {
        case AUDIOZONE_MUTE:
            num = properties.isMute() ? 1 : 0;
            break;
        case AUDIOZONE_POWER:
            num = properties.isOn() ? 1 : 0;
            break;
        case AUDIOZONE_SOURCE:
            num = properties.getSource();
            break;
        case AUDIOZONE_VOLUME:
            num = properties.getVolume();
            break;
        case AUDIOZONE_TEXT:
            if (sourceValid(source)) {
                str = audioSources.get(source).formatAudioText();
            }
            break;
        case AUDIOZONE_TEXT_FIELD1:
            if (sourceValid(source)) {
                str = audioSources.get(source).getAudioText(0);
            }
            break;
        case AUDIOZONE_TEXT_FIELD2:
            if (sourceValid(source)) {
                str = audioSources.get(source).getAudioText(1);
            }
            break;
        case AUDIOZONE_TEXT_FIELD3:
            if (sourceValid(source)) {
                str = audioSources.get(source).getAudioText(2);
            }
            break;
        case AUDIOZONE_KEY:
            num = -1;
            break;
        default:
            return;
    }
    if (item instanceof DimmerItem) {
        logger.debug("updating percent type {}", num);
        publisher.postUpdate(item.getName(), new PercentType(num));
    } else if (item instanceof NumberItem) {
        logger.debug("updating number type {}", num);
        publisher.postUpdate(item.getName(), new DecimalType(num));
    } else if (item instanceof SwitchItem) {
        logger.debug("updating switch type {}", num > 0 ? OnOffType.ON : OnOffType.OFF);
        publisher.postUpdate(item.getName(), num > 0 ? OnOffType.ON : OnOffType.OFF);
    } else if (item instanceof StringItem) {
        logger.debug("updating string type {}", str);
        publisher.postUpdate(item.getName(), new StringType(str));
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) DimmerItem(org.openhab.core.library.items.DimmerItem) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 17 with DimmerItem

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

the class RockerSwitchInDimmerProfileTest method setUpDefaultDevice.

@Before
public void setUpDefaultDevice() {
    parameterAddress = new EnoceanParameterAddress(EnoceanId.fromString(EnoceanBindingProviderMock.DEVICE_ID));
    provider.setParameterAddress(parameterAddress);
    provider.setItem(new DimmerItem("dummie"));
    provider.setEep(EEPId.EEP_F6_02_01);
    binding.addBindingProvider(provider);
}
Also used : EnoceanParameterAddress(org.opencean.core.address.EnoceanParameterAddress) DimmerItem(org.openhab.core.library.items.DimmerItem) Before(org.junit.Before)

Example 18 with DimmerItem

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

the class DigitalSTROMBinding method updateItemState.

private void updateItemState(Item item) {
    if (item != null) {
        Device device = deviceMap.get(item.getName());
        if (device != null) {
            State state = null;
            if (item instanceof DimmerItem) {
                state = new PercentType(getPercent(device.getMaxOutPutValue(), device.getOutputValue()));
            } else if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
                state = device.getOutputValue() > 0 ? OnOffType.ON : OnOffType.OFF;
            } else if (item instanceof NumberItem) {
                DigitalSTROMBindingConfig confItem = getConfigForItemName(item.getName());
                if (confItem != null) {
                    if (confItem.sensor != null) {
                        int value = -1;
                        switch(confItem.sensor) {
                            case TEMPERATURE_INDOORS:
                                value = device.getTemperatureSensorValue();
                                if (value != -1) {
                                    // Celsius
                                    // TODO use resolution
                                    state = new DecimalType((double) (value) / 40 - 43.15);
                                // from sensor
                                }
                                break;
                            case RELATIVE_HUMIDITY_INDOORS:
                                value = device.getHumiditySensorValue();
                                if (value != -1) {
                                    // Percent
                                    // TODO use resolution from
                                    state = new DecimalType((double) (value) / 40);
                                // sensor
                                }
                                break;
                            case TEMPERATURE_OUTDOORS:
                                value = device.getTemperatureSensorValue();
                                if (value != -1) {
                                    // Celsius
                                    // TODO use resolution
                                    state = new DecimalType((double) (value) / 40 - 43.15);
                                // from sensor
                                }
                                break;
                            case RELATIVE_HUMIDITY_OUTDOORS:
                                value = device.getHumiditySensorValue();
                                if (value != -1) {
                                    // Percent
                                    // TODO use resolution from
                                    state = new DecimalType((double) (value) / 40);
                                // sensor
                                }
                                break;
                            default:
                                break;
                        }
                    } else if (confItem.consumption != null) {
                        int value = -1;
                        switch(confItem.consumption) {
                            case ACTIVE_POWER:
                                value = device.getPowerConsumption();
                                break;
                            case OUTPUT_CURRENT:
                                value = device.getEnergyMeterValue();
                                if (value != -1) {
                                    state = new DecimalType(value);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
            } else if (item instanceof RollershutterItem) {
                DigitalSTROMBindingConfig confItem = getConfigForItemName(item.getName());
                if (confItem != null) {
                    if (confItem.context != null && confItem.context.equals(ContextConfig.slat)) {
                        int output = getPercent(device.getMaxSlatPosition(), device.getSlatPosition());
                        state = new PercentType(100 - output);
                    } else if (confItem.context != null && confItem.context.equals(ContextConfig.awning)) {
                        int output = getPercent(device.getMaxOutPutValue(), device.getOutputValue());
                        state = new PercentType(output);
                    } else {
                        int output = getPercent(device.getMaxOutPutValue(), device.getOutputValue());
                        state = new PercentType(100 - output);
                    }
                }
            } else if (item instanceof StringItem) {
                DigitalSTROMBindingConfig confItem = getConfigForItemName(item.getName());
                if (confItem != null) {
                    if (confItem.sensor != null) {
                        int value = -1;
                        switch(confItem.sensor) {
                            case TEMPERATURE_INDOORS:
                                value = device.getTemperatureSensorValue();
                                if (value != -1) {
                                    // Celsius
                                    // TODO use resolution
                                    state = new DecimalType((double) (value) / 40 - 43.15);
                                // from sensor
                                }
                                break;
                            case RELATIVE_HUMIDITY_INDOORS:
                                value = device.getHumiditySensorValue();
                                if (value != -1) {
                                    // Percent
                                    // TODO use resolution from
                                    state = new DecimalType((double) (value) / 40);
                                // sensor
                                }
                                break;
                            case TEMPERATURE_OUTDOORS:
                                value = device.getTemperatureSensorValue();
                                if (value != -1) {
                                    // Celsius
                                    // TODO use resolution
                                    state = new DecimalType((double) (value) / 40 - 43.15);
                                // from sensor
                                }
                                break;
                            case RELATIVE_HUMIDITY_OUTDOORS:
                                value = device.getHumiditySensorValue();
                                if (value != -1) {
                                    // Percent
                                    // TODO use resolution from
                                    state = new DecimalType((double) (value) / 40);
                                // sensor
                                }
                                break;
                            default:
                                break;
                        }
                    } else if (confItem.consumption != null) {
                        int value = -1;
                        switch(confItem.consumption) {
                            case ACTIVE_POWER:
                                value = device.getPowerConsumption();
                                if (value != -1) {
                                    state = new DecimalType(value);
                                }
                                break;
                            case OUTPUT_CURRENT:
                                value = device.getEnergyMeterValue();
                                if (value != -1) {
                                    state = new DecimalType(value);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            eventPublisher.postUpdate(item.getName(), state);
        } else {
            logger.error("couldn't update item state, because device is null: " + item.getName());
        }
    } else {
        logger.error("couldn't update item state, because item is null");
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) Device(org.openhab.binding.digitalstrom.internal.client.entity.Device) State(org.openhab.core.types.State) DimmerItem(org.openhab.core.library.items.DimmerItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DigitalSTROMBindingConfig(org.openhab.binding.digitalstrom.internal.config.DigitalSTROMBindingConfig) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 19 with DimmerItem

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

the class HueGenericBindingProvider method processBindingConfiguration.

@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 (item instanceof ColorItem) {
                BindingConfig hueBindingConfig = new HueBindingConfig(configParts[0], BindingType.rgb.name(), null);
                addBindingConfig(item, hueBindingConfig);
            } else if (item instanceof DimmerItem) {
                BindingConfig hueBindingConfig = new HueBindingConfig(configParts[0], configParts.length < 2 ? null : configParts[1], configParts.length < 3 ? null : configParts[2]);
                addBindingConfig(item, hueBindingConfig);
            } else if (item instanceof SwitchItem) {
                BindingConfig hueBindingConfig = new HueBindingConfig(configParts[0], BindingType.switching.name(), null);
                addBindingConfig(item, hueBindingConfig);
            }
        } 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 : BindingConfig(org.openhab.core.binding.BindingConfig) DimmerItem(org.openhab.core.library.items.DimmerItem) ColorItem(org.openhab.core.library.items.ColorItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 20 with DimmerItem

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

the class LightwaveRfBindingFunctionalTest method testOffMessageSentByAndriodApp.

@Test
public void testOffMessageSentByAndriodApp() throws Exception {
    String message = "030271,102,!R3D1F0|Living Room|Side Light 1 Off";
    testReceivingACommandAndVerify(new DimmerItem("LivingRoom"), "room=3,device=1,type=DIMMER", message, OnOffType.OFF);
}
Also used : DimmerItem(org.openhab.core.library.items.DimmerItem) Test(org.junit.Test)

Aggregations

DimmerItem (org.openhab.core.library.items.DimmerItem)34 SwitchItem (org.openhab.core.library.items.SwitchItem)20 PercentType (org.openhab.core.library.types.PercentType)18 NumberItem (org.openhab.core.library.items.NumberItem)16 RollershutterItem (org.openhab.core.library.items.RollershutterItem)15 ColorItem (org.openhab.core.library.items.ColorItem)13 ContactItem (org.openhab.core.library.items.ContactItem)11 DecimalType (org.openhab.core.library.types.DecimalType)11 Test (org.junit.Test)9 State (org.openhab.core.types.State)9 DateTimeItem (org.openhab.core.library.items.DateTimeItem)7 StringType (org.openhab.core.library.types.StringType)7 Calendar (java.util.Calendar)6 Item (org.openhab.core.items.Item)6 DateTimeType (org.openhab.core.library.types.DateTimeType)6 HSBType (org.openhab.core.library.types.HSBType)6 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)5 StringItem (org.openhab.core.library.items.StringItem)5 SappBindingConfigContactItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem)4 SappBindingConfigDimmerItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem)4