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);
}
}
}
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);
}
}
}
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;
}
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));
}
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));
}
Aggregations