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