Skip to content

Commit

Permalink
Add Home ID as property and representation property
Browse files Browse the repository at this point in the history
Signed-off-by: Aitor Iturrioz <[email protected]>
  • Loading branch information
bodiroga committed Sep 13, 2020
1 parent 293ac3b commit eeef109
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public String getServiceType() {
public @Nullable DiscoveryResult createResult(ServiceInfo service) {
ThingUID thingUID = getThingUID(service);
if (thingUID != null) {
String homeId = service.getPropertyString("HOME_ID");
String ipAddress = service.getHostAddresses()[0];
int port = service.getPort();
String port_id = String.format("rfc2217://%s:%d", ipAddress, port);
Expand All @@ -64,8 +65,14 @@ public String getServiceType() {
isZWaveController(service) ? ZWAVE_CONTROLLER_DEFAULT_LABEL : ZWAVE_PLUS_CONTROLLER_DEFAULT_LABEL,
ipAddress);

return DiscoveryResultBuilder.create(thingUID).withProperty(CONFIGURATION_PORT, port_id)
.withRepresentationProperty(CONFIGURATION_PORT).withLabel(label).build();
DiscoveryResultBuilder discoveryResult = DiscoveryResultBuilder.create(thingUID)
.withProperty(CONFIGURATION_PORT, port_id).withLabel(label);

if (homeId != null) {
discoveryResult.withProperty("homeId", homeId).withRepresentationProperty("homeId");
}

return discoveryResult.build();
}
return null;

Expand All @@ -77,10 +84,15 @@ public String getServiceType() {
if (isZWaveController(service) || isZWavePlusController(service)) {
String ipAddress = getIPAddress(service);
if (ipAddress != null) {
String homeId = service.getPropertyString("HOME_ID");
String ipAddressLastOctet = getIPAddressLastOctet(ipAddress);
String id = String.format("%s%s%s", service.getPropertyString("VENDOR_ID"),
service.getPropertyString("MODEL_ID"), ipAddressLastOctet);

if (homeId != null) {
id = homeId;
}

return new ThingUID(CONTROLLER_SERIAL, id);
}
}
Expand Down

0 comments on commit eeef109

Please sign in to comment.