Search in sources :

Example 11 with HmDatapoint

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

the class GetAllScriptsParser method parse.

@Override
public Void parse(Object[] message) throws IOException {
    message = (Object[]) message[0];
    for (int i = 0; i < message.length; i++) {
        String scriptName = ObjectUtils.toString(message[i]);
        HmDatapoint dpScript = new HmDatapoint(scriptName, scriptName, HmValueType.BOOL, Boolean.FALSE, false, HmParamsetType.VALUES);
        dpScript.setInfo(scriptName);
        channel.addDatapoint(dpScript);
    }
    return null;
}
Also used : HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 12 with HmDatapoint

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

Example 13 with HmDatapoint

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

the class HomematicThingHandler method updateDynamicChannelList.

/**
 * Update the given thing channel list to reflect the device's current datapoint set
 *
 * @return true if the list was modified, false if it was not modified
 */
private boolean updateDynamicChannelList(HmDevice device, List<Channel> thingChannels) {
    boolean changed = false;
    for (HmChannel channel : device.getChannels()) {
        if (!channel.isReconfigurable()) {
            continue;
        }
        final String expectedFunction = channel.getDatapoint(HmParamsetType.MASTER, HomematicConstants.DATAPOINT_NAME_CHANNEL_FUNCTION).getOptionValue();
        final String propertyName = String.format(PROPERTY_DYNAMIC_FUNCTION_FORMAT, channel.getNumber());
        // remove thing channels that were configured for a different function
        Iterator<Channel> channelIter = thingChannels.iterator();
        while (channelIter.hasNext()) {
            Map<String, String> properties = channelIter.next().getProperties();
            String function = properties.get(propertyName);
            if (function != null && !function.equals(expectedFunction)) {
                channelIter.remove();
                changed = true;
            }
        }
        for (HmDatapoint dp : channel.getDatapoints()) {
            if (HomematicTypeGeneratorImpl.isIgnoredDatapoint(dp) || dp.getParamsetType() != HmParamsetType.VALUES) {
                continue;
            }
            ChannelUID channelUID = UidUtils.generateChannelUID(dp, getThing().getUID());
            if (containsChannel(thingChannels, channelUID)) {
                // Channel is already present -> channel configuration likely hasn't changed
                continue;
            }
            Map<String, String> channelProps = new HashMap<>();
            channelProps.put(propertyName, expectedFunction);
            Channel thingChannel = ChannelBuilder.create(channelUID, MetadataUtils.getItemType(dp)).withProperties(channelProps).withLabel(MetadataUtils.getLabel(dp)).withDescription(MetadataUtils.getDatapointDescription(dp)).withType(UidUtils.generateChannelTypeUID(dp)).build();
            thingChannels.add(thingChannel);
            changed = true;
        }
    }
    return changed;
}
Also used : HashMap(java.util.HashMap) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 14 with HmDatapoint

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

the class HomematicThingHandler method handleConfigurationUpdate.

@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters) throws ConfigValidationException {
    super.handleConfigurationUpdate(configurationParameters);
    try {
        HomematicGateway gateway = getHomematicGateway();
        HmDevice device = gateway.getDevice(UidUtils.getHomematicAddress(getThing()));
        for (Entry<String, Object> configurationParameter : configurationParameters.entrySet()) {
            String key = configurationParameter.getKey();
            Object newValue = configurationParameter.getValue();
            if (key.startsWith("HMP_")) {
                key = StringUtils.removeStart(key, "HMP_");
                Integer channelNumber = NumberUtils.toInt(StringUtils.substringBefore(key, "_"));
                String dpName = StringUtils.substringAfter(key, "_");
                HmDatapointInfo dpInfo = new HmDatapointInfo(device.getAddress(), HmParamsetType.MASTER, channelNumber, dpName);
                HmDatapoint dp = device.getChannel(channelNumber).getDatapoint(dpInfo);
                if (dp != null) {
                    try {
                        if (newValue != null) {
                            if (newValue instanceof BigDecimal) {
                                final BigDecimal decimal = (BigDecimal) newValue;
                                if (dp.isIntegerType()) {
                                    newValue = decimal.intValue();
                                } else if (dp.isFloatType()) {
                                    newValue = decimal.doubleValue();
                                }
                            }
                            if (ObjectUtils.notEqual(dp.isEnumType() ? dp.getOptionValue() : dp.getValue(), newValue)) {
                                sendDatapoint(dp, new HmDatapointConfig(), newValue);
                            }
                        }
                    } catch (IOException ex) {
                        logger.error("Error setting thing property {}: {}", dpInfo, ex.getMessage());
                    }
                } else {
                    logger.error("Can't find datapoint for thing property {}", dpInfo);
                }
            }
        }
        gateway.triggerDeviceValuesReload(device);
    } catch (HomematicClientException | GatewayNotAvailableException ex) {
        logger.error("Error setting thing properties: {}", ex.getMessage(), ex);
    }
}
Also used : HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HmDatapointConfig(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig) HomematicGateway(org.eclipse.smarthome.binding.homematic.internal.communicator.HomematicGateway) HmDatapointInfo(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo)

Example 15 with HmDatapoint

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

the class AbstractHomematicGateway method getDatapoint.

@Override
public HmDatapoint getDatapoint(HmDatapointInfo dpInfo) throws HomematicClientException {
    HmDevice device = getDevice(dpInfo.getAddress());
    HmChannel channel = device.getChannel(dpInfo.getChannel());
    if (channel == null) {
        throw new HomematicClientException(String.format("Channel %s in device '%s' not found on gateway '%s'", dpInfo.getChannel(), dpInfo.getAddress(), id));
    }
    HmDatapoint dp = channel.getDatapoint(dpInfo);
    if (dp == null) {
        throw new HomematicClientException(String.format("Datapoint '%s' not found on gateway '%s'", dpInfo, id));
    }
    return dp;
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) 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