Search in sources :

Example 16 with HmChannel

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

the class HomematicTypeGeneratorImpl method generate.

@Override
public void generate(HmDevice device) {
    if (thingTypeProvider != null) {
        ThingTypeUID thingTypeUID = UidUtils.generateThingTypeUID(device);
        ThingType tt = thingTypeProvider.getInternalThingType(thingTypeUID);
        if (tt == null || device.isGatewayExtras()) {
            logger.debug("Generating ThingType for device '{}' with {} datapoints", device.getType(), device.getDatapointCount());
            List<ChannelGroupType> groupTypes = new ArrayList<ChannelGroupType>();
            for (HmChannel channel : device.getChannels()) {
                List<ChannelDefinition> channelDefinitions = new ArrayList<ChannelDefinition>();
                // those will be populated dynamically during thing initialization
                if (!channel.isReconfigurable()) {
                    // generate channel
                    for (HmDatapoint dp : channel.getDatapoints()) {
                        if (!isIgnoredDatapoint(dp) && dp.getParamsetType() == HmParamsetType.VALUES) {
                            ChannelTypeUID channelTypeUID = UidUtils.generateChannelTypeUID(dp);
                            ChannelType channelType = channelTypeProvider.getInternalChannelType(channelTypeUID);
                            if (channelType == null) {
                                channelType = createChannelType(dp, channelTypeUID);
                                channelTypeProvider.addChannelType(channelType);
                            }
                            ChannelDefinition channelDef = new ChannelDefinitionBuilder(dp.getName(), channelType.getUID()).build();
                            channelDefinitions.add(channelDef);
                        }
                    }
                }
                // generate group
                ChannelGroupTypeUID groupTypeUID = UidUtils.generateChannelGroupTypeUID(channel);
                ChannelGroupType groupType = channelGroupTypeProvider.getInternalChannelGroupType(groupTypeUID);
                if (groupType == null || device.isGatewayExtras()) {
                    String groupLabel = String.format("%s", WordUtils.capitalizeFully(StringUtils.replace(channel.getType(), "_", " ")));
                    groupType = ChannelGroupTypeBuilder.instance(groupTypeUID, groupLabel).withChannelDefinitions(channelDefinitions).build();
                    channelGroupTypeProvider.addChannelGroupType(groupType);
                    groupTypes.add(groupType);
                }
            }
            tt = createThingType(device, groupTypes);
            thingTypeProvider.addThingType(tt);
        }
        addFirmware(device);
    }
}
Also used : ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) ArrayList(java.util.ArrayList) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelGroupTypeUID(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType)

Example 17 with HmChannel

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

the class StateContactVirtualDatapointHandler method initialize.

@Override
public void initialize(HmDevice device) {
    if (isApplicable(device)) {
        HmChannel channelOne = device.getChannel(1);
        if (channelOne != null) {
            HmDatapointInfo dpStateInfo = HmDatapointInfo.createValuesInfo(channelOne, DATAPOINT_NAME_STATE);
            HmDatapoint dpState = channelOne.getDatapoint(dpStateInfo);
            if (dpState != null) {
                addDatapoint(device, 1, getName(), HmValueType.BOOL, convertState(dpState.getValue()), true);
            }
        }
    }
}
Also used : HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapointInfo(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 18 with HmChannel

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

the class DisplayTextVirtualDatapoint method initialize.

@Override
public void initialize(HmDevice device) {
    if (isDisplay(device)) {
        for (HmChannel channel : device.getChannels()) {
            if (channel.hasDatapoint(new HmDatapointInfo(HmParamsetType.VALUES, channel, DATAPOINT_NAME_SUBMIT))) {
                for (int i = 1; i <= getLineCount(device); i++) {
                    addDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_LINE + i, HmValueType.STRING, null, false);
                    addEnumDisplayDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_ICON + i, Icon.class);
                    if (!isEpDisplay(device)) {
                        addEnumDisplayDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_COLOR + i, Color.class);
                    }
                }
                if (isEpDisplay(device)) {
                    addEnumDisplayDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_BEEPER, Beeper.class);
                    HmDatapoint bc = addDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_BEEPCOUNT, HmValueType.INTEGER, 1, false);
                    bc.setMinValue(0);
                    bc.setMaxValue(15);
                    HmDatapoint bd = addDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_BEEPINTERVAL, HmValueType.INTEGER, 1, false);
                    bd.setMinValue(10);
                    bd.setMaxValue(160);
                    bd.setStep(10);
                    addEnumDisplayDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_LED, Led.class);
                }
                addDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_SUBMIT, HmValueType.BOOL, false, false);
            }
        }
    }
}
Also used : HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapointInfo(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 19 with HmChannel

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

the class HmwIoModuleVirtualDatapointHandler method initialize.

@Override
public void initialize(HmDevice device) {
    if (device.getType().startsWith(DEVICE_TYPE_WIRED_IO_MODULE)) {
        for (HmChannel channel : device.getChannels()) {
            if (channel.getNumber() >= 7) {
                HmDatapointInfo dpInfoState = HmDatapointInfo.createValuesInfo(channel, DATAPOINT_NAME_STATE);
                HmDatapointInfo dpInfoValue = HmDatapointInfo.createValuesInfo(channel, DATAPOINT_NAME_VALUE);
                boolean hasStateDatapoint = channel.hasDatapoint(dpInfoState);
                boolean hasValueDatapoint = channel.hasDatapoint(dpInfoValue);
                if (hasStateDatapoint && !hasValueDatapoint) {
                    HmDatapoint dp = addDatapoint(channel.getDevice(), channel.getNumber(), DATAPOINT_NAME_VALUE, HmValueType.FLOAT, 0.0, false);
                    dp.setMinValue(0.0);
                    dp.setMaxValue(1000.0);
                    dp.setVirtual(false);
                } else if (hasValueDatapoint && !hasStateDatapoint) {
                    HmDatapoint dp = addDatapoint(channel.getDevice(), channel.getNumber(), DATAPOINT_NAME_STATE, HmValueType.BOOL, false, false);
                    dp.setVirtual(false);
                }
            }
            if (channel.getNumber() >= 21) {
                HmDatapointInfo dpInfoCalibration = new HmDatapointInfo(HmParamsetType.MASTER, channel, DATAPOINT_NAME_CALIBRATION);
                if (!channel.hasDatapoint(dpInfoCalibration)) {
                    HmDatapoint dp = new HmDatapoint(DATAPOINT_NAME_CALIBRATION, DATAPOINT_NAME_CALIBRATION, HmValueType.INTEGER, 0, false, HmParamsetType.MASTER);
                    dp.setMinValue(-127);
                    dp.setMaxValue(127);
                    addDatapoint(channel, dp);
                    dp.setVirtual(false);
                }
            }
        }
    }
}
Also used : HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapointInfo(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 20 with HmChannel

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

the class ButtonVirtualDatapointHandler method initialize.

@Override
public void initialize(HmDevice device) {
    for (HmChannel channel : device.getChannels()) {
        if (channel.hasPressDatapoint()) {
            HmDatapoint dp = addDatapoint(device, channel.getNumber(), getName(), HmValueType.STRING, null, false);
            dp.setTrigger(true);
            dp.setOptions(new String[] { CommonTriggerEvents.SHORT_PRESSED, CommonTriggerEvents.LONG_PRESSED, CommonTriggerEvents.DOUBLE_PRESSED });
        }
    }
}
Also used : HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Aggregations

HmChannel (org.eclipse.smarthome.binding.homematic.internal.model.HmChannel)35 HmDatapoint (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)19 HmDevice (org.eclipse.smarthome.binding.homematic.internal.model.HmDevice)9 DimmerHelper.createDimmerHmChannel (org.eclipse.smarthome.binding.homematic.test.util.DimmerHelper.createDimmerHmChannel)7 Test (org.junit.Test)7 HmDatapointInfo (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo)6 JavaTest (org.eclipse.smarthome.test.java.JavaTest)5 ArrayList (java.util.ArrayList)4 HomematicClientException (org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException)4 HashMap (java.util.HashMap)3 HmDatapointConfig (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig)3 IOException (java.io.IOException)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 DisplayOptionsVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DisplayOptionsVirtualDatapointHandler)2 FirmwareVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.FirmwareVirtualDatapointHandler)2 HmwIoModuleVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.HmwIoModuleVirtualDatapointHandler)2 OnTimeAutomaticVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.OnTimeAutomaticVirtualDatapointHandler)2