Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lcn] Make auto discovery use segment id and module id for ThingID #8120

Merged
merged 5 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.lcn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ To do so, simply start openHAB's discovery.

If not all LCN modules get listed on the first run, click on the refresh button to start another scan.

When adding a module by discovery, the new *Thing*'s UID will be the module's serial number.
When adding a module by discovery, the new *Thing*'s UID will be a combination of segment and module id using the following format: *S<segment_id>M<module_id>*.

### Discover PCK Gateways

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ protected void startScan() {

ThingUID bridgeUid = localBridgeHandler.getThing().getUID();
String serialNumber = matcher.group("sn");
ThingUID thingUid = new ThingUID(LcnBindingConstants.THING_TYPE_MODULE, bridgeUid,
serialNumber);

String thingID = String.format("S%dM%d", addr.getSegmentId(), addr.getModuleId());
toweosp marked this conversation as resolved.
Show resolved Hide resolved

ThingUID thingUid = new ThingUID(LcnBindingConstants.THING_TYPE_MODULE, bridgeUid, thingID);

Map<String, Object> properties = new HashMap<>(3);
properties.put(SEGMENT_ID, addr.getSegmentId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.regex.Matcher;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -68,6 +69,7 @@
public class LcnModuleHandler extends BaseThingHandler {
private final Logger logger = LoggerFactory.getLogger(LcnModuleHandler.class);
private static final Map<String, Converter> CONVERTERS = new HashMap<>();
private static final String SERIAL_NUMBER = "serialNumber";
private @Nullable LcnAddrMod moduleAddress;
private final Map<LcnChannelGroup, @Nullable AbstractLcnModuleSubHandler> subHandlers = new HashMap<>();
private final List<AbstractLcnModuleSubHandler> metadataSubHandlers = new ArrayList<>();
Expand All @@ -93,6 +95,30 @@ public void initialize() {
LcnAddrMod localModuleAddress = moduleAddress = new LcnAddrMod(localConfig.segmentId, localConfig.moduleId);

try {

// Determine serial number of manually added modules
if (getThing().getThingTypeUID().equals(LcnBindingConstants.THING_TYPE_MODULE)
&& getThing().getProperties().get(SERIAL_NUMBER).isEmpty()) {
PckGatewayHandler localBridgeHandler = getPckGatewayHandler();
localBridgeHandler.registerPckListener(data -> {
Matcher matcher;

if ((matcher = LcnModuleMetaFirmwareSubHandler.PATTERN.matcher(data)).matches()) {
if (isMyAddress(matcher.group("segId"), matcher.group("modId"))
&& matcher.pattern() == LcnModuleMetaFirmwareSubHandler.PATTERN) {
String serialNumber = matcher.group("sn");
updateProperty(SERIAL_NUMBER, serialNumber);
}
}
});
synchronized (LcnModuleHandler.this) {
Connection connection = localBridgeHandler.getConnection();
if (connection != null) {
connection.sendSerialNumberRequest(localModuleAddress);
}
}
}

// create sub handlers
ModInfo info = getPckGatewayHandler().getModInfo(localModuleAddress);
for (LcnChannelGroup type : LcnChannelGroup.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<channel-group typeId="keyslocktabled" id="keylocktabled"/>
<channel-group typeId="codes" id="code"/>
</channel-groups>
<properties>
<property name="serialNumber" />
</properties>
<representation-property>serialNumber</representation-property>

<config-description-ref uri="thing-type:lcn:module"/>
</thing-type>
Expand Down