Search in sources :

Example 16 with HmDatapoint

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

Example 17 with HmDatapoint

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

the class AbstractHomematicGateway method cloneAllDatapointsIntoChannel.

/**
 * Clones all datapoints into the given channel.
 */
private void cloneAllDatapointsIntoChannel(HmChannel channel, Collection<HmDatapoint> datapoints) {
    logger.trace("    Cloning {} datapoints into channel {}", datapoints.size(), channel);
    for (HmDatapoint dp : datapoints) {
        if (!dp.isVirtual()) {
            HmDatapoint clonedDp = dp.clone();
            clonedDp.setValue(null);
            channel.addDatapoint(clonedDp);
        }
    }
}
Also used : HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 18 with HmDatapoint

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

the class AbstractHomematicGateway method loadAllDeviceMetadata.

@Override
public void loadAllDeviceMetadata() throws IOException {
    cancelLoadAllMetadata = false;
    // load all device descriptions
    List<HmDevice> deviceDescriptions = getDeviceDescriptions();
    // loading datapoints for all channels
    Set<String> loadedDevices = new HashSet<String>();
    Map<String, Collection<HmDatapoint>> datapointsByChannelIdCache = new HashMap<String, Collection<HmDatapoint>>();
    for (HmDevice device : deviceDescriptions) {
        if (!cancelLoadAllMetadata) {
            try {
                logger.trace("Loading metadata for device '{}' of type '{}'", device.getAddress(), device.getType());
                if (device.isGatewayExtras()) {
                    loadChannelValues(device.getChannel(HmChannel.CHANNEL_NUMBER_VARIABLE));
                    loadChannelValues(device.getChannel(HmChannel.CHANNEL_NUMBER_SCRIPT));
                } else {
                    for (HmChannel channel : device.getChannels()) {
                        logger.trace("  Loading channel {}", channel);
                        // speed up metadata generation a little bit for equal channels in the gateway devices
                        if ((DEVICE_TYPE_VIRTUAL.equals(device.getType()) || DEVICE_TYPE_VIRTUAL_WIRED.equals(device.getType())) && channel.getNumber() > 1) {
                            HmChannel previousChannel = device.getChannel(channel.getNumber() - 1);
                            cloneAllDatapointsIntoChannel(channel, previousChannel.getDatapoints());
                        } else {
                            String channelId = String.format("%s:%s:%s", channel.getDevice().getType(), channel.getDevice().getFirmware(), channel.getNumber());
                            Collection<HmDatapoint> cachedDatapoints = datapointsByChannelIdCache.get(channelId);
                            if (cachedDatapoints != null) {
                                // clone all datapoints
                                cloneAllDatapointsIntoChannel(channel, cachedDatapoints);
                            } else {
                                logger.trace("    Loading datapoints into channel {}", channel);
                                addChannelDatapoints(channel, HmParamsetType.MASTER);
                                addChannelDatapoints(channel, HmParamsetType.VALUES);
                                // the data point set might change depending on the selected mode.
                                if (!channel.isReconfigurable()) {
                                    datapointsByChannelIdCache.put(channelId, channel.getDatapoints());
                                }
                            }
                        }
                    }
                }
                prepareDevice(device);
                loadedDevices.add(device.getAddress());
                gatewayAdapter.onDeviceLoaded(device);
            } catch (IOException ex) {
                logger.warn("Can't load device with address '{}' from gateway '{}': {}", device.getAddress(), id, ex.getMessage());
            }
        }
    }
    if (!cancelLoadAllMetadata) {
        devices.keySet().retainAll(loadedDevices);
    }
    initialized = true;
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HashMap(java.util.HashMap) Collection(java.util.Collection) IOException(java.io.IOException) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HashSet(java.util.HashSet) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 19 with HmDatapoint

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

the class ButtonDatapointTest method testDoublePress.

@Test
public void testDoublePress() throws IOException, HomematicClientException, InterruptedException {
    HmDatapoint shortPressDp = createPressDatapoint("PRESS_SHORT", Boolean.TRUE);
    HmDatapoint buttonVirtualDatapoint = getButtonVirtualDatapoint(shortPressDp);
    mockEventReceiver.eventReceived(shortPressDp);
    assertThat(buttonVirtualDatapoint.getValue(), is(CommonTriggerEvents.SHORT_PRESSED));
    Thread.sleep(DISABLE_DATAPOINT_DELAY / 2);
    shortPressDp.setValue(Boolean.TRUE);
    mockEventReceiver.eventReceived(shortPressDp);
    assertThat(buttonVirtualDatapoint.getValue(), is(CommonTriggerEvents.DOUBLE_PRESSED));
    Thread.sleep(DISABLE_DATAPOINT_DELAY * 2);
    shortPressDp.setValue(Boolean.TRUE);
    mockEventReceiver.eventReceived(shortPressDp);
    assertThat(buttonVirtualDatapoint.getValue(), is(CommonTriggerEvents.SHORT_PRESSED));
}
Also used : HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Example 20 with HmDatapoint

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

the class ButtonDatapointTest method testLongPress.

@Test
public void testLongPress() throws IOException, HomematicClientException {
    HmDatapoint longPressDp = createPressDatapoint("PRESS_LONG", Boolean.TRUE);
    HmDatapoint buttonVirtualDatapoint = getButtonVirtualDatapoint(longPressDp);
    mockEventReceiver.eventReceived(longPressDp);
    assertThat(buttonVirtualDatapoint.getValue(), is(CommonTriggerEvents.LONG_PRESSED));
}
Also used : HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

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