use of org.eclipse.smarthome.binding.homematic.internal.model.HmDevice 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.HmDevice 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.HmDevice in project smarthome by eclipse.
the class AbstractHomematicGateway method getDeviceDescriptions.
/**
* Loads all device descriptions from the gateway.
*/
private List<HmDevice> getDeviceDescriptions() throws IOException {
List<HmDevice> deviceDescriptions = new ArrayList<HmDevice>();
for (HmInterface hmInterface : availableInterfaces.keySet()) {
deviceDescriptions.addAll(getRpcClient(hmInterface).listDevices(hmInterface));
}
if (!cancelLoadAllMetadata) {
deviceDescriptions.add(createGatewayDevice());
loadDeviceNames(deviceDescriptions);
}
return deviceDescriptions;
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDevice in project smarthome by eclipse.
the class AbstractHomematicGateway method deleteDevices.
@Override
public void deleteDevices(List<String> addresses) {
if (initialized) {
for (String address : addresses) {
logger.debug("Device '{}' removed from gateway with id '{}'", address, id);
HmDevice device = devices.remove(address);
if (device != null) {
gatewayAdapter.onDeviceDeleted(device);
}
}
}
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDevice in project smarthome by eclipse.
the class BaseConverterTest method setup.
@Before
public void setup() {
HmChannel stubChannel = new HmChannel("stubChannel", 0);
stubChannel.setDevice(new HmDevice("LEQ123456", HmInterface.RF, "HM-STUB-DEVICE", "", "", ""));
floatDp.setChannel(stubChannel);
}
Aggregations