Search in sources :

Example 51 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class ButtonDatapointTest method testShortPress.

@Test
public void testShortPress() throws IOException, HomematicClientException {
    HmDatapoint shortPressDp = createPressDatapoint("PRESS_SHORT", Boolean.TRUE);
    HmDatapoint buttonVirtualDatapoint = getButtonVirtualDatapoint(shortPressDp);
    mockEventReceiver.eventReceived(shortPressDp);
    assertThat(buttonVirtualDatapoint.getValue(), is(CommonTriggerEvents.SHORT_PRESSED));
}
Also used : HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Example 52 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class ButtonDatapointTest method testUnsupportedEvents.

@Test
public void testUnsupportedEvents() throws IOException, HomematicClientException {
    HmDatapoint contPressDp = createPressDatapoint("PRESS_CONT", Boolean.TRUE);
    HmDatapoint contButtonVirtualDatapoint = getButtonVirtualDatapoint(contPressDp);
    mockEventReceiver.eventReceived(contPressDp);
    HmDatapoint releaseDp = createPressDatapoint("PRESS_LONG_RELEASE", Boolean.TRUE);
    HmDatapoint releaseButtonVirtualDatapoint = getButtonVirtualDatapoint(releaseDp);
    mockEventReceiver.eventReceived(releaseDp);
    HmDatapoint crapDp = createPressDatapoint("CRAP", Boolean.TRUE);
    HmDatapoint crapButtonVirtualDatapoint = getButtonVirtualDatapoint(releaseDp);
    mockEventReceiver.eventReceived(crapDp);
    assertThat(contButtonVirtualDatapoint.getValue(), nullValue());
    assertThat(releaseButtonVirtualDatapoint.getValue(), nullValue());
    assertThat(crapButtonVirtualDatapoint.getValue(), nullValue());
}
Also used : HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Example 53 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class CcuVariablesAndScriptsParser method parse.

@Override
public Void parse(TclScriptDataList resultList) throws IOException {
    if (resultList.getEntries() != null) {
        for (TclScriptDataEntry entry : resultList.getEntries()) {
            HmDatapoint dp = channel.getDatapoint(HmParamsetType.VALUES, entry.name);
            if (dp != null) {
                dp.setValue(convertToType(entry.value));
            } else {
                dp = new HmDatapoint();
                dp.setName(entry.name);
                dp.setInfo(entry.name);
                dp.setDescription(entry.description);
                dp.setType(HmValueType.parse(entry.valueType));
                dp.setValue(convertToType(entry.value));
                if (dp.isIntegerType()) {
                    dp.setMinValue(toInteger(entry.minValue));
                    dp.setMaxValue(toInteger(entry.maxValue));
                } else {
                    dp.setMinValue(toDouble(entry.minValue));
                    dp.setMaxValue(toDouble(entry.maxValue));
                }
                dp.setReadOnly(entry.readOnly);
                dp.setUnit(entry.unit);
                String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(entry.options, ";");
                dp.setOptions(result == null || result.length == 0 ? null : result);
                if (dp.getOptions() != null) {
                    dp.setMinValue(0);
                    dp.setMaxValue(dp.getOptions().length - 1);
                }
                dp.setParamsetType(HmParamsetType.VALUES);
                channel.addDatapoint(dp);
            }
        }
    }
    return null;
}
Also used : TclScriptDataEntry(org.eclipse.smarthome.binding.homematic.internal.model.TclScriptDataEntry) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 54 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class MetadataUtils method generateOptions.

/**
 * Creates channel and config description metadata options for the given Datapoint.
 */
public static <T> List<T> generateOptions(HmDatapoint dp, OptionsBuilder<T> optionsBuilder) {
    List<T> options = null;
    if (dp.getOptions() == null) {
        logger.warn("No options for ENUM datapoint {}", dp);
    } else {
        options = new ArrayList<T>();
        for (int i = 0; i < dp.getOptions().length; i++) {
            String description = null;
            if (!dp.isVariable() && !dp.isScript()) {
                description = getDescription(dp.getChannel().getType(), dp.getName(), dp.getOptions()[i]);
            }
            if (description == null) {
                description = dp.getOptions()[i];
            }
            options.add(optionsBuilder.createOption(dp.getOptions()[i], description));
        }
    }
    return options;
}
Also used : HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 55 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class HomematicTypeGeneratorImpl method generateConfigDescription.

private void generateConfigDescription(HmDevice device, URI configDescriptionURI) {
    List<ConfigDescriptionParameter> parms = new ArrayList<ConfigDescriptionParameter>();
    List<ConfigDescriptionParameterGroup> groups = new ArrayList<ConfigDescriptionParameterGroup>();
    for (HmChannel channel : device.getChannels()) {
        String groupName = "HMG_" + channel.getNumber();
        String groupLabel = MetadataUtils.getDescription("CHANNEL_NAME") + " " + channel.getNumber();
        groups.add(new ConfigDescriptionParameterGroup(groupName, null, false, groupLabel, null));
        for (HmDatapoint dp : channel.getDatapoints()) {
            if (dp.getParamsetType() == HmParamsetType.MASTER) {
                ConfigDescriptionParameterBuilder builder = ConfigDescriptionParameterBuilder.create(MetadataUtils.getParameterName(dp), MetadataUtils.getConfigDescriptionParameterType(dp));
                builder.withLabel(MetadataUtils.getLabel(dp));
                builder.withDefault(ObjectUtils.toString(dp.getDefaultValue()));
                builder.withDescription(MetadataUtils.getDatapointDescription(dp));
                if (dp.isEnumType()) {
                    builder.withLimitToOptions(dp.isEnumType());
                    List<ParameterOption> options = MetadataUtils.generateOptions(dp, new OptionsBuilder<ParameterOption>() {

                        @Override
                        public ParameterOption createOption(String value, String description) {
                            return new ParameterOption(value, description);
                        }
                    });
                    builder.withOptions(options);
                }
                if (dp.isNumberType()) {
                    builder.withMinimum(MetadataUtils.createBigDecimal(dp.getMinValue()));
                    builder.withMaximum(MetadataUtils.createBigDecimal(dp.getMaxValue()));
                    builder.withStepSize(MetadataUtils.createBigDecimal(dp.isFloatType() ? new Float(0.1) : 1L));
                    builder.withUnitLabel(MetadataUtils.getUnit(dp));
                }
                builder.withGroupName(groupName);
                parms.add(builder.build());
            }
        }
    }
    configDescriptionProvider.addConfigDescription(new ConfigDescription(configDescriptionURI, parms, groups));
}
Also used : ArrayList(java.util.ArrayList) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ConfigDescriptionParameterBuilder(org.eclipse.smarthome.config.core.ConfigDescriptionParameterBuilder) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) ConfigDescriptionParameterGroup(org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup) ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel)

Aggregations

HmDatapoint (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)55 HmChannel (org.eclipse.smarthome.binding.homematic.internal.model.HmChannel)21 HmDatapointInfo (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo)12 HmDatapointConfig (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig)7 HmDevice (org.eclipse.smarthome.binding.homematic.internal.model.HmDevice)7 Test (org.junit.Test)6 IOException (java.io.IOException)5 HomematicClientException (org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException)5 ArrayList (java.util.ArrayList)4 HomematicGateway (org.eclipse.smarthome.binding.homematic.internal.communicator.HomematicGateway)4 Channel (org.eclipse.smarthome.core.thing.Channel)4 JavaTest (org.eclipse.smarthome.test.java.JavaTest)4 Map (java.util.Map)3 TclScriptDataEntry (org.eclipse.smarthome.binding.homematic.internal.model.TclScriptDataEntry)3 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)3 HashMap (java.util.HashMap)2 BatteryTypeVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.BatteryTypeVirtualDatapointHandler)2 ButtonVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ButtonVirtualDatapointHandler)2 DeleteDeviceModeVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceModeVirtualDatapointHandler)2 DeleteDeviceVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceVirtualDatapointHandler)2