Search in sources :

Example 6 with HmChannel

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

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

Example 8 with HmChannel

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

the class AbstractHomematicGateway method newDevices.

@Override
public void newDevices(List<String> adresses) {
    if (initialized && newDeviceEventsEnabled) {
        for (String address : adresses) {
            try {
                logger.debug("New device '{}' detected on gateway with id '{}'", address, id);
                List<HmDevice> deviceDescriptions = getDeviceDescriptions();
                for (HmDevice device : deviceDescriptions) {
                    if (device.getAddress().equals(address)) {
                        for (HmChannel channel : device.getChannels()) {
                            addChannelDatapoints(channel, HmParamsetType.MASTER);
                            addChannelDatapoints(channel, HmParamsetType.VALUES);
                        }
                        prepareDevice(device);
                        gatewayAdapter.onNewDevice(device);
                    }
                }
            } catch (Exception ex) {
                logger.error("{}", ex.getMessage(), ex);
            }
        }
    }
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) IOException(java.io.IOException) UnknownParameterSetException(org.eclipse.smarthome.binding.homematic.internal.communicator.client.UnknownParameterSetException)

Example 9 with HmChannel

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

the class AbstractHomematicGateway method updateRssiInfo.

private void updateRssiInfo(String address, String datapointName, Integer value) {
    HmDatapointInfo dpInfo = new HmDatapointInfo(address, HmParamsetType.VALUES, 0, datapointName);
    HmChannel channel;
    try {
        channel = getDevice(dpInfo.getAddress()).getChannel(0);
        if (channel != null) {
            eventReceived(dpInfo, value);
        }
    } catch (HomematicClientException e) {
    // ignore
    }
}
Also used : HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) HmDatapointInfo(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel)

Example 10 with HmChannel

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

the class AbstractHomematicGateway method setInstallMode.

@Override
public void setInstallMode(boolean enable, int seconds) throws IOException {
    HmDevice gwExtrasHm = devices.get(HmDevice.ADDRESS_GATEWAY_EXTRAS);
    if (gwExtrasHm != null) {
        // since the homematic virtual device exist: try setting install mode via its dataPoints
        HmDatapoint installModeDataPoint = null;
        HmDatapoint installModeDurationDataPoint = null;
        // collect virtual datapoints to be accessed
        HmChannel hmChannel = gwExtrasHm.getChannel(HmChannel.CHANNEL_NUMBER_EXTRAS);
        HmDatapointInfo installModeDurationDataPointInfo = new HmDatapointInfo(HmParamsetType.VALUES, hmChannel, HomematicConstants.VIRTUAL_DATAPOINT_NAME_INSTALL_MODE_DURATION);
        if (enable) {
            installModeDurationDataPoint = hmChannel.getDatapoint(installModeDurationDataPointInfo);
        }
        HmDatapointInfo installModeDataPointInfo = new HmDatapointInfo(HmParamsetType.VALUES, hmChannel, HomematicConstants.VIRTUAL_DATAPOINT_NAME_INSTALL_MODE);
        installModeDataPoint = hmChannel.getDatapoint(installModeDataPointInfo);
        // first set duration on the datapoint
        if (installModeDurationDataPoint != null) {
            try {
                VirtualDatapointHandler handler = getVirtualDatapointHandler(installModeDurationDataPoint, null);
                handler.handleCommand(this, installModeDurationDataPoint, new HmDatapointConfig(), seconds);
                // notify thing if exists
                gatewayAdapter.onStateUpdated(installModeDurationDataPoint);
            } catch (HomematicClientException ex) {
                logger.warn("Failed to send datapoint {}", installModeDurationDataPoint, ex);
            }
        }
        // now that the duration is set, we can enable / disable
        if (installModeDataPoint != null) {
            try {
                VirtualDatapointHandler handler = getVirtualDatapointHandler(installModeDataPoint, null);
                handler.handleCommand(this, installModeDataPoint, new HmDatapointConfig(), enable);
                // notify thing if exists
                gatewayAdapter.onStateUpdated(installModeDataPoint);
                return;
            } catch (HomematicClientException ex) {
                logger.warn("Failed to send datapoint {}", installModeDataPoint, ex);
            }
        }
    }
    // no gwExtrasHm available (or previous approach failed), therefore use rpc client directly
    for (HmInterface hmInterface : availableInterfaces.keySet()) {
        if (hmInterface == HmInterface.RF || hmInterface == HmInterface.CUXD) {
            getRpcClient(hmInterface).setInstallMode(hmInterface, enable, seconds);
        }
    }
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HmDatapointConfig(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig) HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) HmInterface(org.eclipse.smarthome.binding.homematic.internal.model.HmInterface) 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) ReloadFromGatewayVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ReloadFromGatewayVirtualDatapointHandler) RssiVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.RssiVirtualDatapointHandler) ReloadAllFromGatewayVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ReloadAllFromGatewayVirtualDatapointHandler) StateContactVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.StateContactVirtualDatapointHandler) SignalStrengthVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.SignalStrengthVirtualDatapointHandler) ButtonVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ButtonVirtualDatapointHandler) FirmwareVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.FirmwareVirtualDatapointHandler) ReloadRssiVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ReloadRssiVirtualDatapointHandler) DeleteDeviceModeVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceModeVirtualDatapointHandler) VirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.VirtualDatapointHandler) DeleteDeviceVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceVirtualDatapointHandler) HmwIoModuleVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.HmwIoModuleVirtualDatapointHandler) OnTimeAutomaticVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.OnTimeAutomaticVirtualDatapointHandler) BatteryTypeVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.BatteryTypeVirtualDatapointHandler) DisplayOptionsVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DisplayOptionsVirtualDatapointHandler)

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