Search in sources :

Example 26 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint 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 27 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint 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 28 with HmDatapoint

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

the class DeleteDeviceVirtualDatapointHandler method handleCommand.

@Override
public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value) throws IOException, HomematicClientException {
    dp.setValue(value);
    if (MiscUtils.isTrueValue(dp.getValue())) {
        try {
            HmDatapoint deleteMode = dp.getChannel().getDatapoint(HmDatapointInfo.createValuesInfo(dp.getChannel(), VIRTUAL_DATAPOINT_NAME_DELETE_DEVICE_MODE));
            HmDevice device = dp.getChannel().getDevice();
            int flag = -1;
            switch(deleteMode.getOptionValue()) {
                case MODE_RESET:
                    flag = 1;
                    break;
                case MODE_FORCE:
                    flag = 2;
                    break;
                case MODE_DEFER:
                    flag = 4;
            }
            if (flag == -1) {
                logger.info("Can't delete device '{}' from gateway '{}', DELETE_MODE is LOCKED", device.getAddress(), gateway.getId());
            } else {
                gateway.getRpcClient(device.getHmInterface()).deleteDevice(device, flag);
            }
        } finally {
            gateway.disableDatapoint(dp, AbstractHomematicGateway.DEFAULT_DISABLE_DELAY);
        }
    }
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 29 with HmDatapoint

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

the class DisplayTextVirtualDatapoint method addEnumDisplayDatapoint.

/**
 * Adds a Datapoint to the device with the values of the given enum.
 */
private void addEnumDisplayDatapoint(HmDevice device, int channelNumber, String datapointName, Class<? extends Enum<?>> e) {
    HmDatapoint dpEnum = addDatapoint(device, channelNumber, datapointName, HmValueType.ENUM, null, false);
    dpEnum.setOptions(getEnumNames(e));
    dpEnum.setMinValue(0);
    dpEnum.setMaxValue(e.getEnumConstants().length);
}
Also used : HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 30 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint 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)

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