Skip to content

Instantly share code, notes, and snippets.

@maniac103
Created January 12, 2018 10:10
Show Gist options
  • Save maniac103/f3718a950167b32a4a280af86b21d20b to your computer and use it in GitHub Desktop.
Save maniac103/f3718a950167b32a4a280af86b21d20b to your computer and use it in GitHub Desktop.
diff --git a/addons/binding/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/handler/HomematicBridgeHandler.java b/addons/binding/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/handler/HomematicBridgeHandler.java
index f458d201a..0c7a4fad5 100644
--- a/addons/binding/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/handler/HomematicBridgeHandler.java
+++ b/addons/binding/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/handler/HomematicBridgeHandler.java
@@ -279,6 +279,7 @@ public class HomematicBridgeHandler extends BaseBridgeHandler implements Homemat
@Override
public void reloadDeviceValues(HmDevice device) {
updateThing(device);
+ // XXX: also needed if channel function dp is present
if (device.isGatewayExtras()) {
typeGenerator.generate(device);
}
diff --git a/addons/binding/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/AbstractHomematicGateway.java b/addons/binding/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/AbstractHomematicGateway.java
index 39920390b..6a20ca742 100644
--- a/addons/binding/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/AbstractHomematicGateway.java
+++ b/addons/binding/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/AbstractHomematicGateway.java
@@ -378,6 +378,10 @@ public abstract class AbstractHomematicGateway implements RpcEventListener, Home
if (channel.getDatapoint(HmParamsetType.MASTER,
DATAPOINT_NAME_CHANNEL_FUNCTION) == null) {
datapointsByChannelIdCache.put(channelId, channel.getDatapoints().values());
+ } else {
+ // We'll need the value of channel function immediately (for UID generation),
+ // so fetch values now
+ setChannelDatapointValues(channel, HmParamsetType.MASTER);
}
}
}
diff --git a/addons/binding/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/UidUtils.java b/addons/binding/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/UidUtils.java
index 4e2ddf9f3..6950b5f02 100644
--- a/addons/binding/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/UidUtils.java
+++ b/addons/binding/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/UidUtils.java
@@ -18,6 +18,7 @@ import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelTypeUID;
+import org.openhab.binding.homematic.internal.misc.HomematicConstants;
import org.openhab.binding.homematic.internal.model.HmChannel;
import org.openhab.binding.homematic.internal.model.HmDatapoint;
import org.openhab.binding.homematic.internal.model.HmDatapointInfo;
@@ -37,11 +38,28 @@ public class UidUtils {
* device has more datapoints.
*/
public static ThingTypeUID generateThingTypeUID(HmDevice device) {
- if (!device.isGatewayExtras() && device.getGatewayId().equals(HmGatewayInfo.ID_HOMEGEAR)) {
- return new ThingTypeUID(BINDING_ID, String.format("HG-%s", device.getType()));
- } else {
- return new ThingTypeUID(BINDING_ID, device.getType());
+ String prefix = "";
+ StringBuilder suffixBuilder = null;
+
+ if (device.getGatewayId().equals(HmGatewayInfo.ID_HOMEGEAR) && !device.isGatewayExtras()) {
+ prefix = "HG-";
+ }
+
+ for (HmChannel channel : device.getChannels()) {
+ HmDatapoint dp = channel.getDatapoint(HmParamsetType.MASTER,
+ HomematicConstants.DATAPOINT_NAME_CHANNEL_FUNCTION);
+ Integer value = dp != null ? (Integer) dp.getValue() : null;
+ if (value != null) {
+ if (suffixBuilder == null) {
+ suffixBuilder = new StringBuilder("-funcs-");
+ }
+ suffixBuilder.append(value);
+ }
}
+
+ String suffix = suffixBuilder != null ? suffixBuilder.toString() : "";
+
+ return new ThingTypeUID(BINDING_ID, String.format("%s%s%s", prefix, device.getType(), suffix));
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment