Search in sources :

Example 1 with HmChannel

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

the class AbstractVirtualDatapointHandler method addDatapoint.

/**
 * Creates a new datapoint with the given parameters and adds it to the channel.
 */
protected HmDatapoint addDatapoint(HmDevice device, Integer channelNumber, String datapointName, HmValueType valueType, Object value, boolean readOnly) {
    HmChannel channel = device.getChannel(channelNumber);
    HmDatapoint dp = new HmDatapoint(datapointName, datapointName, valueType, value, readOnly, HmParamsetType.VALUES);
    return addDatapoint(channel, dp);
}
Also used : HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 2 with HmChannel

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

the class DisplayOptionsVirtualDatapointHandler method handleCommand.

@Override
public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value) throws IOException, HomematicClientException {
    HmChannel channel = dp.getChannel();
    DisplayOptionsParser rcOptionsParser = new DisplayOptionsParser(channel);
    rcOptionsParser.parse(value);
    if (StringUtils.isNotBlank(rcOptionsParser.getText())) {
        sendDatapoint(gateway, channel, DATAPOINT_NAME_TEXT, rcOptionsParser.getText());
    }
    sendDatapoint(gateway, channel, DATAPOINT_NAME_BEEP, rcOptionsParser.getBeep());
    sendDatapoint(gateway, channel, DATAPOINT_NAME_UNIT, rcOptionsParser.getUnit());
    sendDatapoint(gateway, channel, DATAPOINT_NAME_BACKLIGHT, rcOptionsParser.getBacklight());
    for (String symbol : rcOptionsParser.getSymbols()) {
        sendDatapoint(gateway, channel, symbol, Boolean.TRUE);
    }
    sendDatapoint(gateway, channel, DATAPOINT_NAME_SUBMIT, Boolean.TRUE);
    dp.setValue(value);
}
Also used : DisplayOptionsParser(org.eclipse.smarthome.binding.homematic.internal.communicator.parser.DisplayOptionsParser) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel)

Example 3 with HmChannel

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

the class OnTimeAutomaticVirtualDatapointHandler method initialize.

@Override
public void initialize(HmDevice device) {
    for (HmChannel channel : device.getChannels()) {
        HmDatapointInfo dpInfoOnTime = HmDatapointInfo.createValuesInfo(channel, DATAPOINT_NAME_ON_TIME);
        if (channel.hasDatapoint(dpInfoOnTime)) {
            HmDatapointInfo dpInfoLevel = HmDatapointInfo.createValuesInfo(channel, DATAPOINT_NAME_LEVEL);
            HmDatapointInfo dpInfoState = HmDatapointInfo.createValuesInfo(channel, DATAPOINT_NAME_STATE);
            if (channel.hasDatapoint(dpInfoLevel) || channel.hasDatapoint(dpInfoState)) {
                HmDatapoint dpOnTime = channel.getDatapoint(dpInfoOnTime);
                HmDatapoint dpOnTimeAutomatic = dpOnTime.clone();
                dpOnTimeAutomatic.setName(getName());
                dpOnTimeAutomatic.setDescription(getName());
                addDatapoint(channel, dpOnTimeAutomatic);
            }
        }
    }
}
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 4 with HmChannel

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

the class DisplayTextVirtualDatapoint method handleCommand.

@Override
public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value) throws IOException, HomematicClientException {
    dp.setValue(value);
    if (DATAPOINT_NAME_DISPLAY_SUBMIT.equals(dp.getName()) && MiscUtils.isTrueValue(dp.getValue())) {
        HmChannel channel = dp.getChannel();
        boolean isEp = isEpDisplay(channel.getDevice());
        List<String> message = new ArrayList<String>();
        message.add(START);
        if (isEp) {
            message.add(LF);
        }
        for (int i = 1; i <= getLineCount(channel.getDevice()); i++) {
            String line = ObjectUtils.toString(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_LINE + i).getValue());
            if (StringUtils.isEmpty(line)) {
                line = " ";
            }
            message.add(LINE);
            message.add(encodeText(line));
            if (!isEp) {
                String color = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_COLOR + i).getOptionValue();
                message.add(COLOR);
                String colorCode = Color.getCode(color);
                message.add(StringUtils.isBlank(colorCode) ? Color.WHITE.getCode() : colorCode);
            }
            String icon = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_ICON + i).getOptionValue();
            String iconCode = Icon.getCode(icon);
            if (StringUtils.isNotBlank(iconCode)) {
                message.add(ICON);
                message.add(iconCode);
            }
            message.add(LF);
        }
        if (isEp) {
            String beeper = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_BEEPER).getOptionValue();
            message.add(BEEPER_START);
            message.add(Beeper.getCode(beeper));
            message.add(BEEPER_END);
            // set number of beeps
            message.add(encodeBeepCount(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_BEEPCOUNT)));
            message.add(BEEPCOUNT_END);
            // set interval between two beeps
            message.add(encodeBeepInterval(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_BEEPINTERVAL)));
            message.add(BEEPINTERVAL_END);
            // LED value must always set (same as beeps)
            String led = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_LED).getOptionValue();
            message.add(Led.getCode(led));
        }
        message.add(STOP);
        gateway.sendDatapoint(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_SUBMIT), new HmDatapointConfig(), StringUtils.join(message, ","), null);
    }
}
Also used : HmDatapointConfig(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig) ArrayList(java.util.ArrayList) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 5 with HmChannel

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

the class HomematicThingHandler method doInitializeInBackground.

private void doInitializeInBackground() throws GatewayNotAvailableException, HomematicClientException, IOException {
    HomematicGateway gateway = getHomematicGateway();
    HmDevice device = gateway.getDevice(UidUtils.getHomematicAddress(getThing()));
    HmChannel channelZero = device.getChannel(0);
    loadHomematicChannelValues(channelZero);
    updateStatus(device);
    logger.debug("Initializing thing '{}' from gateway '{}'", getThing().getUID(), gateway.getId());
    // update properties
    Map<String, String> properties = editProperties();
    setProperty(properties, channelZero, PROPERTY_BATTERY_TYPE, VIRTUAL_DATAPOINT_NAME_BATTERY_TYPE);
    setProperty(properties, channelZero, Thing.PROPERTY_FIRMWARE_VERSION, VIRTUAL_DATAPOINT_NAME_FIRMWARE);
    setProperty(properties, channelZero, Thing.PROPERTY_SERIAL_NUMBER, device.getAddress());
    setProperty(properties, channelZero, PROPERTY_AES_KEY, DATAPOINT_NAME_AES_KEY);
    updateProperties(properties);
    // update data point list for reconfigurable channels
    for (HmChannel channel : device.getChannels()) {
        if (channel.isReconfigurable()) {
            loadHomematicChannelValues(channel);
            if (channel.checkForChannelFunctionChange()) {
                gateway.updateChannelValueDatapoints(channel);
            }
        }
    }
    // update configurations
    Configuration config = editConfiguration();
    for (HmChannel channel : device.getChannels()) {
        loadHomematicChannelValues(channel);
        for (HmDatapoint dp : channel.getDatapoints()) {
            if (dp.getParamsetType() == HmParamsetType.MASTER) {
                config.put(MetadataUtils.getParameterName(dp), dp.isEnumType() ? dp.getOptionValue() : dp.getValue());
            }
        }
    }
    updateConfiguration(config);
    // update thing channel list for reconfigurable channels (relies on the new value of the
    // CHANNEL_FUNCTION datapoint fetched during configuration update)
    List<Channel> thingChannels = new ArrayList<>(getThing().getChannels());
    if (updateDynamicChannelList(device, thingChannels)) {
        updateThing(editThing().withChannels(thingChannels).build());
    }
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) Configuration(org.eclipse.smarthome.config.core.Configuration) Channel(org.eclipse.smarthome.core.thing.Channel) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) ArrayList(java.util.ArrayList) HomematicGateway(org.eclipse.smarthome.binding.homematic.internal.communicator.HomematicGateway) 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