Fix discovery label consistency (#14919)

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2023-05-02 08:41:10 +02:00 committed by GitHub
parent feee01d65c
commit 26a52a1540
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 6 deletions

View File

@ -101,7 +101,9 @@ public class HueBindingConstants {
public static final String NORMALIZE_ID_REGEX = "[^a-zA-Z0-9_]"; public static final String NORMALIZE_ID_REGEX = "[^a-zA-Z0-9_]";
// public static final String DISCOVERY_LABEL_PATTERN = "Philips Hue (%s)";
// I18N string references
public static final String TEXT_OFFLINE_COMMUNICATION_ERROR = "@text/offline.communication-error"; public static final String TEXT_OFFLINE_COMMUNICATION_ERROR = "@text/offline.communication-error";
public static final String TEXT_OFFLINE_CONFIGURATION_ERROR_INVALID_SSL_CERIFICATE = "@text/offline.conf-error-invalid-ssl-certificate"; public static final String TEXT_OFFLINE_CONFIGURATION_ERROR_INVALID_SSL_CERIFICATE = "@text/offline.conf-error-invalid-ssl-certificate";

View File

@ -107,7 +107,7 @@ public class HueBridgeMDNSDiscoveryParticipant implements MDNSDiscoveryParticipa
if (uid != null) { if (uid != null) {
String host = service.getHostAddresses()[0]; String host = service.getHostAddresses()[0];
String id = service.getPropertyString(MDNS_PROPERTY_BRIDGE_ID); String id = service.getPropertyString(MDNS_PROPERTY_BRIDGE_ID);
String friendlyName = String.format("%s (%s)", service.getName(), host); String friendlyName = String.format(DISCOVERY_LABEL_PATTERN, host);
return DiscoveryResultBuilder.create(uid) // return DiscoveryResultBuilder.create(uid) //
.withProperties(Map.of( // .withProperties(Map.of( //
HOST, host, // HOST, host, //

View File

@ -49,10 +49,10 @@ import com.google.gson.reflect.TypeToken;
@NonNullByDefault @NonNullByDefault
public class HueBridgeNupnpDiscovery extends AbstractDiscoveryService { public class HueBridgeNupnpDiscovery extends AbstractDiscoveryService {
private static final String MODEL_NAME_PHILIPS_HUE = "\"name\":\"Philips hue\"";
protected static final String BRIDGE_INDICATOR = "fffe"; protected static final String BRIDGE_INDICATOR = "fffe";
private static final String MODEL_NAME_PHILIPS_HUE = "\"name\":\"Philips hue\"";
private static final String DISCOVERY_URL = "https://discovery.meethue.com/"; private static final String DISCOVERY_URL = "https://discovery.meethue.com/";
protected static final String LABEL_PATTERN = "Philips Hue (%s)";
private static final String CONFIG_URL_PATTERN = "http://%s/api/0/config"; private static final String CONFIG_URL_PATTERN = "http://%s/api/0/config";
private static final int REQUEST_TIMEOUT = 5000; private static final int REQUEST_TIMEOUT = 5000;
private static final int DISCOVERY_TIMEOUT = 10; private static final int DISCOVERY_TIMEOUT = 10;
@ -81,7 +81,7 @@ public class HueBridgeNupnpDiscovery extends AbstractDiscoveryService {
.withProperties(Map.of( // .withProperties(Map.of( //
HOST, host, // HOST, host, //
Thing.PROPERTY_SERIAL_NUMBER, serialNumber)) // Thing.PROPERTY_SERIAL_NUMBER, serialNumber)) //
.withLabel(String.format(LABEL_PATTERN, host)) // .withLabel(String.format(DISCOVERY_LABEL_PATTERN, host)) //
.withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER) // .withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER) //
.build(); .build();
thingDiscovered(result); thingDiscovered(result);

View File

@ -27,6 +27,7 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.openhab.binding.hue.internal.HueBindingConstants;
import org.openhab.core.config.discovery.DiscoveryListener; import org.openhab.core.config.discovery.DiscoveryListener;
import org.openhab.core.config.discovery.DiscoveryResult; import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryService; import org.openhab.core.config.discovery.DiscoveryService;
@ -61,7 +62,7 @@ public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
private void checkDiscoveryResult(DiscoveryResult result, String expIp, String expSn) { private void checkDiscoveryResult(DiscoveryResult result, String expIp, String expSn) {
assertThat(result.getBridgeUID(), nullValue()); assertThat(result.getBridgeUID(), nullValue());
assertThat(result.getLabel(), is(String.format(HueBridgeNupnpDiscovery.LABEL_PATTERN, expIp))); assertThat(result.getLabel(), is(String.format(HueBindingConstants.DISCOVERY_LABEL_PATTERN, expIp)));
assertThat(result.getProperties().get("ipAddress"), is(expIp)); assertThat(result.getProperties().get("ipAddress"), is(expIp));
assertThat(result.getProperties().get("serialNumber"), is(expSn)); assertThat(result.getProperties().get("serialNumber"), is(expSn));
} }