Skip to content

Commit

Permalink
gen3 gateway uses mDNS 'sn' property
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Fiddian-Green <[email protected]>
  • Loading branch information
andrewfg committed Feb 10, 2025
1 parent c25269d commit 868d4f4
Showing 1 changed file with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.hdpowerview.internal.config.HDPowerViewHubConfiguration;
import org.openhab.binding.hdpowerview.internal.exceptions.HubException;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.config.discovery.mdns.MDNSDiscoveryParticipant;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -46,13 +43,6 @@ public class GatewayDiscoveryParticipant implements MDNSDiscoveryParticipant {

private final Logger logger = LoggerFactory.getLogger(GatewayDiscoveryParticipant.class);

private final HDPowerviewPropertyGetter propertyGetter;

@Activate
public GatewayDiscoveryParticipant(@Reference HDPowerviewPropertyGetter propertyGetter) {
this.propertyGetter = propertyGetter;
}

@Override
public @Nullable DiscoveryResult createResult(ServiceInfo service) {
ThingUID thingUID = getThingUID(service);
Expand Down Expand Up @@ -86,11 +76,11 @@ public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
public @Nullable ThingUID getThingUID(ServiceInfo service) {
String host = getIpV4Address(service);
if (host != null) {
try {
String serial = propertyGetter.getSerialNumberApiV3(host);
String serial = service.getPropertyString("sn");
if (serial != null) {
return new ThingUID(THING_TYPE_GATEWAY, serial);
} catch (HubException e) {
logger.debug("Error discovering gateway", e);
} else {
logger.debug("Error discovering gateway 'missing serial number'");
}
}
return null;
Expand Down

0 comments on commit 868d4f4

Please sign in to comment.