-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
Modified finder discovery schema to make future finders easier to create #3924
Changes from all commits
300cd4e
f078ada
011644b
8577681
9a08aba
2fab660
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.addon; | ||
|
||
import java.util.Objects; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
/** | ||
* DTO for serialization of a add-on discovery parameter. | ||
* | ||
* @author Mark Herwege - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class AddonParameter { | ||
private @NonNullByDefault({}) String name; | ||
private @NonNullByDefault({}) String value; | ||
|
||
public AddonParameter(String name, String value) { | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, value); | ||
} | ||
|
||
@Override | ||
public boolean equals(@Nullable Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
AddonParameter other = (AddonParameter) obj; | ||
return Objects.equals(name, other.name) && Objects.equals(value, other.value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.addon.internal.xml; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.core.addon.AddonMatchProperty; | ||
import org.openhab.core.addon.AddonParameter; | ||
import org.openhab.core.config.core.xml.util.GenericUnmarshaller; | ||
import org.openhab.core.config.core.xml.util.NodeIterator; | ||
|
||
import com.thoughtworks.xstream.converters.UnmarshallingContext; | ||
import com.thoughtworks.xstream.io.HierarchicalStreamReader; | ||
|
||
/** | ||
* The {@link AddonParameterConverter} is a concrete implementation of the {@code XStream} {@link Converter} | ||
* interface used to convert add-on discovery method parameter information within an XML document into a | ||
* {@link AddonMatchProperty} object. | ||
* | ||
* @author Mark Herwege - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class AddonParameterConverter extends GenericUnmarshaller<AddonParameter> { | ||
|
||
public AddonParameterConverter() { | ||
super(AddonParameter.class); | ||
} | ||
|
||
@Override | ||
public @Nullable Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { | ||
List<?> nodes = (List<?>) context.convertAnother(context, List.class); | ||
NodeIterator nodeIterator = new NodeIterator(nodes); | ||
|
||
String name = requireNonEmpty((String) nodeIterator.nextValue("name", true), "Name is null or empty"); | ||
String value = requireNonEmpty((String) nodeIterator.nextValue("value", true), "Value is null or empty"); | ||
|
||
nodeIterator.assertEndOfType(); | ||
|
||
return new AddonParameter(name, value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,16 +12,9 @@ | |
*/ | ||
package org.openhab.core.addon; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
|
@@ -67,7 +60,7 @@ private AddonInfoProvider createAddonInfoProvider0() { | |
|
||
private AddonInfoProvider createAddonInfoProvider1() { | ||
AddonDiscoveryMethod discoveryMethod = new AddonDiscoveryMethod().setServiceType("mdns") | ||
.setMdnsServiceType("_hue._tcp.local."); | ||
.setParameters(List.of(new AddonParameter("mdnsServiceType", "_hue._tcp.local."))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "mdnsServiceType" should be a constant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left as is, as this would also require a local constant and the exact name of the parameter is not relevant for the test. |
||
AddonInfo addonInfo = AddonInfo.builder("hue", "binding").withName("name-one") | ||
.withDescription("description-one").withCountries("GB,NL").withConnection("local") | ||
.withDiscoveryMethods(List.of(discoveryMethod)).build(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"mdnsServiceType" should be a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left as is, as this would also require a local constant and the exact name of the parameter is not relevant for the test.