If set to false, the inbox may contain results although identical things already exist.
+ ]]>
+
+ true
+
+
+
+
\ No newline at end of file
diff --git a/bundles/config/org.eclipse.smarthome.config.discovery/META-INF/MANIFEST.MF b/bundles/config/org.eclipse.smarthome.config.discovery/META-INF/MANIFEST.MF
index 5570fc87133..44e6ac46eb9 100644
--- a/bundles/config/org.eclipse.smarthome.config.discovery/META-INF/MANIFEST.MF
+++ b/bundles/config/org.eclipse.smarthome.config.discovery/META-INF/MANIFEST.MF
@@ -7,6 +7,7 @@ Bundle-Vendor: Eclipse.org/SmartHome
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.google.common.base,
com.google.common.collect,
+ org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.config.core,
org.eclipse.smarthome.config.discovery,
org.eclipse.smarthome.config.discovery.dto,
@@ -18,6 +19,7 @@ Import-Package: com.google.common.base,
org.eclipse.smarthome.core.storage,
org.eclipse.smarthome.core.thing,
org.eclipse.smarthome.core.thing.binding,
+ org.eclipse.smarthome.core.thing.events,
org.eclipse.smarthome.core.thing.type,
org.eclipse.smarthome.io.console,
org.eclipse.smarthome.io.console.extensions,
@@ -29,6 +31,7 @@ Import-Package: com.google.common.base,
org.osgi.framework,
org.osgi.service.cm,
org.osgi.service.component,
+ org.osgi.service.component.annotations;resolution:=optional,
org.slf4j
Service-Component: OSGI-INF/*.xml
Export-Package: org.eclipse.smarthome.config.discovery,
diff --git a/bundles/config/org.eclipse.smarthome.config.discovery/OSGI-INF/.gitignore b/bundles/config/org.eclipse.smarthome.config.discovery/OSGI-INF/.gitignore
new file mode 100644
index 00000000000..3dc79f73c09
--- /dev/null
+++ b/bundles/config/org.eclipse.smarthome.config.discovery/OSGI-INF/.gitignore
@@ -0,0 +1 @@
+/org.eclipse.smarthome.config.discovery.internal.AutomaticInboxProcessor.xml
diff --git a/bundles/config/org.eclipse.smarthome.config.discovery/build.properties b/bundles/config/org.eclipse.smarthome.config.discovery/build.properties
index 9beae6ace39..050539ec5e8 100644
--- a/bundles/config/org.eclipse.smarthome.config.discovery/build.properties
+++ b/bundles/config/org.eclipse.smarthome.config.discovery/build.properties
@@ -3,4 +3,5 @@ output.. = target/classes/
bin.includes = META-INF/,\
.,\
OSGI-INF/,\
- about.html
+ about.html,\
+ ESH-INF/
diff --git a/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/AbstractDiscoveryService.java b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/AbstractDiscoveryService.java
index 68a7308fc57..48a159488fc 100644
--- a/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/AbstractDiscoveryService.java
+++ b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/AbstractDiscoveryService.java
@@ -43,7 +43,8 @@ public abstract class AbstractDiscoveryService implements DiscoveryService {
private final Logger logger = LoggerFactory.getLogger(AbstractDiscoveryService.class);
- static protected final ScheduledExecutorService scheduler = ThreadPoolManager.getScheduledPool(DISCOVERY_THREADPOOL_NAME);
+ static protected final ScheduledExecutorService scheduler = ThreadPoolManager
+ .getScheduledPool(DISCOVERY_THREADPOOL_NAME);
private Set discoveryListeners = new CopyOnWriteArraySet<>();
protected ScanListener scanListener = null;
@@ -252,8 +253,8 @@ protected void thingDiscovered(DiscoveryResult discoveryResult) {
try {
discoveryListener.thingDiscovered(this, discoveryResult);
} catch (Exception e) {
- logger.error("An error occurred while calling the discovery listener "
- + discoveryListener.getClass().getName() + ".", e);
+ logger.error("An error occurred while calling the discovery listener {}.",
+ discoveryListener.getClass().getName(), e);
}
}
synchronized (cachedResults) {
@@ -272,8 +273,8 @@ protected void thingRemoved(ThingUID thingUID) {
try {
discoveryListener.thingRemoved(this, thingUID);
} catch (Exception e) {
- logger.error("An error occurred while calling the discovery listener "
- + discoveryListener.getClass().getName() + ".", e);
+ logger.error("An error occurred while calling the discovery listener {}.",
+ discoveryListener.getClass().getName(), e);
}
}
synchronized (cachedResults) {
@@ -316,8 +317,8 @@ protected void removeOlderResults(long timestamp, Collection thing
try {
removedThings = discoveryListener.removeOlderResults(this, timestamp, thingTypeUIDs);
} catch (Exception e) {
- logger.error("An error occurred while calling the discovery listener "
- + discoveryListener.getClass().getName() + ".", e);
+ logger.error("An error occurred while calling the discovery listener {}.",
+ discoveryListener.getClass().getName(), e);
}
}
if (removedThings != null) {
diff --git a/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/DiscoveryResult.java b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/DiscoveryResult.java
index f7921fda85f..b200d25594a 100644
--- a/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/DiscoveryResult.java
+++ b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/DiscoveryResult.java
@@ -80,7 +80,7 @@ public interface DiscoveryResult {
* discovered. Its actual value can be retrieved from the {@link DiscoveryResult#getProperties()} map. Such unique
* identifiers are typically the ipAddress, the macAddress or the
* serialNumber of the discovered thing.
- *
+ *
* @return the representation property of this result object (could be null)
*/
public String getRepresentationProperty();
@@ -112,14 +112,14 @@ public interface DiscoveryResult {
/**
* Get the timestamp of this {@link DiscoveryResult}.
- *
+ *
* @return timestamp as long
*/
public long getTimestamp();
/**
* Get the time to live in seconds for this entry.
- *
+ *
* @return time to live in seconds
*/
public long getTimeToLive();
diff --git a/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/dto/DiscoveryResultDTOMapper.java b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/dto/DiscoveryResultDTOMapper.java
index 3d38928d420..e65d2e7bea5 100644
--- a/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/dto/DiscoveryResultDTOMapper.java
+++ b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/dto/DiscoveryResultDTOMapper.java
@@ -8,11 +8,15 @@
package org.eclipse.smarthome.config.discovery.dto;
import org.eclipse.smarthome.config.discovery.DiscoveryResult;
+import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder;
+import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.ThingUID;
/**
* The {@link DiscoveryResultDTOMapper} is an utility class to map discovery results into discovery result transfer
* objects.
+ *
+ * @author Stefan Bussweiler - Initial contribution
*/
public class DiscoveryResultDTOMapper {
@@ -31,4 +35,22 @@ public static DiscoveryResultDTO map(DiscoveryResult discoveryResult) {
discoveryResult.getLabel(), discoveryResult.getFlag(), discoveryResult.getProperties(),
discoveryResult.getRepresentationProperty());
}
+
+ /**
+ * Maps discovery result data transfer object into discovery result.
+ *
+ * @param discoveryResultDTO the discovery result data transfer object
+ * @return the discovery result
+ */
+ public static DiscoveryResult map(DiscoveryResultDTO discoveryResultDTO) {
+ ThingUID thingUID = new ThingUID(discoveryResultDTO.thingUID);
+ ThingTypeUID thingTypeUID = discoveryResultDTO.thingTypeUID != null
+ ? new ThingTypeUID(discoveryResultDTO.thingTypeUID) : null;
+ ThingUID bridgeUID = discoveryResultDTO.bridgeUID != null ? new ThingUID(discoveryResultDTO.bridgeUID) : null;
+
+ return DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID).withBridge(bridgeUID)
+ .withLabel(discoveryResultDTO.label)
+ .withRepresentationProperty(discoveryResultDTO.representationProperty)
+ .withProperties(discoveryResultDTO.properties).build();
+ }
}
diff --git a/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/inbox/Inbox.java b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/inbox/Inbox.java
index e173a329cbf..1b6a606acfe 100644
--- a/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/inbox/Inbox.java
+++ b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/inbox/Inbox.java
@@ -8,6 +8,7 @@
package org.eclipse.smarthome.config.discovery.inbox;
import java.util.List;
+import java.util.stream.Stream;
import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.DiscoveryResultFlag;
@@ -75,7 +76,10 @@ public interface Inbox {
*
* @return all discovery results in this inbox which fit to the specified filter criteria
* (not null, could be empty)
+ *
+ * @deprecated use {@link InboxPredicates} to filter on streams of {@link DiscoveryResult}s
*/
+ @Deprecated
List get(InboxFilterCriteria criteria);
/**
@@ -85,6 +89,13 @@ public interface Inbox {
*/
List getAll();
+ /**
+ * Returns a stream of all {@link DiscoveryResult}s in this {@link Inbox}.
+ *
+ * @return stream of all discovery results in this inbox
+ */
+ Stream stream();
+
/**
* Sets the flag for a given thingUID result.
* The flag signals e.g. if the result is {@link DiscoveryResultFlag#NEW} or has been marked as
@@ -121,14 +132,14 @@ public interface Inbox {
* @param listener the listener to be removed (could be null)
*/
void removeInboxListener(InboxListener listener);
-
+
/**
- * Creates new {@link Thing} and adds it to the {@link ThingRegistry}.
- *
- * @param thingUID the UID of the Thing
- * @param label the label of the Thing
+ * Creates new {@link Thing} and adds it to the {@link ThingRegistry}.
+ *
+ * @param thingUID the UID of the Thing
+ * @param label the label of the Thing
* @return the approved Thing
*/
- Thing approve(ThingUID thingUID, String label);
+ Thing approve(ThingUID thingUID, String label);
}
diff --git a/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/inbox/InboxFilterCriteria.java b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/inbox/InboxFilterCriteria.java
index 3a22e6f781e..6d8cf34b338 100644
--- a/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/inbox/InboxFilterCriteria.java
+++ b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/inbox/InboxFilterCriteria.java
@@ -7,6 +7,7 @@
*/
package org.eclipse.smarthome.config.discovery.inbox;
+import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.DiscoveryResultFlag;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.ThingUID;
@@ -20,7 +21,10 @@
* @author Michael Grammling - Initial Contribution
*
* @see Inbox
+ *
+ * @deprecated use {@link InboxPredicates} to filter on streams of {@link DiscoveryResult}s
*/
+@Deprecated
public final class InboxFilterCriteria {
private final String bindingId;
diff --git a/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/inbox/InboxPredicates.java b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/inbox/InboxPredicates.java
new file mode 100644
index 00000000000..0867f9e0b0d
--- /dev/null
+++ b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/inbox/InboxPredicates.java
@@ -0,0 +1,52 @@
+/**
+ * Copyright (c) 2014-2017 by the respective copyright holders.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.eclipse.smarthome.config.discovery.inbox;
+
+import java.util.function.Predicate;
+
+import org.eclipse.smarthome.config.discovery.DiscoveryResult;
+import org.eclipse.smarthome.config.discovery.DiscoveryResultFlag;
+import org.eclipse.smarthome.core.thing.ThingTypeUID;
+import org.eclipse.smarthome.core.thing.ThingUID;
+
+/**
+ * Implements static factory methods for {@link Predicate}s to filter in streams of {@link DiscoveryResult}s.
+ *
+ * @author Andre Fuechsel - Initial Contribution
+ */
+public class InboxPredicates {
+
+ public static Predicate forBinding(String bindingId) {
+ return r -> bindingId != null && bindingId.equals(r.getBindingId());
+ }
+
+ public static Predicate forThingTypeUID(ThingTypeUID uid) {
+ return r -> uid != null && uid.equals(r.getThingTypeUID());
+ }
+
+ public static Predicate forThingUID(ThingUID thingUID) {
+ return r -> thingUID != null && thingUID.equals(r.getThingUID());
+ }
+
+ public static Predicate withFlag(DiscoveryResultFlag flag) {
+ return r -> flag == r.getFlag();
+ }
+
+ public static Predicate withProperty(String propertyName, String propertyValue) {
+ return r -> r.getProperties().containsKey(propertyName)
+ && r.getProperties().get(propertyName).equals(propertyValue);
+ }
+
+ public static Predicate withRepresentationProperty(String propertyName) {
+ return r -> propertyName != null && propertyName.equals(r.getRepresentationProperty());
+ }
+
+ public static Predicate withRepresentationPropertyValue(String propertyValue) {
+ return r -> propertyValue != null && propertyValue.equals(r.getProperties().get(r.getRepresentationProperty()));
+ }
+}
diff --git a/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/internal/AutomaticInboxProcessor.java b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/internal/AutomaticInboxProcessor.java
new file mode 100644
index 00000000000..1eb24225abd
--- /dev/null
+++ b/bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/internal/AutomaticInboxProcessor.java
@@ -0,0 +1,204 @@
+/**
+ * Copyright (c) 2014-2017 by the respective copyright holders.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.eclipse.smarthome.config.discovery.internal;
+
+import static org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.*;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import org.eclipse.smarthome.config.core.Configuration;
+import org.eclipse.smarthome.config.discovery.DiscoveryResult;
+import org.eclipse.smarthome.config.discovery.DiscoveryResultFlag;
+import org.eclipse.smarthome.config.discovery.inbox.Inbox;
+import org.eclipse.smarthome.config.discovery.inbox.InboxListener;
+import org.eclipse.smarthome.core.events.AbstractTypedEventSubscriber;
+import org.eclipse.smarthome.core.events.EventSubscriber;
+import org.eclipse.smarthome.core.thing.Thing;
+import org.eclipse.smarthome.core.thing.ThingRegistry;
+import org.eclipse.smarthome.core.thing.ThingStatus;
+import org.eclipse.smarthome.core.thing.events.ThingStatusInfoChangedEvent;
+import org.eclipse.smarthome.core.thing.type.ThingType;
+import org.eclipse.smarthome.core.thing.type.ThingTypeRegistry;
+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;
+
+/**
+ * This class implements a service to automatically ignore {@link Inbox} entries of newly created things.
+ *
+ * The {@link AutomaticInboxProcessor} service implements a {@link EventSubscriber}, that is triggered
+ * for each thing when coming ONLINE. {@link Inbox}Â entries with the same representation value like the
+ * newly created thing will be automatically set to {@link DiscoveryResultFlag#IGNORED}.
+ *
+ *
+ * If a thing is being removed, possibly existing {@link Inbox}Â entries with the same representation value
+ * are removed from the {@link Inbox} so they could be discovered again afterwards.
+ *
+ *
+ * This service can be enabled or disabled by setting the {@code autoIgnore} property to either
+ * {@code true}Â or {@code false} via ConfigAdmin.
+ *
The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at http://www.eclipse.org/legal/epl-v10.html.
+For purposes of the EPL, "Program" will mean the Content.
+
+
If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at http://www.eclipse.org.
+
+
+
\ No newline at end of file
diff --git a/bundles/config/org.eclipse.smarthome.config.dispatch.test/build.properties b/bundles/config/org.eclipse.smarthome.config.dispatch.test/build.properties
index 3f16129255e..71f608e525e 100644
--- a/bundles/config/org.eclipse.smarthome.config.dispatch.test/build.properties
+++ b/bundles/config/org.eclipse.smarthome.config.dispatch.test/build.properties
@@ -1,5 +1,6 @@
bin.includes = .,\
META-INF/,\
- OSGI-INF/
+ OSGI-INF/,\
+ about.html
source.. = src/test/groovy/
output.. = target/classes/
diff --git a/bundles/config/org.eclipse.smarthome.config.dispatch/about.html b/bundles/config/org.eclipse.smarthome.config.dispatch/about.html
new file mode 100644
index 00000000000..2ba76b399bd
--- /dev/null
+++ b/bundles/config/org.eclipse.smarthome.config.dispatch/about.html
@@ -0,0 +1,28 @@
+
+
+
+
+About
+
+
+
About This Content
+
+
July 24, 2017
+
License
+
+
The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at http://www.eclipse.org/legal/epl-v10.html.
+For purposes of the EPL, "Program" will mean the Content.
+
+
If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at http://www.eclipse.org.
The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at http://www.eclipse.org/legal/epl-v10.html.
+For purposes of the EPL, "Program" will mean the Content.
+
+
If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at http://www.eclipse.org.
+
+
+
\ No newline at end of file
diff --git a/bundles/core/org.eclipse.smarthome.core.audio.test/build.properties b/bundles/core/org.eclipse.smarthome.core.audio.test/build.properties
index 9ebf2ba45c2..1f6c66a9b22 100644
--- a/bundles/core/org.eclipse.smarthome.core.audio.test/build.properties
+++ b/bundles/core/org.eclipse.smarthome.core.audio.test/build.properties
@@ -1,4 +1,5 @@
source.. = src/test/groovy/
output.. = target/classes/
bin.includes = META-INF/,\
- .
+ .,\
+ about.html
diff --git a/bundles/core/org.eclipse.smarthome.core.audio/META-INF/MANIFEST.MF b/bundles/core/org.eclipse.smarthome.core.audio/META-INF/MANIFEST.MF
index 07f552ee5cc..6fe4da3f8e1 100644
--- a/bundles/core/org.eclipse.smarthome.core.audio/META-INF/MANIFEST.MF
+++ b/bundles/core/org.eclipse.smarthome.core.audio/META-INF/MANIFEST.MF
@@ -12,6 +12,7 @@ Import-Package: javax.servlet,
org.apache.commons.lang,
org.eclipse.smarthome.config.core,
org.eclipse.smarthome.core.audio,
+ org.eclipse.smarthome.core.audio.utils,
org.eclipse.smarthome.core.common.registry,
org.eclipse.smarthome.core.events,
org.eclipse.smarthome.core.i18n,
@@ -25,6 +26,7 @@ Import-Package: javax.servlet,
org.osgi.framework,
org.osgi.service.http,
org.slf4j
-Export-Package: org.eclipse.smarthome.core.audio
+Export-Package: org.eclipse.smarthome.core.audio,
+ org.eclipse.smarthome.core.audio.utils
Service-Component: OSGI-INF/*.xml
Bundle-ActivationPolicy: lazy
diff --git a/bundles/core/org.eclipse.smarthome.core.audio/src/main/java/org/eclipse/smarthome/core/audio/FileAudioStream.java b/bundles/core/org.eclipse.smarthome.core.audio/src/main/java/org/eclipse/smarthome/core/audio/FileAudioStream.java
index d3d5693b2f5..a0a5f9e8277 100644
--- a/bundles/core/org.eclipse.smarthome.core.audio/src/main/java/org/eclipse/smarthome/core/audio/FileAudioStream.java
+++ b/bundles/core/org.eclipse.smarthome.core.audio/src/main/java/org/eclipse/smarthome/core/audio/FileAudioStream.java
@@ -14,19 +14,22 @@
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
+import org.eclipse.smarthome.core.audio.utils.AudioStreamUtils;
/**
* This is an AudioStream from an audio file
*
* @author Karel Goderis - Initial contribution and API
* @author Kai Kreuzer - Refactored to take a file as input
+ * @author Christoph Weitkamp - Refactored use of filename extension
+ *
*/
public class FileAudioStream extends FixedLengthAudioStream {
- public static String WAV_EXTENSION = ".wav";
- public static String MP3_EXTENSION = ".mp3";
- public static String OGG_EXTENSION = ".ogg";
- public static String AAC_EXTENSION = ".aac";
+ public static final String WAV_EXTENSION = "wav";
+ public static final String MP3_EXTENSION = "mp3";
+ public static final String OGG_EXTENSION = "ogg";
+ public static final String AAC_EXTENSION = "aac";
private File file;
private AudioFormat audioFormat;
@@ -45,16 +48,20 @@ public FileAudioStream(File file, AudioFormat format) throws AudioException {
}
private static AudioFormat getAudioFormat(File file) throws AudioException {
- if (file.getName().toLowerCase().endsWith(WAV_EXTENSION)) {
- return new AudioFormat(AudioFormat.CONTAINER_WAVE, AudioFormat.CODEC_PCM_SIGNED, false, 16, 705600, 44100L);
- } else if (file.getName().toLowerCase().endsWith(MP3_EXTENSION)) {
- return AudioFormat.MP3;
- } else if (file.getName().toLowerCase().endsWith(OGG_EXTENSION)) {
- return AudioFormat.OGG;
- } else if (file.getName().toLowerCase().endsWith(AAC_EXTENSION)) {
- return AudioFormat.AAC;
- } else {
- throw new AudioException("Unsupported file extension!");
+ final String filename = file.getName().toLowerCase();
+ final String extension = AudioStreamUtils.getExtension(filename);
+ switch (extension) {
+ case WAV_EXTENSION:
+ return new AudioFormat(AudioFormat.CONTAINER_WAVE, AudioFormat.CODEC_PCM_SIGNED, false, 16, 705600,
+ 44100L);
+ case MP3_EXTENSION:
+ return AudioFormat.MP3;
+ case OGG_EXTENSION:
+ return AudioFormat.OGG;
+ case AAC_EXTENSION:
+ return AudioFormat.AAC;
+ default:
+ throw new AudioException("Unsupported file extension!");
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.audio/src/main/java/org/eclipse/smarthome/core/audio/URLAudioStream.java b/bundles/core/org.eclipse.smarthome.core.audio/src/main/java/org/eclipse/smarthome/core/audio/URLAudioStream.java
index abca372358e..148ec4493ba 100644
--- a/bundles/core/org.eclipse.smarthome.core.audio/src/main/java/org/eclipse/smarthome/core/audio/URLAudioStream.java
+++ b/bundles/core/org.eclipse.smarthome.core.audio/src/main/java/org/eclipse/smarthome/core/audio/URLAudioStream.java
@@ -18,6 +18,7 @@
import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils;
+import org.eclipse.smarthome.core.audio.utils.AudioStreamUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,15 +28,19 @@
*
* @author Karel Goderis - Initial contribution and API
* @author Kai Kreuzer - Refactored to not require a source
+ * @author Christoph Weitkamp - Refactored use of filename extension
*
*/
-public class URLAudioStream extends org.eclipse.smarthome.core.audio.AudioStream {
+public class URLAudioStream extends AudioStream {
- private static final Pattern plsStreamPattern = Pattern.compile("^File[0-9]=(.+)$");
+ private static final Pattern PLS_STREAM_PATTERN = Pattern.compile("^File[0-9]=(.+)$");
+
+ public static final String M3U_EXTENSION = "m3u";
+ public static final String PLS_EXTENSION = "pls";
private final Logger logger = LoggerFactory.getLogger(URLAudioStream.class);
- private AudioFormat audioFormat;
+ private final AudioFormat audioFormat;
private final InputStream inputStream;
private String url;
@@ -51,32 +56,38 @@ public URLAudioStream(String url) throws AudioException {
}
private InputStream createInputStream() throws AudioException {
+ final String filename = url.toLowerCase();
+ final String extension = AudioStreamUtils.getExtension(filename);
try {
- if (url.toLowerCase().endsWith(".m3u")) {
- InputStream is = new URL(url).openStream();
- String urls = IOUtils.toString(is);
- for (String line : urls.split("\n")) {
- if (!line.isEmpty() && !line.startsWith("#")) {
- url = line;
- break;
+ switch (extension) {
+ case M3U_EXTENSION:
+ try (final InputStream isM3U = new URL(url).openStream()) {
+ for (final String line : IOUtils.readLines(isM3U)) {
+ if (!line.isEmpty() && !line.startsWith("#")) {
+ url = line;
+ break;
+ }
+ }
}
- }
- } else if (url.toLowerCase().endsWith(".pls")) {
- InputStream is = new URL(url).openStream();
- String urls = IOUtils.toString(is);
- for (String line : urls.split("\n")) {
- if (!line.isEmpty() && line.startsWith("File")) {
- Matcher matcher = plsStreamPattern.matcher(line);
- if (matcher.find()) {
- url = matcher.group(1);
- break;
+ break;
+ case PLS_EXTENSION:
+ try (final InputStream isPLS = new URL(url).openStream()) {
+ for (final String line : IOUtils.readLines(isPLS)) {
+ if (!line.isEmpty() && line.startsWith("File")) {
+ final Matcher matcher = PLS_STREAM_PATTERN.matcher(line);
+ if (matcher.find()) {
+ url = matcher.group(1);
+ break;
+ }
+ }
}
}
- }
+ break;
+ default:
+ break;
}
URL streamUrl = new URL(url);
URLConnection connection = streamUrl.openConnection();
- InputStream is = null;
if (connection.getContentType().equals("unknown/unknown")) {
// Java does not parse non-standard headers used by SHOUTCast
int port = streamUrl.getPort() > 0 ? streamUrl.getPort() : 80;
@@ -88,19 +99,18 @@ private InputStream createInputStream() throws AudioException {
String req = "GET / HTTP/1.0\r\nuser-agent: " + user_agent
+ "\r\nIcy-MetaData: 1\r\nConnection: keep-alive\r\n\r\n";
os.write(req.getBytes());
- is = shoutCastSocket.getInputStream();
+ return shoutCastSocket.getInputStream();
} else {
// getInputStream() method is more error-proof than openStream(),
// because openStream() does openConnection().getInputStream(),
// which opens a new connection and does not reuse the old one.
- is = connection.getInputStream();
+ return connection.getInputStream();
}
- return is;
} catch (MalformedURLException e) {
- logger.error("URL '{}' is not a valid url : '{}'", url, e.getMessage());
+ logger.error("URL '{}' is not a valid url: {}", url, e.getMessage(), e);
throw new AudioException("URL not valid");
} catch (IOException e) {
- logger.error("Cannot set up stream '{}': {}", url, e);
+ logger.error("Cannot set up stream '{}': {}", url, e.getMessage(), e);
throw new AudioException("IO Error");
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.audio/src/main/java/org/eclipse/smarthome/core/audio/utils/AudioStreamUtils.java b/bundles/core/org.eclipse.smarthome.core.audio/src/main/java/org/eclipse/smarthome/core/audio/utils/AudioStreamUtils.java
new file mode 100644
index 00000000000..f3fb19bab81
--- /dev/null
+++ b/bundles/core/org.eclipse.smarthome.core.audio/src/main/java/org/eclipse/smarthome/core/audio/utils/AudioStreamUtils.java
@@ -0,0 +1,75 @@
+/**
+ * Copyright (c) 2014-2017 by the respective copyright holders.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.eclipse.smarthome.core.audio.utils;
+
+/**
+ * Some general filename and extension utilities.
+ *
+ * @author Christoph Weitkamp - Initial contribution and API
+ *
+ */
+public class AudioStreamUtils {
+
+ public static final String EXTENSION_SEPARATOR = ".";
+
+ /**
+ * Gets the base name of a filename.
+ *
+ * @param filename the filename to query
+ * @return the base name of the file or an empty string if none exists or {@code null} if the filename is
+ * {@code null}
+ */
+ public static String getBaseName(String filename) {
+ if (filename == null) {
+ return null;
+ }
+ final int index = filename.lastIndexOf(EXTENSION_SEPARATOR);
+ if (index == -1) {
+ return filename;
+ } else {
+ return filename.substring(0, index);
+ }
+ }
+
+ /**
+ * Gets the extension of a filename.
+ *
+ * @param filename the filename to retrieve the extension of
+ * @return the extension of the file or an empty string if none exists or {@code null} if the filename is
+ * {@code null}
+ */
+ public static String getExtension(String filename) {
+ if (filename == null) {
+ return null;
+ }
+ final int index = filename.lastIndexOf(EXTENSION_SEPARATOR);
+ if (index == -1) {
+ return "";
+ } else {
+ return filename.substring(index + 1);
+ }
+ }
+
+ /**
+ * Checks if the extension of a filename matches the given.
+ *
+ * @param filename the filename to check the extension of
+ * @param extension the extension to check for
+ * @return {@code true} if the filename has the specified extension
+ */
+ public static boolean isExtension(String filename, String extension) {
+ if (filename == null) {
+ return false;
+ }
+ if (extension == null || extension.isEmpty()) {
+ return false;
+ }
+ return getExtension(filename).equals(extension);
+ }
+
+}
diff --git a/bundles/core/org.eclipse.smarthome.core.binding.xml.test/src/test/groovy/org/eclipse/smarthome/core/binding/xml/test/BindingInfoI18nTest.groovy b/bundles/core/org.eclipse.smarthome.core.binding.xml.test/src/test/groovy/org/eclipse/smarthome/core/binding/xml/test/BindingInfoI18nTest.groovy
index 58194680500..d77d3b282b5 100644
--- a/bundles/core/org.eclipse.smarthome.core.binding.xml.test/src/test/groovy/org/eclipse/smarthome/core/binding/xml/test/BindingInfoI18nTest.groovy
+++ b/bundles/core/org.eclipse.smarthome.core.binding.xml.test/src/test/groovy/org/eclipse/smarthome/core/binding/xml/test/BindingInfoI18nTest.groovy
@@ -13,6 +13,7 @@ import static org.junit.matchers.JUnitMatchers.*
import org.eclipse.smarthome.core.binding.BindingInfo
import org.eclipse.smarthome.core.binding.BindingInfoRegistry
+import org.eclipse.smarthome.core.i18n.LocaleProvider
import org.eclipse.smarthome.test.OSGiTest
import org.eclipse.smarthome.test.SyntheticBundleInstaller
import org.junit.After
@@ -109,6 +110,12 @@ class BindingInfoI18nTest extends OSGiTest {
localeCfg.put("country", "DE");
config.update(localeCfg);
+ //before running the test with a default locale make sure the locale has been set
+ LocaleProvider localeProvider = getService(LocaleProvider.class);
+ waitForAssert {
+ assertThat localeProvider.getLocale().toString(), is("de")
+ }
+
def bundleContext = getBundleContext()
def initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size()
diff --git a/bundles/core/org.eclipse.smarthome.core.persistence/META-INF/MANIFEST.MF b/bundles/core/org.eclipse.smarthome.core.persistence/META-INF/MANIFEST.MF
index 3d423a0965a..16f52f68702 100644
--- a/bundles/core/org.eclipse.smarthome.core.persistence/META-INF/MANIFEST.MF
+++ b/bundles/core/org.eclipse.smarthome.core.persistence/META-INF/MANIFEST.MF
@@ -6,10 +6,14 @@ Bundle-Version: 0.9.0.qualifier
Bundle-ManifestVersion: 2
Bundle-License: http://www.eclipse.org/legal/epl-v10.html
Bundle-SymbolicName: org.eclipse.smarthome.core.persistence
-Import-Package: org.eclipse.smarthome.config.core,
+Import-Package: org.eclipse.jdt.annotation;resolution:=optional,
+ org.eclipse.smarthome.config.core,
org.eclipse.smarthome.core.common.registry,
org.eclipse.smarthome.core.items,
org.eclipse.smarthome.core.persistence,
+ org.eclipse.smarthome.core.persistence.config,
+ org.eclipse.smarthome.core.persistence.dto,
+ org.eclipse.smarthome.core.persistence.strategy,
org.eclipse.smarthome.core.scheduler,
org.eclipse.smarthome.core.types,
org.slf4j
diff --git a/bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/service/AbstractWatchServiceTest.groovy b/bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/service/AbstractWatchServiceTest.groovy
index 741a93f8111..94b7018c96d 100644
--- a/bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/service/AbstractWatchServiceTest.groovy
+++ b/bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/service/AbstractWatchServiceTest.groovy
@@ -396,7 +396,6 @@ class AbstractWatchServiceTest extends OSGiTest {
allFullEvents << fullEvent
}
- @SuppressWarnings("unchecked")
@Override
protected Kind>[] getWatchEventKinds(Path subDir) {
return [
diff --git a/bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/storage/ManagedItemProviderOSGiTest.groovy b/bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/storage/ManagedItemProviderOSGiTest.groovy
index 8342bee77d1..8605ecb53b5 100644
--- a/bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/storage/ManagedItemProviderOSGiTest.groovy
+++ b/bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/storage/ManagedItemProviderOSGiTest.groovy
@@ -21,11 +21,11 @@ import org.eclipse.smarthome.core.items.ManagedItemProvider.PersistedItem
import org.eclipse.smarthome.core.library.items.NumberItem
import org.eclipse.smarthome.core.library.items.StringItem
import org.eclipse.smarthome.core.library.items.SwitchItem
+import org.eclipse.smarthome.core.library.types.OnOffType;
+import org.eclipse.smarthome.core.library.types.StringType
import org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction.And
import org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction.Avg
import org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction.Sum
-import org.eclipse.smarthome.core.library.types.OnOffType;
-import org.eclipse.smarthome.core.library.types.StringType
import org.eclipse.smarthome.core.types.Command
import org.eclipse.smarthome.core.types.State
import org.eclipse.smarthome.test.OSGiTest
@@ -216,7 +216,7 @@ class ManagedItemProviderOSGiTest extends OSGiTest {
Storage storage = storageService.getStorage(Item.class.getName())
StrangeItem item = new StrangeItem('SomeStrangeItem')
- String key = itemProvider.keyToString(itemProvider.getKey(item))
+ String key = itemProvider.keyToString(item.getUID())
// put an item into the storage that cannot be handled (yet)
PersistedItem persistableElement = storage.put(key, itemProvider.toPersistableElement(item))
@@ -256,8 +256,8 @@ class ManagedItemProviderOSGiTest extends OSGiTest {
GroupItem groupItem = new GroupItem('SomeGroupItem')
item.addGroupName(groupItem.getName())
groupItem.addMember(item)
- String itemKey = itemProvider.keyToString(itemProvider.getKey(item))
- String groupKey = itemProvider.keyToString(itemProvider.getKey(groupItem))
+ String itemKey = itemProvider.keyToString(item.getUID())
+ String groupKey = itemProvider.keyToString(groupItem.getUID())
// put items into the storage that cannot be handled (yet)
PersistedItem persistableElement1 = storage.put(itemKey, itemProvider.toPersistableElement(item))
@@ -316,7 +316,7 @@ class ManagedItemProviderOSGiTest extends OSGiTest {
@Test
- void 'assert group functions are stored and retrieved as well'() {
+ void 'assert group functions are stored and retrieved as well'() {
assertThat itemProvider.getAll().size(), is(0)
diff --git a/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/items/GroupItemTest.java b/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/items/GroupItemTest.java
index 9d33ba2e41a..d2edf474f72 100644
--- a/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/items/GroupItemTest.java
+++ b/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/items/GroupItemTest.java
@@ -10,14 +10,18 @@
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.smarthome.core.events.Event;
+import org.eclipse.smarthome.core.events.EventFilter;
import org.eclipse.smarthome.core.events.EventPublisher;
+import org.eclipse.smarthome.core.events.EventSubscriber;
import org.eclipse.smarthome.core.items.events.GroupItemStateChangedEvent;
+import org.eclipse.smarthome.core.items.events.ItemUpdatedEvent;
import org.eclipse.smarthome.core.library.items.ColorItem;
import org.eclipse.smarthome.core.library.items.DimmerItem;
import org.eclipse.smarthome.core.library.items.NumberItem;
@@ -33,6 +37,7 @@
import org.eclipse.smarthome.core.types.UnDefType;
import org.eclipse.smarthome.test.java.JavaOSGiTest;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
public class GroupItemTest extends JavaOSGiTest {
@@ -43,9 +48,61 @@ public class GroupItemTest extends JavaOSGiTest {
List events = new LinkedList<>();
EventPublisher publisher;
+ ItemRegistry itemRegistry;
+
@Before
public void setUp() {
+ registerVolatileStorageService();
publisher = event -> events.add(event);
+
+ itemRegistry = getService(ItemRegistry.class);
+ assertNotNull(itemRegistry);
+
+ registerService(new EventSubscriber() {
+
+ @Override
+ public void receive(Event event) {
+ events.add(event);
+ }
+
+ @Override
+ public Set getSubscribedEventTypes() {
+ HashSet hs = new HashSet<>();
+ hs.add(ItemUpdatedEvent.TYPE);
+ return hs;
+ }
+
+ @Override
+ public EventFilter getEventFilter() {
+ return null;
+ }
+ });
+ }
+
+ @Ignore
+ @Test
+ public void testItemUpdateWithItemRegistry() {
+ GroupItem item = new GroupItem("mySimpleGroupItem");
+ item.setLabel("firstLabel");
+
+ itemRegistry.add(item);
+
+ GroupItem updatedItem = (GroupItem) itemRegistry.get("mySimpleGroupItem");
+ assertNotNull(updatedItem);
+
+ events.clear();
+
+ updatedItem.setLabel("secondLabel");
+ itemRegistry.update(updatedItem);
+ waitForAssert(() -> assertThat(events.size(), is(1)));
+
+ List stateChanges = events.stream().filter(it -> it instanceof ItemUpdatedEvent)
+ .collect(Collectors.toList());
+ assertThat(stateChanges.size(), is(1));
+
+ ItemUpdatedEvent change = (ItemUpdatedEvent) stateChanges.get(0);
+
+ assertThat(change.getItem().label, is("secondLabel"));
}
@Test()
diff --git a/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/net/NetUtilTest.java b/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/net/NetUtilTest.java
new file mode 100644
index 00000000000..3eb68a36999
--- /dev/null
+++ b/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/net/NetUtilTest.java
@@ -0,0 +1,68 @@
+/**
+ * Copyright (c) 2014-2017 by the respective copyright holders.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.eclipse.smarthome.core.net;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+/**
+ * Tests for NetUtil class
+ *
+ * @author Stefan Triller - initial contribution
+ *
+ */
+public class NetUtilTest {
+
+ @Test
+ public void testNetwork() {
+ String network = NetUtil.getIpv4NetAddress("192.168.0.1", (short) 24);
+ assertThat(network, is("192.168.0.0"));
+
+ network = NetUtil.getIpv4NetAddress("192.168.23.5", (short) 24);
+ assertThat(network, is("192.168.23.0"));
+
+ network = NetUtil.getIpv4NetAddress("172.16.42.23", (short) 16);
+ assertThat(network, is("172.16.0.0"));
+
+ network = NetUtil.getIpv4NetAddress("10.8.13.5", (short) 8);
+ assertThat(network, is("10.0.0.0"));
+
+ network = NetUtil.getIpv4NetAddress("192.168.5.8", (short) 23);
+ assertThat(network, is("192.168.4.0"));
+
+ network = NetUtil.getIpv4NetAddress("192.168.5.8", (short) 27);
+ assertThat(network, is("192.168.5.0"));
+
+ network = NetUtil.getIpv4NetAddress("192.168.5.8", (short) 29);
+ assertThat(network, is("192.168.5.8"));
+
+ try {
+ network = NetUtil.getIpv4NetAddress("192.168.5.8", (short) 32);
+ } catch (IllegalArgumentException iae) {
+ assertThat(iae.getMessage(), is("Netmask '32' is out of bounds (1-31)"));
+ }
+ try {
+ network = NetUtil.getIpv4NetAddress("192.168.58", (short) 24);
+ } catch (IllegalArgumentException iae) {
+ assertThat(iae.getMessage(), is("IP '192.168.58' is not a valid IPv4 address"));
+ }
+ try {
+ network = NetUtil.getIpv4NetAddress("SOME_TEXT", (short) 24);
+ } catch (IllegalArgumentException iae) {
+ assertThat(iae.getMessage(), is("IP 'SOME_TEXT' is not a valid IPv4 address"));
+ }
+ try {
+ network = NetUtil.getIpv4NetAddress("SOME_TEXT", (short) 42);
+ } catch (IllegalArgumentException iae) {
+ assertThat(iae.getMessage(), is("IP 'SOME_TEXT' is not a valid IPv4 address"));
+ }
+ }
+
+}
diff --git a/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/scheduler/CronExpressionTest.java b/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/scheduler/CronExpressionTest.java
index bf2982082e3..3b90d6ef719 100644
--- a/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/scheduler/CronExpressionTest.java
+++ b/bundles/core/org.eclipse.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/scheduler/CronExpressionTest.java
@@ -17,6 +17,7 @@
import java.util.List;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -78,6 +79,8 @@ public void getFinalTimeCheck() throws ParseException {
}
@Test
+ @Ignore
+ // FIXME: see issue #3912
public void findNext() throws ParseException {
boolean trace = false;
@@ -115,11 +118,11 @@ public void findNext() throws ParseException {
if (nextDate == null) {
final String msg = String.format("Cannot find a time after '%s' for expression '%s'",
sdf.format(curDate), cronExpression.getExpression());
- logger.error(msg);
+ logger.error("{}", msg);
Assert.fail(msg);
} else {
if (trace) {
- logger.info("Got: " + sdf.format(nextDate));
+ logger.info("Got: {}", sdf.format(nextDate));
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/BindingBaseClassesOSGiTest.groovy b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/BindingBaseClassesOSGiTest.groovy
index 87a9d613648..26c5396101d 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/BindingBaseClassesOSGiTest.groovy
+++ b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/BindingBaseClassesOSGiTest.groovy
@@ -116,6 +116,11 @@ class BindingBaseClassesOSGiTest extends OSGiTest {
// check getBridge works
assertThat getBridge().getUID().toString(), is("bindingId:type1:bridgeId")
}
+
+ @Override
+ void initialize() {
+ updateStatus(ThingStatus.ONLINE);
+ }
}
class SimpleBridgeHandler extends BaseBridgeHandler {
@@ -131,6 +136,11 @@ class BindingBaseClassesOSGiTest extends OSGiTest {
public void updateBridgetatus(ThingStatus status) {
updateStatus(status)
}
+
+ @Override
+ void initialize() {
+ updateStatus(ThingStatus.ONLINE);
+ }
}
@@ -314,6 +324,11 @@ class BindingBaseClassesOSGiTest extends OSGiTest {
// not implemented
}
+ @Override
+ void initialize() {
+ updateStatus(ThingStatus.ONLINE);
+ }
+
@Override
public Collection getConfigStatus() {
if("invalid".equals(getThing().getConfiguration().get(PARAM))) {
@@ -344,12 +359,12 @@ class BindingBaseClassesOSGiTest extends OSGiTest {
@Override
public void initialize() {
- super.initialize()
ThingBuilder thingBuilder = editThing()
thingBuilder.withChannels([
new Channel(new ChannelUID("bindingId:type:thingId:1"), "String")
])
updateThing(thingBuilder.build())
+ updateStatus(ThingStatus.ONLINE)
}
@Override
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/ChangeThingTypeOSGiTest.groovy b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/ChangeThingTypeOSGiTest.groovy
index 1a6ef3f22a7..1ac3a4ecc7d 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/ChangeThingTypeOSGiTest.groovy
+++ b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/ChangeThingTypeOSGiTest.groovy
@@ -209,7 +209,7 @@ class ChangeThingTypeOSGiTest extends OSGiTest {
@Override
public void initialize() {
println "[ChangeThingTypeOSGiTest] GenericThingHandler.initialize"
- super.initialize()
+ updateStatus(ThingStatus.ONLINE)
genericInits++;
if (selfChanging) {
changeThingType(THING_TYPE_SPECIFIC_UID, new Configuration(['providedspecific':'there']))
@@ -233,7 +233,7 @@ class ChangeThingTypeOSGiTest extends OSGiTest {
public void initialize() {
println "[ChangeThingTypeOSGiTest] SpecificThingHandler.initialize"
specificInits++;
- super.initialize();
+ updateStatus(ThingStatus.ONLINE);
}
@Override
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/ThingFactoryTest.groovy b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/ThingFactoryTest.groovy
index b98bc940216..b6cc5104900 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/ThingFactoryTest.groovy
+++ b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/ThingFactoryTest.groovy
@@ -181,8 +181,8 @@ class ThingFactoryTest extends OSGiTest{
ChannelDefinition channelDef1 = new ChannelDefinition("ch1", channelType1.UID)
ChannelDefinition channelDef2 = new ChannelDefinition("ch2", channelType2.UID)
- ChannelGroupType channelGroupType1 = new ChannelGroupType(new ChannelGroupTypeUID("bindingid:groupTypeId1"), false, "label", "description", [channelDef1, channelDef2])
- ChannelGroupType channelGroupType2 = new ChannelGroupType(new ChannelGroupTypeUID("bindingid:groupTypeId2"), false, "label", "description", [channelDef1])
+ ChannelGroupType channelGroupType1 = new ChannelGroupType(new ChannelGroupTypeUID("bindingid:groupTypeId1"), false, "label", "description", "myCategory1", [channelDef1, channelDef2])
+ ChannelGroupType channelGroupType2 = new ChannelGroupType(new ChannelGroupTypeUID("bindingid:groupTypeId2"), false, "label", "description", "myCategory2", [channelDef1])
ChannelGroupDefinition channelGroupDef1 = new ChannelGroupDefinition("group1", channelGroupType1.UID)
ChannelGroupDefinition channelGroupDef2 = new ChannelGroupDefinition("group2", channelGroupType2.UID)
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/firmware/FirmwareUpdateServiceOSGiTest.groovy b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/firmware/FirmwareUpdateServiceOSGiTest.groovy
index ef751749506..23e4a09d126 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/firmware/FirmwareUpdateServiceOSGiTest.groovy
+++ b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/firmware/FirmwareUpdateServiceOSGiTest.groovy
@@ -210,7 +210,7 @@ final class FirmwareUpdateServiceOSGiTest extends OSGiTest {
managedThingProvider = getService ManagedThingProvider
assertThat managedThingProvider, is(notNullValue())
}
-
+
thingRegistry = getService(ThingRegistry)
assertThat thingRegistry, is(notNullValue())
@@ -1099,7 +1099,7 @@ final class FirmwareUpdateServiceOSGiTest extends OSGiTest {
@Override
public void initialize() {
sleep wait
- super.initialize();
+ updateStatus(ThingStatus.ONLINE)
}
@Override
@@ -1172,7 +1172,7 @@ final class FirmwareUpdateServiceOSGiTest extends OSGiTest {
@Override
public void initialize() {
sleep wait
- super.initialize()
+ updateStatus(ThingStatus.ONLINE)
}
@Override
@@ -1223,5 +1223,10 @@ final class FirmwareUpdateServiceOSGiTest extends OSGiTest {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
}
+
+ @Override
+ public void initialize() {
+ updateStatus(ThingStatus.ONLINE)
+ }
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/i18n/ThingStatusInfoI18nLocalizationServiceOSGiTest.groovy b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/i18n/ThingStatusInfoI18nLocalizationServiceOSGiTest.groovy
index a53c61ab29c..b53d67dffb7 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/i18n/ThingStatusInfoI18nLocalizationServiceOSGiTest.groovy
+++ b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/i18n/ThingStatusInfoI18nLocalizationServiceOSGiTest.groovy
@@ -201,6 +201,11 @@ class ThingStatusInfoI18nLocalizationServiceOSGiTest extends OSGiTest {
//do nothing
}
+ @Override
+ public void initialize() {
+ updateStatus(ThingStatus.ONLINE);
+ }
+
void setThingStatusInfo(ThingStatusInfo thingStatusInfo) {
updateStatus(thingStatusInfo.getStatus(), thingStatusInfo.getStatusDetail(), thingStatusInfo.getDescription())
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/internal/ThingLinkManagerOSGiTest.groovy b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/internal/ThingLinkManagerOSGiTest.groovy
index b1361ef88d7..ded05e89b71 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/internal/ThingLinkManagerOSGiTest.groovy
+++ b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/internal/ThingLinkManagerOSGiTest.groovy
@@ -20,6 +20,7 @@ import org.eclipse.smarthome.core.thing.ChannelUID
import org.eclipse.smarthome.core.thing.ManagedThingProvider
import org.eclipse.smarthome.core.thing.Thing
import org.eclipse.smarthome.core.thing.ThingRegistry
+import org.eclipse.smarthome.core.thing.ThingStatus
import org.eclipse.smarthome.core.thing.ThingTypeUID
import org.eclipse.smarthome.core.thing.ThingUID
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler
@@ -176,6 +177,11 @@ class ThingLinkManagerOSGiTest extends OSGiTest {
return new BaseThingHandler(thing) {
public void handleCommand(ChannelUID channelUID, Command command) { }
+ @Override
+ public void initialize() {
+ updateStatus(ThingStatus.ONLINE);
+ }
+
void channelLinked(ChannelUID channelUID) {
putContext("linkedChannel", channelUID)
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/java/org/eclipse/smarthome/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/java/org/eclipse/smarthome/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java
index 8010eae1763..d373611da7b 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/java/org/eclipse/smarthome/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/java/org/eclipse/smarthome/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java
@@ -32,6 +32,7 @@
import org.eclipse.smarthome.core.thing.ManagedThingProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingRegistry;
+import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
@@ -296,6 +297,11 @@ protected ThingHandler createHandler(Thing thing) {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
}
+
+ @Override
+ public void initialize() {
+ updateStatus(ThingStatus.ONLINE);
+ }
};
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml.test/CoreThingXmlTests.launch b/bundles/core/org.eclipse.smarthome.core.thing.xml.test/CoreThingXmlTests.launch
index 1d6daa7f522..209ff888343 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml.test/CoreThingXmlTests.launch
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml.test/CoreThingXmlTests.launch
@@ -25,7 +25,7 @@
-
+
@@ -33,7 +33,7 @@
-
+
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/groovy/org/eclipse/smarthome/core/thing/xml/test/ChannelTypesTest.groovy b/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/groovy/org/eclipse/smarthome/core/thing/xml/test/ChannelTypesTest.groovy
index 6632fa58cf7..d6fd38e90df 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/groovy/org/eclipse/smarthome/core/thing/xml/test/ChannelTypesTest.groovy
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/groovy/org/eclipse/smarthome/core/thing/xml/test/ChannelTypesTest.groovy
@@ -74,6 +74,7 @@ class ChannelTypesTest extends OSGiTest {
def channelGroupType = channelGroupTypes.find( {it.UID.toString().equals("somebinding:channelgroup")} )
assertThat channelGroupType, is(not(null))
+ assertThat channelGroupType.category, is("Temperature")
SyntheticBundleInstaller.uninstall(bundleContext, TEST_BUNDLE_NAME)
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/groovy/org/eclipse/smarthome/core/thing/xml/test/ThingTypesTest.groovy b/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/groovy/org/eclipse/smarthome/core/thing/xml/test/ThingTypesTest.groovy
index eba7f9050ff..ce2138ceb0e 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/groovy/org/eclipse/smarthome/core/thing/xml/test/ThingTypesTest.groovy
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/groovy/org/eclipse/smarthome/core/thing/xml/test/ThingTypesTest.groovy
@@ -59,6 +59,7 @@ class ThingTypesTest extends OSGiTest {
assertThat bridgeType.description, is("The hue Bridge represents the Philips hue bridge.")
assertThat bridgeType.properties.size(), is(1)
assertThat bridgeType.properties.get("vendor"), is("Philips")
+ assertThat bridgeType.representationProperty, is("serialNumber")
def thingType = thingTypes.find { it.toString().equals("hue:lamp") } as ThingType
assertThat thingType, is(notNullValue())
@@ -70,6 +71,7 @@ class ThingTypesTest extends OSGiTest {
assertThat thingType.properties.size(), is(2)
assertThat thingType.properties.get("key1"), is("value1")
assertThat thingType.properties.get("key2"), is("value2")
+ assertThat thingType.representationProperty, is("uniqueId")
thingType.channelDefinitions.with {
assertThat size(), is(3)
def colorChannel = it.find { it.id.equals("color") } as ChannelDefinition
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/resources/test-bundle-pool/ChannelTypesTest.bundle/ESH-INF/thing/thing-types.xml b/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/resources/test-bundle-pool/ChannelTypesTest.bundle/ESH-INF/thing/thing-types.xml
index 509b6e017d0..88ef35a087c 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/resources/test-bundle-pool/ChannelTypesTest.bundle/ESH-INF/thing/thing-types.xml
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/resources/test-bundle-pool/ChannelTypesTest.bundle/ESH-INF/thing/thing-types.xml
@@ -26,6 +26,7 @@
+ Temperature
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/resources/test-bundle-pool/ThingTypesTest.bundle/ESH-INF/thing/thing-types.xml b/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/resources/test-bundle-pool/ThingTypesTest.bundle/ESH-INF/thing/thing-types.xml
index 252ae675331..6a9dfbee1c7 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/resources/test-bundle-pool/ThingTypesTest.bundle/ESH-INF/thing/thing-types.xml
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml.test/src/test/resources/test-bundle-pool/ThingTypesTest.bundle/ESH-INF/thing/thing-types.xml
@@ -13,6 +13,7 @@
Philips
+ serialNumber
@@ -55,6 +56,7 @@
value1value2
+ uniqueId
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/BridgeTypeConverter.java b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/BridgeTypeConverter.java
index 08b3a0bc7cf..37c7b415e92 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/BridgeTypeConverter.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/BridgeTypeConverter.java
@@ -27,6 +27,7 @@
*
* @author Michael Grammling - Initial Contribution
* @author Thomas Höfer - Added thing and thing type properties
+ * @author Andre Fuechsel - Added representationProperty
*/
public class BridgeTypeConverter extends ThingTypeConverter {
@@ -43,7 +44,7 @@ protected BridgeTypeXmlResult unmarshalType(HierarchicalStreamReader reader, Unm
super.readSupportedBridgeTypeUIDs(nodeIterator, context), super.readLabel(nodeIterator),
super.readDescription(nodeIterator), super.getListed(attributes),
super.getChannelTypeReferenceObjects(nodeIterator), getProperties(nodeIterator),
- super.getConfigDescriptionObjects(nodeIterator));
+ super.getRepresentationProperty(nodeIterator), super.getConfigDescriptionObjects(nodeIterator));
return bridgeTypeXmlResult;
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/BridgeTypeXmlResult.java b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/BridgeTypeXmlResult.java
index 5bc7613681e..a1f8bfbfa2c 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/BridgeTypeXmlResult.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/BridgeTypeXmlResult.java
@@ -26,22 +26,24 @@
*
* @author Michael Grammling - Initial Contribution
* @author Thomas Höfer - Added thing and thing type properties
+ * @author Andre Fuechsel - Added representationProperty
*/
public class BridgeTypeXmlResult extends ThingTypeXmlResult {
public BridgeTypeXmlResult(ThingTypeUID bridgeTypeUID, List supportedBridgeTypeUIDs, String label,
String description, boolean listed, List[] channelTypeReferenceObjects,
- List properties, Object[] configDescriptionObjects) {
+ List properties, String representationProperty, Object[] configDescriptionObjects) {
super(bridgeTypeUID, supportedBridgeTypeUIDs, label, description, listed, channelTypeReferenceObjects,
- properties, configDescriptionObjects);
+ properties, representationProperty, configDescriptionObjects);
}
@Override
public ThingType toThingType() throws ConversionException {
BridgeType bridgeType = new BridgeType(super.thingTypeUID, super.supportedBridgeTypeUIDs, super.label,
- super.description, super.listed, super.toChannelDefinitions(this.channelTypeReferences),
+ super.description, super.listed, super.representationProperty,
+ super.toChannelDefinitions(this.channelTypeReferences),
super.toChannelGroupDefinitions(this.channelGroupTypeReferences), super.toPropertiesMap(),
super.configDescriptionURI);
@@ -52,9 +54,10 @@ public ThingType toThingType() throws ConversionException {
public String toString() {
return "BridgeTypeXmlResult [thingTypeUID=" + thingTypeUID + ", supportedBridgeTypeUIDs="
+ supportedBridgeTypeUIDs + ", label=" + label + ", description=" + description + ", listed=" + listed
- + ", channelTypeReferences=" + channelTypeReferences + ", channelGroupTypeReferences="
- + channelGroupTypeReferences + ", properties=" + properties + ", configDescriptionURI="
- + configDescriptionURI + ", configDescription=" + configDescription + "]";
+ + ", representationProperty=" + representationProperty + ", channelTypeReferences="
+ + channelTypeReferences + ", channelGroupTypeReferences=" + channelGroupTypeReferences + ", properties="
+ + properties + ", configDescriptionURI=" + configDescriptionURI + ", configDescription="
+ + configDescription + "]";
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ChannelGroupTypeConverter.java b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ChannelGroupTypeConverter.java
index 945bdeb42b1..4bf62076580 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ChannelGroupTypeConverter.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ChannelGroupTypeConverter.java
@@ -35,8 +35,8 @@ public class ChannelGroupTypeConverter extends AbstractDescriptionTypeConverter<
public ChannelGroupTypeConverter() {
super(ChannelGroupTypeXmlResult.class, "channel-group-type");
- super.attributeMapValidator = new ConverterAttributeMapValidator(new String[][] { { "id", "true" },
- { "advanced", "false" } });
+ super.attributeMapValidator = new ConverterAttributeMapValidator(
+ new String[][] { { "id", "true" }, { "advanced", "false" } });
}
private boolean isAdvanced(Map attributes, boolean defaultValue) {
@@ -65,12 +65,22 @@ protected ChannelGroupTypeXmlResult unmarshalType(HierarchicalStreamReader reade
String label = super.readLabel(nodeIterator);
String description = super.readDescription(nodeIterator);
+ String category = readCategory(nodeIterator);
List channelTypeDefinitions = readChannelTypeDefinitions(nodeIterator);
- ChannelGroupTypeXmlResult groupChannelType = new ChannelGroupTypeXmlResult(channelGroupTypeUID, advanced,
- label, description, channelTypeDefinitions);
+ ChannelGroupTypeXmlResult groupChannelType = new ChannelGroupTypeXmlResult(channelGroupTypeUID, advanced, label,
+ description, category, channelTypeDefinitions);
return groupChannelType;
}
+ private String readCategory(NodeIterator nodeIterator) {
+ Object category = nodeIterator.nextValue("category", false);
+ if (category != null) {
+ return category.toString();
+ } else {
+ return null;
+ }
+ }
+
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ChannelGroupTypeXmlResult.java b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ChannelGroupTypeXmlResult.java
index 3b671e31801..e4792d7fdf4 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ChannelGroupTypeXmlResult.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ChannelGroupTypeXmlResult.java
@@ -32,15 +32,17 @@ public class ChannelGroupTypeXmlResult {
private boolean advanced;
private String label;
private String description;
+ private String category;
private List channelTypeReferences;
public ChannelGroupTypeXmlResult(ChannelGroupTypeUID channelGroupTypeUID, boolean advanced, String label,
- String description, List channelTypeReferences) {
+ String description, String category, List channelTypeReferences) {
this.channelGroupTypeUID = channelGroupTypeUID;
this.advanced = advanced;
this.label = label;
this.description = description;
+ this.category = category;
this.channelTypeReferences = channelTypeReferences;
}
@@ -67,7 +69,7 @@ protected List toChannelDefinitions(List ch
public ChannelGroupType toChannelGroupType() throws ConversionException {
ChannelGroupType channelGroupType = new ChannelGroupType(this.channelGroupTypeUID, this.advanced, this.label,
- this.description, toChannelDefinitions(this.channelTypeReferences));
+ this.description, this.category, toChannelDefinitions(this.channelTypeReferences));
return channelGroupType;
}
@@ -75,8 +77,8 @@ public ChannelGroupType toChannelGroupType() throws ConversionException {
@Override
public String toString() {
return "ChannelGroupTypeXmlResult [channelGroupTypeUID=" + channelGroupTypeUID + ", advanced=" + advanced
- + ", label=" + label + ", description=" + description + ", channelTypeReferences="
- + channelTypeReferences + "]";
+ + ", label=" + label + ", description=" + description + ", category=" + category
+ + ", channelTypeReferences=" + channelTypeReferences + "]";
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/EventDescriptionConverter.java b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/EventDescriptionConverter.java
index 1d3442e9f27..dd2a7c05fb2 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/EventDescriptionConverter.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/EventDescriptionConverter.java
@@ -10,12 +10,14 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+
import org.eclipse.smarthome.config.xml.util.GenericUnmarshaller;
import org.eclipse.smarthome.config.xml.util.NodeIterator;
import org.eclipse.smarthome.config.xml.util.NodeList;
import org.eclipse.smarthome.config.xml.util.NodeValue;
import org.eclipse.smarthome.core.types.EventDescription;
import org.eclipse.smarthome.core.types.EventOption;
+
import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
@@ -26,6 +28,8 @@
* used to convert a event description within an XML document into a {@link EventDescription} object.
*
* This converter converts {@code state} XML tags.
+ *
+ * @author Moritz Kammerer - Initial contribution
*/
public class EventDescriptionConverter extends GenericUnmarshaller {
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ThingDescriptionReader.java b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ThingDescriptionReader.java
index d9778ae78cf..31b01dc1d03 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ThingDescriptionReader.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ThingDescriptionReader.java
@@ -8,6 +8,7 @@
package org.eclipse.smarthome.core.thing.xml.internal;
import java.util.List;
+
import org.eclipse.smarthome.config.core.ConfigDescription;
import org.eclipse.smarthome.config.core.ConfigDescriptionParameter;
import org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup;
@@ -25,6 +26,7 @@
import org.eclipse.smarthome.config.xml.util.XmlDocumentReader;
import org.eclipse.smarthome.core.types.EventDescription;
import org.eclipse.smarthome.core.types.StateDescription;
+
import com.thoughtworks.xstream.XStream;
/**
@@ -101,6 +103,7 @@ public void registerAliases(XStream xstream) {
xstream.alias("criteria", FilterCriteria.class);
xstream.alias("properties", NodeList.class);
xstream.alias("property", NodeValue.class);
+ xstream.alias("representation-property", NodeValue.class);
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ThingTypeConverter.java b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ThingTypeConverter.java
index f44ecd09eac..148feba5666 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ThingTypeConverter.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ThingTypeConverter.java
@@ -32,6 +32,7 @@
* @author Michael Grammling - Initial Contribution
* @author Thomas Höfer - Added thing and thing type properties
* @author Chris Jackson - Added channel properties
+ * @author Andre Fuechsel - Added representationProperty
*/
public class ThingTypeConverter extends AbstractDescriptionTypeConverter {
@@ -95,7 +96,7 @@ protected ThingTypeXmlResult unmarshalType(HierarchicalStreamReader reader, Unma
new ThingTypeUID(super.getUID(attributes, context)), readSupportedBridgeTypeUIDs(nodeIterator, context),
super.readLabel(nodeIterator), super.readDescription(nodeIterator), getListed(attributes),
getChannelTypeReferenceObjects(nodeIterator), getProperties(nodeIterator),
- super.getConfigDescriptionObjects(nodeIterator));
+ getRepresentationProperty(nodeIterator), super.getConfigDescriptionObjects(nodeIterator));
return thingTypeXmlResult;
}
@@ -108,4 +109,8 @@ protected boolean getListed(Map attributes) {
return true;
}
+ protected String getRepresentationProperty(NodeIterator nodeIterator) {
+ return (String) nodeIterator.nextValue("representation-property", false);
+ }
+
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ThingTypeXmlResult.java b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ThingTypeXmlResult.java
index 7b5678d1403..70e44145ac4 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ThingTypeXmlResult.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/ThingTypeXmlResult.java
@@ -35,6 +35,7 @@
* @author Thomas Höfer - Added thing and thing type properties
* @author Chris Jackson - Added channel properties
* @author Simon Kaufmann - Added listed field
+ * @author Andre Fuechsel - Added representationProperty field
*/
public class ThingTypeXmlResult {
@@ -43,6 +44,7 @@ public class ThingTypeXmlResult {
protected String label;
protected String description;
protected boolean listed;
+ protected String representationProperty;
protected List channelTypeReferences;
protected List channelGroupTypeReferences;
protected List properties;
@@ -51,13 +53,14 @@ public class ThingTypeXmlResult {
public ThingTypeXmlResult(ThingTypeUID thingTypeUID, List supportedBridgeTypeUIDs, String label,
String description, boolean listed, List[] channelTypeReferenceObjects,
- List properties, Object[] configDescriptionObjects) {
+ List properties, String representationProperty, Object[] configDescriptionObjects) {
this.thingTypeUID = thingTypeUID;
this.supportedBridgeTypeUIDs = supportedBridgeTypeUIDs;
this.label = label;
this.description = description;
this.listed = listed;
+ this.representationProperty = representationProperty;
this.channelTypeReferences = channelTypeReferenceObjects[0];
this.channelGroupTypeReferences = channelTypeReferenceObjects[1];
this.properties = properties;
@@ -126,7 +129,8 @@ protected Map toPropertiesMap() {
public ThingType toThingType() throws ConversionException {
ThingType thingType = new ThingType(this.thingTypeUID, this.supportedBridgeTypeUIDs, this.label,
- this.description, this.listed, toChannelDefinitions(this.channelTypeReferences),
+ this.description, this.listed, this.representationProperty,
+ toChannelDefinitions(this.channelTypeReferences),
toChannelGroupDefinitions(this.channelGroupTypeReferences), toPropertiesMap(),
this.configDescriptionURI);
@@ -137,9 +141,10 @@ this.description, this.listed, toChannelDefinitions(this.channelTypeReferences),
public String toString() {
return "ThingTypeXmlResult [thingTypeUID=" + thingTypeUID + ", supportedBridgeTypeUIDs="
+ supportedBridgeTypeUIDs + ", label=" + label + ", description=" + description + ", listed=" + listed
- + ", channelTypeReferences=" + channelTypeReferences + ", channelGroupTypeReferences="
- + channelGroupTypeReferences + ", properties=" + properties + ", configDescriptionURI="
- + configDescriptionURI + ", configDescription=" + configDescription + "]";
+ + ", representationProperty=" + representationProperty + ", channelTypeReferences="
+ + channelTypeReferences + ", channelGroupTypeReferences=" + channelGroupTypeReferences + ", properties="
+ + properties + ", configDescriptionURI=" + configDescriptionURI + ", configDescription="
+ + configDescription + "]";
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/XmlChannelGroupTypeProvider.java b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/XmlChannelGroupTypeProvider.java
index 0f59278422f..ac86af2a8e4 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/XmlChannelGroupTypeProvider.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/XmlChannelGroupTypeProvider.java
@@ -67,7 +67,8 @@ protected ChannelGroupType localize(Bundle bundle, ChannelGroupType channelGroup
channelGroupType.getDescription(), locale);
ChannelGroupType localizedChannelGroupType = new ChannelGroupType(channelGroupTypeUID,
- channelGroupType.isAdvanced(), label, description, channelGroupType.getChannelDefinitions());
+ channelGroupType.isAdvanced(), label, description, channelGroupType.getCategory(),
+ channelGroupType.getChannelDefinitions());
return localizedChannelGroupType;
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing.xml/thing-description-1.0.0.xsd b/bundles/core/org.eclipse.smarthome.core.thing.xml/thing-description-1.0.0.xsd
index 0478d8798b2..74ae3d521d2 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing.xml/thing-description-1.0.0.xsd
+++ b/bundles/core/org.eclipse.smarthome.core.thing.xml/thing-description-1.0.0.xsd
@@ -29,6 +29,7 @@
+
@@ -68,6 +69,7 @@
+
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/META-INF/MANIFEST.MF b/bundles/core/org.eclipse.smarthome.core.thing/META-INF/MANIFEST.MF
index 88cae26aa28..a26257abd34 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/META-INF/MANIFEST.MF
+++ b/bundles/core/org.eclipse.smarthome.core.thing/META-INF/MANIFEST.MF
@@ -11,6 +11,7 @@ Import-Package: com.google.common.base,
org.apache.commons.collections.iterators,
org.apache.commons.io,
org.apache.commons.lang,
+ org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.config.core,
org.eclipse.smarthome.config.core.dto,
org.eclipse.smarthome.config.core.status,
@@ -28,8 +29,11 @@ Import-Package: com.google.common.base,
org.eclipse.smarthome.core.thing,
org.eclipse.smarthome.core.thing.binding,
org.eclipse.smarthome.core.thing.binding.builder,
+ org.eclipse.smarthome.core.thing.binding.firmware,
org.eclipse.smarthome.core.thing.dto,
org.eclipse.smarthome.core.thing.events,
+ org.eclipse.smarthome.core.thing.firmware,
+ org.eclipse.smarthome.core.thing.firmware.dto,
org.eclipse.smarthome.core.thing.i18n,
org.eclipse.smarthome.core.thing.link,
org.eclipse.smarthome.core.thing.link.dto,
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/Channel.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/Channel.java
index 1e2c9da7c29..1137a3a7b0c 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/Channel.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/Channel.java
@@ -13,6 +13,9 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.items.Item;
import org.eclipse.smarthome.core.thing.type.ChannelKind;
@@ -44,9 +47,9 @@ public class Channel {
private String description;
- private Configuration configuration;
+ private @NonNull Configuration configuration;
- private Map properties;
+ private @NonNull Map<@NonNull String, String> properties;
private Set defaultTags = new LinkedHashSet<>();
@@ -54,6 +57,8 @@ public class Channel {
* Package protected default constructor to allow reflective instantiation.
*/
Channel() {
+ this.configuration = new Configuration();
+ this.properties = Collections.unmodifiableMap(new HashMap<@NonNull String, String>(0));
}
public Channel(ChannelUID uid, String acceptedItemType) {
@@ -61,7 +66,7 @@ public Channel(ChannelUID uid, String acceptedItemType) {
this.acceptedItemType = acceptedItemType;
this.kind = ChannelKind.STATE;
this.configuration = new Configuration();
- this.properties = Collections.unmodifiableMap(new HashMap(0));
+ this.properties = Collections.unmodifiableMap(new HashMap<@NonNull String, String>(0));
}
public Channel(ChannelUID uid, String acceptedItemType, Configuration configuration) {
@@ -74,13 +79,13 @@ public Channel(ChannelUID uid, String acceptedItemType, Set defaultTags)
}
public Channel(ChannelUID uid, String acceptedItemType, Configuration configuration, Set defaultTags,
- Map properties) {
+ Map<@NonNull String, String> properties) {
this(uid, null, acceptedItemType, ChannelKind.STATE, null,
defaultTags == null ? new HashSet(0) : defaultTags, properties, null, null);
}
public Channel(ChannelUID uid, ChannelTypeUID channelTypeUID, String acceptedItemType, ChannelKind kind,
- Configuration configuration, Set defaultTags, Map properties, String label,
+ Configuration configuration, Set defaultTags, Map<@NonNull String, String> properties, String label,
String description) {
if (kind == null) {
throw new IllegalArgumentException("kind must not be null");
@@ -89,17 +94,19 @@ public Channel(ChannelUID uid, ChannelTypeUID channelTypeUID, String acceptedIte
this.uid = uid;
this.channelTypeUID = channelTypeUID;
this.acceptedItemType = acceptedItemType;
- this.configuration = configuration;
this.kind = kind;
this.label = label;
this.description = description;
- this.properties = properties;
this.defaultTags = Collections. unmodifiableSet(new HashSet(defaultTags));
- if (this.configuration == null) {
+ if (configuration == null) {
this.configuration = new Configuration();
+ } else {
+ this.configuration = configuration;
}
- if (this.properties == null) {
- this.properties = Collections.unmodifiableMap(new HashMap(0));
+ if (properties == null) {
+ this.properties = Collections.unmodifiableMap(new HashMap<@NonNull String, String>(0));
+ } else {
+ this.properties = properties;
}
}
@@ -140,7 +147,7 @@ public ChannelUID getUID() {
*
* @return channel type UID or null if no channel type is specified
*/
- public ChannelTypeUID getChannelTypeUID() {
+ public @Nullable ChannelTypeUID getChannelTypeUID() {
return channelTypeUID;
}
@@ -150,7 +157,7 @@ public ChannelTypeUID getChannelTypeUID() {
*
* @return the label for the channel. Can be null.
*/
- public String getLabel() {
+ public @Nullable String getLabel() {
return this.label;
}
@@ -161,7 +168,7 @@ public String getLabel() {
*
* @return the description for the channel. Can be null.
*/
- public String getDescription() {
+ public @Nullable String getDescription() {
return this.description;
}
@@ -170,7 +177,7 @@ public String getDescription() {
*
* @return channel configuration (not null)
*/
- public Configuration getConfiguration() {
+ public @NonNull Configuration getConfiguration() {
return configuration;
}
@@ -179,7 +186,7 @@ public Configuration getConfiguration() {
*
* @return channel properties (not null)
*/
- public Map getProperties() {
+ public @NonNull Map<@NonNull String, String> getProperties() {
return properties;
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ManagedThingProvider.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ManagedThingProvider.java
index 82a98605ff5..7f6f467aacd 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ManagedThingProvider.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ManagedThingProvider.java
@@ -21,11 +21,6 @@
*/
public class ManagedThingProvider extends DefaultAbstractManagedProvider implements ThingProvider {
- @Override
- protected ThingUID getKey(Thing thing) {
- return thing.getUID();
- }
-
@Override
protected String getStorageName() {
return Thing.class.getName();
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/Thing.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/Thing.java
index d8c777f30ac..d8ea50b579a 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/Thing.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/Thing.java
@@ -10,6 +10,8 @@
import java.util.List;
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.common.registry.Identifiable;
import org.eclipse.smarthome.core.items.Item;
@@ -75,6 +77,7 @@ public interface Thing extends Identifiable {
* @return the channel for the given id or null if no channel with the id
* exists
*/
+ @Nullable
Channel getChannel(String channelId);
/**
@@ -117,6 +120,7 @@ public interface Thing extends Identifiable {
*
* @return the handler (can be null)
*/
+ @Nullable
ThingHandler getHandler();
/**
@@ -124,6 +128,7 @@ public interface Thing extends Identifiable {
*
* @return the bridge UID (can be null)
*/
+ @Nullable
ThingUID getBridgeUID();
/**
@@ -139,6 +144,7 @@ public interface Thing extends Identifiable {
*
* @return the configuration (not null)
*/
+ @NonNull
Configuration getConfiguration();
/**
@@ -161,7 +167,8 @@ public interface Thing extends Identifiable {
*
* @return an immutable copy of the {@link Thing} properties (not null)
*/
- Map getProperties();
+ @NonNull
+ Map<@NonNull String, String> getProperties();
/**
* Sets the property value for the property identified by the given name. If the value to be set is null then the
@@ -173,14 +180,14 @@ public interface Thing extends Identifiable {
*
* @return the previous value associated with the name, or null if there was no mapping for the name
*/
- String setProperty(String name, String value);
+ String setProperty(@NonNull String name, String value);
/**
* Updates all properties of the thing.
*
* @param properties the properties to set (must not be null)
*/
- void setProperties(Map properties);
+ void setProperties(@NonNull Map properties);
/**
* Get the physical location of the {@link Thing}.
@@ -188,6 +195,7 @@ public interface Thing extends Identifiable {
* @return the location identifier (presumably an item name) or null if no location has been
* configured.
*/
+ @Nullable
String getLocation();
/**
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ThingRegistry.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ThingRegistry.java
index 3dfeb688804..ca3a96dc815 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ThingRegistry.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ThingRegistry.java
@@ -9,6 +9,8 @@
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.config.core.validation.ConfigValidationException;
import org.eclipse.smarthome.core.common.registry.Registry;
@@ -42,7 +44,8 @@ public interface ThingRegistry extends Registry {
* @param channelUID channel UID
* @return channel for the given channel UID or null of no channel was found
*/
- Channel getChannel(ChannelUID channelUID);
+ @Nullable
+ Channel getChannel(@NonNull ChannelUID channelUID);
/**
* Updates the configuration of a thing for the given UID.
@@ -53,7 +56,7 @@ public interface ThingRegistry extends Registry {
* @throws ConfigValidationException if one or more of the given configuration parameters do not match
* their declarations in the configuration description
*/
- void updateConfiguration(ThingUID thingUID, Map configurationParameters);
+ void updateConfiguration(@NonNull ThingUID thingUID, Map<@NonNull String, Object> configurationParameters);
/**
* Initiates the removal process for the {@link Thing} specified by the given {@link ThingUID}.
@@ -80,7 +83,8 @@ public interface ThingRegistry extends Registry {
* @param thingUID Identificator of the {@link Thing} to be removed
* @return the {@link Thing} that was removed, or null if no {@link Thing} with the given {@link ThingUID} exists
*/
- Thing forceRemove(ThingUID thingUID);
+ @Nullable
+ Thing forceRemove(@NonNull ThingUID thingUID);
/**
* Creates a thing based on the given configuration properties
@@ -97,6 +101,6 @@ public interface ThingRegistry extends Registry {
* the configuration
* @return the created thing
*/
- Thing createThingOfType(ThingTypeUID thingTypeUID, ThingUID thingUIDObject, ThingUID bridgeUID, String label,
- Configuration configuration);
+ Thing createThingOfType(@NonNull ThingTypeUID thingTypeUID, ThingUID thingUIDObject, ThingUID bridgeUID,
+ String label, Configuration configuration);
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ThingStatusInfo.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ThingStatusInfo.java
index 8abfc050431..fe17f0c7c36 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ThingStatusInfo.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ThingStatusInfo.java
@@ -8,6 +8,7 @@
package org.eclipse.smarthome.core.thing;
import org.apache.commons.lang.StringUtils;
+import org.eclipse.jdt.annotation.NonNull;
/**
* A {@link ThingStatusInfo} represents status information of a thing which consists of
@@ -22,9 +23,9 @@
*/
public class ThingStatusInfo {
- private ThingStatus status;
+ private @NonNull ThingStatus status;
- private ThingStatusDetail statusDetail;
+ private @NonNull ThingStatusDetail statusDetail;
private String description;
@@ -32,6 +33,8 @@ public class ThingStatusInfo {
* Default constructor for deserialization e.g. by Gson.
*/
protected ThingStatusInfo() {
+ status = ThingStatus.UNKNOWN;
+ statusDetail = ThingStatusDetail.NONE;
}
/**
@@ -43,14 +46,8 @@ protected ThingStatusInfo() {
*
* @throws IllegalArgumentException if thing status or thing status detail is null
*/
- public ThingStatusInfo(ThingStatus status, ThingStatusDetail statusDetail, String description)
+ public ThingStatusInfo(@NonNull ThingStatus status, @NonNull ThingStatusDetail statusDetail, String description)
throws IllegalArgumentException {
- if (status == null) {
- throw new IllegalArgumentException("Thing status must not be null");
- }
- if (statusDetail == null) {
- throw new IllegalArgumentException("Thing status detail must not be null");
- }
this.status = status;
this.statusDetail = statusDetail;
this.description = description;
@@ -61,7 +58,7 @@ public ThingStatusInfo(ThingStatus status, ThingStatusDetail statusDetail, Strin
*
* @return the status (not null)
*/
- public ThingStatus getStatus() {
+ public @NonNull ThingStatus getStatus() {
return status;
}
@@ -70,7 +67,7 @@ public ThingStatus getStatus() {
*
* @return the status detail (not null)
*/
- public ThingStatusDetail getStatusDetail() {
+ public @NonNull ThingStatusDetail getStatusDetail() {
return statusDetail;
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ThingTypeMigrationService.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ThingTypeMigrationService.java
index b7d06fcf2db..deb2332fc21 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ThingTypeMigrationService.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ThingTypeMigrationService.java
@@ -7,25 +7,26 @@
*/
package org.eclipse.smarthome.core.thing;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.Configuration;
/**
* The {@link ThingTypeMigrationService} describes a service to change the thing type
* of a given {@link Thing}.
- *
+ *
* @author Andre Fuechsel - initial contribution
*/
public interface ThingTypeMigrationService {
/**
* Changes the type of a given {@link Thing}.
- *
+ *
* @param thing {@link Thing} whose type should be changed
* @param thingTypeUID new {@link ThingTypeUID}
* @param configuration new configuration
- *
+ *
* @throws RuntimeException, if the new thing type is not registered in the registry
*/
- void migrateThingType(Thing thing, ThingTypeUID thingTypeUID, Configuration configuration);
+ void migrateThingType(@NonNull Thing thing, @NonNull ThingTypeUID thingTypeUID, Configuration configuration);
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseBridgeHandler.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseBridgeHandler.java
index 7f6a6ff2b58..e6e681d6f39 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseBridgeHandler.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseBridgeHandler.java
@@ -9,6 +9,7 @@
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingUID;
@@ -29,7 +30,7 @@ public abstract class BaseBridgeHandler extends BaseThingHandler implements Brid
/**
* @see BaseThingHandler
*/
- public BaseBridgeHandler(Bridge bridge) {
+ public BaseBridgeHandler(@NonNull Bridge bridge) {
super(bridge);
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseThingHandler.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseThingHandler.java
index c53989b3e24..d4b2467315b 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseThingHandler.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseThingHandler.java
@@ -12,6 +12,7 @@
import java.util.Map.Entry;
import java.util.concurrent.ScheduledExecutorService;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.config.core.validation.ConfigDescriptionValidator;
import org.eclipse.smarthome.config.core.validation.ConfigValidationException;
@@ -41,8 +42,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Preconditions;
-
/**
* {@link BaseThingHandler} provides a base implementation for the {@link ThingHandler} interface.
*
@@ -71,7 +70,7 @@ public abstract class BaseThingHandler implements ThingHandler {
protected ItemChannelLinkRegistry linkRegistry;
protected BundleContext bundleContext;
- protected Thing thing;
+ protected @NonNull Thing thing;
@SuppressWarnings("rawtypes")
private ServiceTracker thingRegistryServiceTracker;
@@ -84,11 +83,8 @@ public abstract class BaseThingHandler implements ThingHandler {
* Creates a new instance of this class for the {@link Thing}.
*
* @param thing the thing that should be handled, not null
- *
- * @throws IllegalArgumentException if thing argument is null
*/
- public BaseThingHandler(Thing thing) {
- Preconditions.checkArgument(thing != null, "The argument 'thing' must not be null.");
+ public BaseThingHandler(@NonNull Thing thing) {
this.thing = thing;
}
@@ -168,7 +164,7 @@ public void dispose() {
}
@Override
- public Thing getThing() {
+ public @NonNull Thing getThing() {
return this.thing;
}
@@ -178,11 +174,12 @@ public void handleUpdate(ChannelUID channelUID, State newState) {
}
@Override
+ @Deprecated
public void initialize() {
- // can be overridden by subclasses
- // standard behavior is to set the thing to ONLINE,
- // assuming no further initialization is necessary.
+ // should be overridden by subclasses!
updateStatus(ThingStatus.ONLINE);
+ logger.warn(
+ "BaseThingHandler.initialize() will be removed soon, ThingStatus can be set manually via updateStatus(ThingStatus.ONLINE)");
}
@Override
@@ -297,7 +294,7 @@ protected void triggerChannel(ChannelUID channelUID, String event) {
if (this.callback != null) {
this.callback.channelTriggered(this.getThing(), channelUID, event);
} else {
- throw new IllegalStateException("Could not update state, because callback is missing");
+ throw new IllegalStateException("Could not trigger channel, because callback is missing");
}
}
}
@@ -438,7 +435,7 @@ protected ThingBuilder editThing() {
* @throws IllegalStateException
* if handler is not initialized correctly, because no callback is present
*/
- protected void updateThing(Thing thing) {
+ protected void updateThing(@NonNull Thing thing) {
synchronized (this) {
if (this.callback != null) {
this.thing = thing;
@@ -532,7 +529,7 @@ protected void updateProperties(Map properties) {
* @param name the name of the property to be set
* @param value the value of the property
*/
- protected void updateProperty(String name, String value) {
+ protected void updateProperty(@NonNull String name, String value) {
String existingPropertyValue = thing.getProperties().get(name);
if (existingPropertyValue == null || !existingPropertyValue.equals(value)) {
thing.setProperty(name, value);
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseThingHandlerFactory.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseThingHandlerFactory.java
index c536cd880b4..5ce91c62f85 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseThingHandlerFactory.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseThingHandlerFactory.java
@@ -10,6 +10,8 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.config.core.ConfigDescriptionRegistry;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.config.core.status.ConfigStatusProvider;
@@ -25,8 +27,6 @@
import org.osgi.service.component.ComponentContext;
import org.osgi.util.tracker.ServiceTracker;
-import com.google.common.base.Preconditions;
-
/**
* The {@link BaseThingHandlerFactory} provides a base implementation for the {@link ThingHandlerFactory} interface.
*
@@ -93,8 +93,6 @@ protected void deactivate(ComponentContext componentContext) {
@Override
public ThingHandler registerHandler(Thing thing) {
- Preconditions.checkArgument(thing != null, "The argument 'thing' must not be null.");
-
ThingHandler thingHandler = createHandler(thing);
if (thingHandler == null) {
throw new IllegalStateException(this.getClass().getSimpleName()
@@ -153,8 +151,6 @@ private ServiceRegistration registerAsService(ThingHandler thingHandler,
@Override
public void unregisterHandler(Thing thing) {
- Preconditions.checkArgument(thing != null, "The argument 'thing' must not be null.");
-
ThingHandler thingHandler = thing.getHandler();
if (thingHandler != null) {
removeHandler(thingHandler);
@@ -172,7 +168,7 @@ public void unregisterHandler(Thing thing) {
* @param thingHandler
* thing handler to be removed
*/
- protected void removeHandler(ThingHandler thingHandler) {
+ protected void removeHandler(@NonNull ThingHandler thingHandler) {
// can be overridden
}
@@ -209,7 +205,7 @@ public void removeThing(ThingUID thingUID) {
* @param thingTypeUID the unique id of the thing type
* @return the thing type represented by the given unique id
*/
- protected ThingType getThingTypeByUID(ThingTypeUID thingTypeUID) {
+ protected @Nullable ThingType getThingTypeByUID(@NonNull ThingTypeUID thingTypeUID) {
if (thingTypeRegistryServiceTracker == null) {
throw new IllegalStateException(
"Base thing handler factory has not been properly initialized. Did you forget to call super.activate()?");
@@ -226,13 +222,14 @@ protected ThingType getThingTypeByUID(ThingTypeUID thingTypeUID) {
*
* @param thingTypeUID
* thing type uid (can not be null)
- * @param thingUID
- * thingUID (can not be null)
* @param configuration
* (can not be null)
+ * @param thingUID
+ * thingUID (can not be null)
* @return thing (can be null, if thing type is unknown)
*/
- protected Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID) {
+ protected @Nullable Thing createThing(@NonNull ThingTypeUID thingTypeUID, @NonNull Configuration configuration,
+ @NonNull ThingUID thingUID) {
return createThing(thingTypeUID, configuration, thingUID, null);
}
@@ -252,9 +249,6 @@ protected Thing createThing(ThingTypeUID thingTypeUID, Configuration configurati
@Override
public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID,
ThingUID bridgeUID) {
- if (thingTypeUID == null) {
- throw new IllegalArgumentException("Thing Type UID must not be null");
- }
if (thingUID == null) {
thingUID = ThingFactory.generateRandomThingUID(thingTypeUID);
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BridgeHandler.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BridgeHandler.java
index fd3e3d809e2..fb65ef7d3ce 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BridgeHandler.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BridgeHandler.java
@@ -7,6 +7,7 @@
*/
package org.eclipse.smarthome.core.thing.binding;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.Thing;
@@ -28,7 +29,7 @@ public interface BridgeHandler extends ThingHandler {
* @param childHandler the initialized child handler
* @param childThing the thing of the initialized child handler
*/
- void childHandlerInitialized(ThingHandler childHandler, Thing childThing);
+ void childHandlerInitialized(@NonNull ThingHandler childHandler, @NonNull Thing childThing);
/**
* Informs the bridge handler that a child handler has been disposed.
@@ -36,6 +37,6 @@ public interface BridgeHandler extends ThingHandler {
* @param childHandler the disposed child handler
* @param childThing the thing of the disposed child handler
*/
- void childHandlerDisposed(ThingHandler childHandler, Thing childThing);
+ void childHandlerDisposed(@NonNull ThingHandler childHandler, @NonNull Thing childThing);
}
\ No newline at end of file
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ConfigStatusBridgeHandler.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ConfigStatusBridgeHandler.java
index 8dc22b4f3e4..0ebba009ac9 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ConfigStatusBridgeHandler.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ConfigStatusBridgeHandler.java
@@ -9,6 +9,7 @@
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.config.core.status.ConfigStatusCallback;
import org.eclipse.smarthome.config.core.status.ConfigStatusProvider;
@@ -37,7 +38,7 @@ public abstract class ConfigStatusBridgeHandler extends BaseBridgeHandler implem
*
* @param bridge the bridge for this handler
*/
- public ConfigStatusBridgeHandler(Bridge bridge) {
+ public ConfigStatusBridgeHandler(@NonNull Bridge bridge) {
super(bridge);
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ConfigStatusThingHandler.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ConfigStatusThingHandler.java
index cf603aca363..78dfad1cac0 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ConfigStatusThingHandler.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ConfigStatusThingHandler.java
@@ -9,6 +9,7 @@
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.config.core.status.ConfigStatusCallback;
import org.eclipse.smarthome.config.core.status.ConfigStatusProvider;
@@ -38,7 +39,7 @@ public abstract class ConfigStatusThingHandler extends BaseThingHandler implemen
*
* @param thing the thing for this handler
*/
- public ConfigStatusThingHandler(Thing thing) {
+ public ConfigStatusThingHandler(@NonNull Thing thing) {
super(thing);
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingConfigStatusSource.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingConfigStatusSource.java
index 86b231e2fe9..b867c6dd5b0 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingConfigStatusSource.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingConfigStatusSource.java
@@ -7,6 +7,7 @@
*/
package org.eclipse.smarthome.core.thing.binding;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.status.ConfigStatusSource;
import org.eclipse.smarthome.core.thing.Thing;
@@ -24,7 +25,7 @@ public final class ThingConfigStatusSource extends ConfigStatusSource {
*
* @param thingUID the UID of the thing
*/
- public ThingConfigStatusSource(String thingUID) {
+ public ThingConfigStatusSource(@NonNull String thingUID) {
super(thingUID);
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingFactory.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingFactory.java
index 96f14347daa..9154ab45b95 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingFactory.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingFactory.java
@@ -11,6 +11,7 @@
import java.util.Map;
import java.util.UUID;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.ConfigDescriptionRegistry;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.thing.Channel;
@@ -102,8 +103,9 @@ public static Thing createThing(ThingType thingType, ThingUID thingUID, Configur
.withProperties(thingType.getProperties()).withBridge(bridgeUID).build();
}
- public static Thing createThing(ThingUID thingUID, Configuration configuration, Map properties,
- ThingUID bridgeUID, ThingTypeUID thingTypeUID, List thingHandlerFactories) {
+ public static Thing createThing(ThingUID thingUID, Configuration configuration,
+ Map<@NonNull String, String> properties, ThingUID bridgeUID, ThingTypeUID thingTypeUID,
+ List thingHandlerFactories) {
for (ThingHandlerFactory thingHandlerFactory : thingHandlerFactories) {
if (thingHandlerFactory.supportsThingType(thingTypeUID)) {
Thing thing = thingHandlerFactory.createThing(thingTypeUID, configuration, thingUID, bridgeUID);
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandler.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandler.java
index 8baf8b62baf..b708ece253d 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandler.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandler.java
@@ -9,6 +9,7 @@
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.validation.ConfigValidationException;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
@@ -88,7 +89,7 @@ public interface ThingHandler {
* @param channelUID the {@link ChannelUID} of the channel to which the command was sent
* @param command the {@link Command}
*/
- void handleCommand(ChannelUID channelUID, Command command);
+ void handleCommand(@NonNull ChannelUID channelUID, Command command);
/**
* Handles a {@link State} update for a given channel.
@@ -99,7 +100,7 @@ public interface ThingHandler {
* @param channelUID the {@link ChannelUID} of the channel on which the update was performed
* @param newState the new {@link State}
*/
- void handleUpdate(ChannelUID channelUID, State newState);
+ void handleUpdate(@NonNull ChannelUID channelUID, @NonNull State newState);
/**
* Handles a configuration update.
@@ -122,7 +123,7 @@ public interface ThingHandler {
*
* @param thing the {@link Thing}, that has been updated
*/
- void thingUpdated(Thing thing);
+ void thingUpdated(@NonNull Thing thing);
/**
* Notifies the handler that a channel was linked.
@@ -132,7 +133,7 @@ public interface ThingHandler {
*
* @param channelUID UID of the linked channel
*/
- void channelLinked(ChannelUID channelUID);
+ void channelLinked(@NonNull ChannelUID channelUID);
/**
* Notifies the handler that a channel was unlinked.
@@ -142,7 +143,7 @@ public interface ThingHandler {
*
* @param channelUID UID of the unlinked channel
*/
- void channelUnlinked(ChannelUID channelUID);
+ void channelUnlinked(@NonNull ChannelUID channelUID);
/**
* Notifies the handler that the bridge's status has changed.
@@ -173,5 +174,4 @@ public interface ThingHandler {
* Only then it will be removed completely.
*/
void handleRemoval();
-
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandlerCallback.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandlerCallback.java
index c72638997b6..81553f3c592 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandlerCallback.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandlerCallback.java
@@ -7,6 +7,7 @@
*/
package org.eclipse.smarthome.core.thing.binding;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
@@ -31,7 +32,7 @@ public interface ThingHandlerCallback {
* @param channelUID channel UID (must not be null)
* @param state state (must not be null)
*/
- void stateUpdated(ChannelUID channelUID, State state);
+ void stateUpdated(@NonNull ChannelUID channelUID, @NonNull State state);
/**
* Informs about a command, which is sent from the channel.
@@ -39,7 +40,7 @@ public interface ThingHandlerCallback {
* @param channelUID channel UID
* @param command command
*/
- void postCommand(ChannelUID channelUID, Command command);
+ void postCommand(@NonNull ChannelUID channelUID, Command command);
/**
* Informs about an updated status of a thing.
@@ -47,7 +48,7 @@ public interface ThingHandlerCallback {
* @param thing thing (must not be null)
* @param thingStatus thing status (must not be null)
*/
- void statusUpdated(Thing thing, ThingStatusInfo thingStatus);
+ void statusUpdated(@NonNull Thing thing, @NonNull ThingStatusInfo thingStatus);
/**
* Informs about an update of the whole thing.
@@ -55,14 +56,14 @@ public interface ThingHandlerCallback {
* @param thing thing that was updated (must not be null)
* @throws IllegalStateException if the {@link Thing} is read-only.
*/
- void thingUpdated(Thing thing);
+ void thingUpdated(@NonNull Thing thing);
/**
* Informs about an updated configuration of a thing.
*
* @param thing thing with the updated configuration (must no be null)
*/
- void configurationUpdated(Thing thing);
+ void configurationUpdated(@NonNull Thing thing);
/**
* Informs the framework that the ThingType of the given {@link Thing} should be changed.
@@ -71,7 +72,7 @@ public interface ThingHandlerCallback {
* @param thingTypeUID the new type of the thing (must not be null)
* @param configuration a configuration that should be applied to the given {@link Thing}
*/
- void migrateThingType(Thing thing, ThingTypeUID thingTypeUID, Configuration configuration);
+ void migrateThingType(@NonNull Thing thing, @NonNull ThingTypeUID thingTypeUID, Configuration configuration);
/**
* Informs the framework that a channel has been triggered.
@@ -79,6 +80,6 @@ public interface ThingHandlerCallback {
* @param channelUID UID of the channel over which has been triggered.
* @param event Event.
*/
- void channelTriggered(Thing thing, ChannelUID channelUID, String event);
+ void channelTriggered(@NonNull Thing thing, @NonNull ChannelUID channelUID, String event);
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandlerFactory.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandlerFactory.java
index 3dd81f75e84..c2804c070bb 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandlerFactory.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandlerFactory.java
@@ -7,6 +7,7 @@
*/
package org.eclipse.smarthome.core.thing.binding;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.config.core.status.ConfigStatusProvider;
import org.eclipse.smarthome.core.thing.Thing;
@@ -29,7 +30,7 @@ public interface ThingHandlerFactory {
* @param thingTypeUID the thing type UID
* @return true, if the handler supports the thing type, false otherwise
*/
- boolean supportsThingType(ThingTypeUID thingTypeUID);
+ boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID);
/**
* Creates a new {@link ThingHandler} instance. In addition, the handler can be registered as a service if it is
@@ -46,7 +47,8 @@ public interface ThingHandlerFactory {
*
* @throws IllegalStateException if the handler instance could not be created
*/
- ThingHandler registerHandler(Thing thing);
+ @NonNull
+ ThingHandler registerHandler(@NonNull Thing thing);
/**
* Unregisters a {@link ThingHandler} instance.
@@ -56,7 +58,7 @@ public interface ThingHandlerFactory {
*
* @param thing the thing for which the handler must be unregistered
*/
- void unregisterHandler(Thing thing);
+ void unregisterHandler(@NonNull Thing thing);
/**
* Creates a thing for given arguments.
@@ -68,13 +70,14 @@ public interface ThingHandlerFactory {
*
* @return created thing
*/
- Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID, ThingUID bridgeUID);
+ Thing createThing(@NonNull ThingTypeUID thingTypeUID, @NonNull Configuration configuration, ThingUID thingUID,
+ ThingUID bridgeUID);
/**
* A thing with the given {@link Thing} UID was removed.
*
* @param thingUID thing UID of the removed object
*/
- void removeThing(ThingUID thingUID);
+ void removeThing(@NonNull ThingUID thingUID);
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingTypeProvider.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingTypeProvider.java
index a6c2f8d6d8b..33321a84871 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingTypeProvider.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingTypeProvider.java
@@ -10,6 +10,7 @@
import java.util.Collection;
import java.util.Locale;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.type.ThingType;
@@ -40,6 +41,7 @@ public interface ThingTypeProvider {
* @return thing type for the given UID or null if no type for the given
* UID exists
*/
+ @Nullable
ThingType getThingType(ThingTypeUID thingTypeUID, Locale locale);
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/BridgeBuilder.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/BridgeBuilder.java
index e353dcabca2..868d4f37ba6 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/BridgeBuilder.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/BridgeBuilder.java
@@ -11,6 +11,7 @@
import java.util.List;
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.Channel;
@@ -29,7 +30,7 @@
*/
public class BridgeBuilder extends ThingBuilder {
- private BridgeBuilder(BridgeImpl thing) {
+ private BridgeBuilder(@NonNull BridgeImpl thing) {
super(thing);
}
@@ -91,7 +92,7 @@ public BridgeBuilder withBridge(ThingUID bridgeUID) {
}
@Override
- public BridgeBuilder withProperties(Map properties) {
+ public BridgeBuilder withProperties(Map<@NonNull String, String> properties) {
return (BridgeBuilder) super.withProperties(properties);
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ChannelBuilder.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ChannelBuilder.java
index 05b41ee1c43..c1da2bb3a7f 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ChannelBuilder.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ChannelBuilder.java
@@ -10,6 +10,8 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.thing.Channel;
import org.eclipse.smarthome.core.thing.ChannelUID;
@@ -31,7 +33,7 @@ public class ChannelBuilder {
private ChannelKind kind;
private Configuration configuration;
private Set defaultTags;
- private Map properties;
+ private Map<@NonNull String, String> properties;
private String label;
private String description;
private ChannelTypeUID channelTypeUID;
@@ -52,7 +54,7 @@ private ChannelBuilder(ChannelUID channelUID, String acceptedItemType, Set());
}
@@ -62,7 +64,7 @@ public static ChannelBuilder create(ChannelUID channelUID, String acceptedItemTy
* @param channelTypeUID channel type UID
* @return channel builder
*/
- public ChannelBuilder withType(ChannelTypeUID channelTypeUID) {
+ public @NonNull ChannelBuilder withType(@NonNull ChannelTypeUID channelTypeUID) {
this.channelTypeUID = channelTypeUID;
return this;
}
@@ -74,7 +76,7 @@ public ChannelBuilder withType(ChannelTypeUID channelTypeUID) {
* configuration
* @return channel builder
*/
- public ChannelBuilder withConfiguration(Configuration configuration) {
+ public @NonNull ChannelBuilder withConfiguration(Configuration configuration) {
this.configuration = configuration;
return this;
}
@@ -85,7 +87,7 @@ public ChannelBuilder withConfiguration(Configuration configuration) {
* @param properties properties to add
* @return channel builder
*/
- public ChannelBuilder withProperties(Map properties) {
+ public @NonNull ChannelBuilder withProperties(Map<@NonNull String, String> properties) {
this.properties = properties;
return this;
}
@@ -96,7 +98,7 @@ public ChannelBuilder withProperties(Map properties) {
* @param label the channel label to override the label set in the {@link ChannelType}
* @return channel builder
*/
- public ChannelBuilder withLabel(String label) {
+ public @NonNull ChannelBuilder withLabel(String label) {
this.label = label;
return this;
}
@@ -107,7 +109,7 @@ public ChannelBuilder withLabel(String label) {
* @param label the channel label to override the label set in the {@link ChannelType}
* @return channel builder
*/
- public ChannelBuilder withDescription(String description) {
+ public @NonNull ChannelBuilder withDescription(String description) {
this.description = description;
return this;
}
@@ -119,7 +121,7 @@ public ChannelBuilder withDescription(String description) {
* default tags
* @return channel builder
*/
- public ChannelBuilder withDefaultTags(Set defaultTags) {
+ public @NonNull ChannelBuilder withDefaultTags(Set defaultTags) {
this.defaultTags = defaultTags;
return this;
}
@@ -130,7 +132,7 @@ public ChannelBuilder withDefaultTags(Set defaultTags) {
* @param kind kind.
* @return channel builder
*/
- public ChannelBuilder withKind(ChannelKind kind) {
+ public @NonNull ChannelBuilder withKind(ChannelKind kind) {
if (kind == null) {
throw new IllegalArgumentException("kind must not be null");
}
@@ -144,7 +146,7 @@ public ChannelBuilder withKind(ChannelKind kind) {
*
* @return channel
*/
- public Channel build() {
+ public @NonNull Channel build() {
return new Channel(channelUID, channelTypeUID, acceptedItemType, kind, configuration, defaultTags, properties,
label, description);
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ThingBuilder.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ThingBuilder.java
index c02eddd297a..5d79f3d7627 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ThingBuilder.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ThingBuilder.java
@@ -12,6 +12,7 @@
import java.util.List;
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.thing.Channel;
import org.eclipse.smarthome.core.thing.ChannelUID;
@@ -32,53 +33,53 @@
*/
public class ThingBuilder {
- private ThingImpl thing;
+ private @NonNull ThingImpl thing;
- protected ThingBuilder(ThingImpl thing) {
+ protected ThingBuilder(@NonNull ThingImpl thing) {
this.thing = thing;
}
- public static ThingBuilder create(ThingTypeUID thingTypeUID, String thingId) {
+ public static @NonNull ThingBuilder create(@NonNull ThingTypeUID thingTypeUID, @NonNull String thingId) {
ThingImpl thing = new ThingImpl(thingTypeUID, thingId);
return new ThingBuilder(thing);
}
@Deprecated
- public static ThingBuilder create(ThingUID thingUID) {
+ public static @NonNull ThingBuilder create(@NonNull ThingUID thingUID) {
ThingImpl thing = new ThingImpl(thingUID);
return new ThingBuilder(thing);
}
- public static ThingBuilder create(ThingTypeUID thingTypeUID, ThingUID thingUID) {
+ public static @NonNull ThingBuilder create(ThingTypeUID thingTypeUID, ThingUID thingUID) {
ThingImpl thing = new ThingImpl(thingTypeUID, thingUID);
return new ThingBuilder(thing);
}
- public ThingBuilder withLabel(String label) {
+ public @NonNull ThingBuilder withLabel(String label) {
this.thing.setLabel(label);
return this;
}
- public ThingBuilder withChannel(Channel channel) {
+ public @NonNull ThingBuilder withChannel(Channel channel) {
final Collection mutableThingChannels = this.thing.getChannelsMutable();
ThingHelper.ensureUniqueChannels(mutableThingChannels, channel);
mutableThingChannels.add(channel);
return this;
}
- public ThingBuilder withChannels(Channel... channels) {
+ public @NonNull ThingBuilder withChannels(Channel... channels) {
ThingHelper.ensureUniqueChannels(channels);
this.thing.setChannels(Lists.newArrayList(channels));
return this;
}
- public ThingBuilder withChannels(List channels) {
+ public @NonNull ThingBuilder withChannels(List channels) {
ThingHelper.ensureUniqueChannels(channels);
this.thing.setChannels(Lists.newArrayList(channels));
return this;
}
- public ThingBuilder withoutChannel(ChannelUID channelUID) {
+ public @NonNull ThingBuilder withoutChannel(ChannelUID channelUID) {
Iterator iterator = this.thing.getChannelsMutable().iterator();
while (iterator.hasNext()) {
if (iterator.next().getUID().equals(channelUID)) {
@@ -88,19 +89,19 @@ public ThingBuilder withoutChannel(ChannelUID channelUID) {
return this;
}
- public ThingBuilder withConfiguration(Configuration thingConfiguration) {
+ public @NonNull ThingBuilder withConfiguration(Configuration thingConfiguration) {
this.thing.setConfiguration(thingConfiguration);
return this;
}
- public ThingBuilder withBridge(ThingUID bridgeUID) {
+ public @NonNull ThingBuilder withBridge(ThingUID bridgeUID) {
if (bridgeUID != null) {
this.thing.setBridgeUID(bridgeUID);
}
return this;
}
- public ThingBuilder withProperties(Map properties) {
+ public @NonNull ThingBuilder withProperties(Map<@NonNull String, String> properties) {
if (properties != null) {
for (String key : properties.keySet()) {
this.thing.setProperty(key, properties.get(key));
@@ -109,12 +110,12 @@ public ThingBuilder withProperties(Map properties) {
return this;
}
- public ThingBuilder withLocation(String location) {
+ public @NonNull ThingBuilder withLocation(String location) {
this.thing.setLocation(location);
return this;
}
- public Thing build() {
+ public @NonNull Thing build() {
return this.thing;
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ThingStatusInfoBuilder.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ThingStatusInfoBuilder.java
index 605dd685de1..905b4eb6dbe 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ThingStatusInfoBuilder.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ThingStatusInfoBuilder.java
@@ -7,13 +7,14 @@
*/
package org.eclipse.smarthome.core.thing.binding.builder;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.ThingStatusDetail;
import org.eclipse.smarthome.core.thing.ThingStatusInfo;
/**
* {@link ThingStatusInfoBuilder} is responsible for creating {@link ThingStatusInfo}s.
- *
+ *
* @author Stefan Bußweiler - Initial contribution
* @author Dennis Nobel - Added null checks
*/
@@ -33,59 +34,51 @@ private ThingStatusInfoBuilder(ThingStatus status, ThingStatusDetail statusDetai
/**
* Creates a status info builder for the given status and detail.
- *
+ *
* @param status the status (must not be null)
* @param statusDetail the detail of the status (must not be null)
* @return status info builder
- *
+ *
* @throws IllegalArgumentException if thing status or thing status detail is null
*/
- public static ThingStatusInfoBuilder create(ThingStatus status, ThingStatusDetail statusDetail)
- throws IllegalArgumentException {
- if (status == null) {
- throw new IllegalArgumentException("Thing status must not be null");
- }
- if (statusDetail == null) {
- throw new IllegalArgumentException("Thing status detail must not be null");
- }
+ public static @NonNull ThingStatusInfoBuilder create(@NonNull ThingStatus status,
+ @NonNull ThingStatusDetail statusDetail) throws IllegalArgumentException {
return new ThingStatusInfoBuilder(status, statusDetail, null);
}
/**
* Creates a status info builder for the given status.
- *
+ *
* @param status the status (must not be null)
* @return status info builder
- *
+ *
* @throws IllegalArgumentException if thing status is null
*/
- public static ThingStatusInfoBuilder create(ThingStatus status) throws IllegalArgumentException {
+ public static @NonNull ThingStatusInfoBuilder create(@NonNull ThingStatus status) throws IllegalArgumentException {
return create(status, ThingStatusDetail.NONE);
}
/**
* Appends a description to the status to build.
- *
+ *
* @param description the description
* @return status info builder
*/
- public ThingStatusInfoBuilder withDescription(String description) throws IllegalArgumentException {
+ public @NonNull ThingStatusInfoBuilder withDescription(String description) throws IllegalArgumentException {
this.description = description;
return this;
}
/**
* Appends a status detail to the status to build.
- *
+ *
* @param statusDetail the status detail (must not be null)
* @return status info builder
- *
+ *
* @throws IllegalArgumentException if thing status detail is null
*/
- public ThingStatusInfoBuilder withStatusDetail(ThingStatusDetail statusDetail) throws IllegalArgumentException {
- if (statusDetail == null) {
- throw new IllegalArgumentException("Thing status detail must not be null");
- }
+ public @NonNull ThingStatusInfoBuilder withStatusDetail(@NonNull ThingStatusDetail statusDetail)
+ throws IllegalArgumentException {
this.statusDetail = statusDetail;
return this;
}
@@ -95,7 +88,7 @@ public ThingStatusInfoBuilder withStatusDetail(ThingStatusDetail statusDetail) t
*
* @return status info
*/
- public ThingStatusInfo build() {
+ public @NonNull ThingStatusInfo build() {
return new ThingStatusInfo(status, statusDetail, description);
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/firmware/Firmware.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/firmware/Firmware.java
index 123c72703fa..2d16e38dfcb 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/firmware/Firmware.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/firmware/Firmware.java
@@ -34,17 +34,17 @@
* firmware relates always to exactly one {@link ThingType}. By its {@link FirmwareUID} it is ensured that there is only
* one firmware in a specific version for a thing type available. Firmwares can be easily created by the
* {@link Firmware.Builder}.
- *
+ *
*
* Firmwares are made available to the system by {@link FirmwareProvider}s that are tracked by the
* {@link FirmwareRegistry}. The registry can be used to get a dedicated firmware or to get all available firmwares for
* a specific {@link ThingType}.
- *
+ *
*
* The {@link FirmwareUpdateService} is responsible to provide the current {@link FirmwareStatusInfo} of a thing.
* Furthermore this service is the central instance to start a firmware update process. In order that the firmware of a
* thing can be updated the hander of the thing has to implement the {@link FirmwareUpdateHandler} interface.
- *
+ *
*
* The {@link Firmware} implements the {@link Comparable} interface in order to be able to sort firmwares based on their
* versions. Firmwares are sorted in a descending sequence, i.e. that the latest firmware will be the first
@@ -54,7 +54,7 @@
* 1-9_9.9_abc. Consequently 2.0-0, 2-0_0 and 2_0.0 represent the same firmware version.
* Furthermore firmware version xyz_1 is newer than firmware version abc.2 which again is newer than
* firmware version 2-0-1.
- *
+ *
*
* A {@link Firmware} consists of various meta information like a version, a vendor or a description. Additionally
* {@link FirmwareProvider}s can specify further meta information in form of properties (e.g. a factory reset of the
@@ -215,7 +215,7 @@ public synchronized byte[] getBytes() {
try (DigestInputStream dis = new DigestInputStream(inputStream, md)) {
bytes = IOUtils.toByteArray(dis);
} catch (IOException ioEx) {
- logger.error(String.format("Cannot read firmware with UID %s.", uid), ioEx);
+ logger.error("Cannot read firmware with UID {}.", uid, ioEx);
return null;
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/dto/ThingDTOMapper.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/dto/ThingDTOMapper.java
index 1a5abca5ee5..fc0d432f45b 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/dto/ThingDTOMapper.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/dto/ThingDTOMapper.java
@@ -43,6 +43,7 @@ public static ThingDTO map(Thing thing) {
String thingTypeUID = thing.getThingTypeUID().getAsString();
String thingUID = thing.getUID().toString();
+ @SuppressWarnings("null") // thing.getBridgeUID() is checked against null before use
String bridgeUID = thing.getBridgeUID() != null ? thing.getBridgeUID().toString() : null;
return new ThingDTO(thingTypeUID, thingUID, thing.getLabel(), bridgeUID, channelDTOs,
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/events/ChannelTriggeredEvent.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/events/ChannelTriggeredEvent.java
index c1609e42ef5..cc88ed40a07 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/events/ChannelTriggeredEvent.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/events/ChannelTriggeredEvent.java
@@ -9,11 +9,12 @@
import org.eclipse.smarthome.core.events.AbstractEvent;
import org.eclipse.smarthome.core.thing.ChannelUID;
-import org.eclipse.smarthome.core.types.Type;
/**
* {@link ChannelTriggeredEvent}s can be used to deliver triggers through the Eclipse SmartHome event bus.
* Trigger events must be created with the {@link ThingEventFactory}.
+ *
+ * @author Moritz Kammerer - Initial contribution
*/
public class ChannelTriggeredEvent extends AbstractEvent {
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/firmware/FirmwareRegistry.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/firmware/FirmwareRegistry.java
index ce5ccf7463f..825a171af41 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/firmware/FirmwareRegistry.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/firmware/FirmwareRegistry.java
@@ -80,9 +80,9 @@ public Firmware getFirmware(FirmwareUID firmwareUID, Locale locale) {
return firmware;
}
} catch (Exception e) {
- logger.warn(String.format(
- "Unexpected exception occurred for firmware provider %s while getting firmware for firmware UID %s.",
- firmwareProvider.getClass().getSimpleName(), firmwareUID), e);
+ logger.warn(
+ "Unexpected exception occurred for firmware provider {} while getting firmware for firmware UID {}.",
+ firmwareProvider.getClass().getSimpleName(), firmwareUID, e);
}
}
@@ -156,9 +156,9 @@ public Collection getFirmwares(ThingTypeUID thingTypeUID, Locale local
firmwares.addAll(result);
}
} catch (Exception e) {
- logger.warn(String.format(
- "Unexpected exception occurred for firmware provider %s while getting firmwares for thing type UID %s.",
- firmwareProvider.getClass().getSimpleName(), thingTypeUID), e);
+ logger.warn(
+ "Unexpected exception occurred for firmware provider {} while getting firmwares for thing type UID {}.",
+ firmwareProvider.getClass().getSimpleName(), thingTypeUID, e);
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/firmware/FirmwareUpdateService.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/firmware/FirmwareUpdateService.java
index 6b5ead03ad6..441a0516580 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/firmware/FirmwareUpdateService.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/firmware/FirmwareUpdateService.java
@@ -7,10 +7,7 @@
*/
package org.eclipse.smarthome.core.thing.firmware;
-import static org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo.createUnknownInfo;
-import static org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo.createUpToDateInfo;
-import static org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo.createUpdateAvailableInfo;
-import static org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo.createUpdateExecutableInfo;
+import static org.eclipse.smarthome.core.thing.firmware.FirmwareStatusInfo.*;
import java.net.URI;
import java.net.URISyntaxException;
@@ -34,8 +31,8 @@
import org.eclipse.smarthome.core.events.EventFilter;
import org.eclipse.smarthome.core.events.EventPublisher;
import org.eclipse.smarthome.core.events.EventSubscriber;
-import org.eclipse.smarthome.core.i18n.TranslationProvider;
import org.eclipse.smarthome.core.i18n.LocaleProvider;
+import org.eclipse.smarthome.core.i18n.TranslationProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.ThingUID;
@@ -233,14 +230,13 @@ public Void call() {
}
}, timeout);
} catch (ExecutionException e) {
- logger.error(String.format(
- "Unexpected exception occurred for firmware update of thing with UID %s and firmware with UID %s.",
- thingUID, firmwareUID), e.getCause());
+ logger.error(
+ "Unexpected exception occurred for firmware update of thing with UID {} and firmware with UID {}.",
+ thingUID, firmwareUID, e.getCause());
progressCallback.failedInternal("unexpected-handler-error");
} catch (TimeoutException e) {
- logger.error(String.format(
- "Timeout occurred for firmware update of thing with UID %s and firmware with UID %s.",
- thingUID, firmwareUID), e);
+ logger.error("Timeout occurred for firmware update of thing with UID {} and firmware with UID {}.",
+ thingUID, firmwareUID, e);
progressCallback.failedInternal("timeout-error");
}
}
@@ -250,7 +246,7 @@ public Void call() {
/**
* Cancels the firmware update of the thing having the given thing UID by invoking the operation
* {@link FirmwareUpdateHandler#cancel()} of the thing´s firmware update handler.
- *
+ *
* @param thingUID the thing UID (must not be null)
*/
public void cancelFirmwareUpdate(final ThingUID thingUID) {
@@ -274,13 +270,11 @@ public Void call() {
}
});
} catch (ExecutionException e) {
- logger.error(String.format(
- "Unexpected exception occurred while canceling firmware update of thing with UID %s.",
- thingUID), e.getCause());
+ logger.error("Unexpected exception occurred while canceling firmware update of thing with UID {}.",
+ thingUID, e.getCause());
progressCallback.failedInternal("unexpected-handler-error-during-cancel");
} catch (TimeoutException e) {
- logger.error(String.format("Timeout occurred while canceling firmware update of thing with UID %s.",
- thingUID), e);
+ logger.error("Timeout occurred while canceling firmware update of thing with UID {}.", thingUID, e);
progressCallback.failedInternal("timeout-error-during-cancel");
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/i18n/ThingTypeI18nLocalizationService.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/i18n/ThingTypeI18nLocalizationService.java
index 0207ebd8e31..8c7dcfa1a57 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/i18n/ThingTypeI18nLocalizationService.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/i18n/ThingTypeI18nLocalizationService.java
@@ -15,7 +15,9 @@
import org.eclipse.smarthome.core.thing.type.BridgeType;
import org.eclipse.smarthome.core.thing.type.ChannelDefinition;
import org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition;
+import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ThingType;
+import org.eclipse.smarthome.core.thing.type.TypeResolver;
import org.osgi.framework.Bundle;
/**
@@ -23,6 +25,7 @@
* framework.
*
* @author Markus Rathgeb - Move code from XML thing type provider to separate service
+ * @author Laurent Garnier - fix localized label and description for channel group definition
*/
public class ThingTypeI18nLocalizationService {
@@ -57,10 +60,17 @@ public ThingType createLocalizedThingType(Bundle bundle, ThingType thingType, Lo
final List localizedChannelGroupDefinitions = new ArrayList<>(
thingType.getChannelGroupDefinitions().size());
for (final ChannelGroupDefinition channelGroupDefinition : thingType.getChannelGroupDefinitions()) {
- final String channelGroupLabel = this.thingTypeI18nUtil.getChannelGroupLabel(bundle,
- channelGroupDefinition.getTypeUID(), channelGroupDefinition.getLabel(), locale);
- final String channelGroupDescription = this.thingTypeI18nUtil.getChannelGroupDescription(bundle,
- channelGroupDefinition.getTypeUID(), channelGroupDefinition.getDescription(), locale);
+ ChannelGroupType channelGroupType = TypeResolver.resolve(channelGroupDefinition.getTypeUID(), locale);
+ final String channelGroupLabel = channelGroupDefinition.getLabel() == null
+ ? this.thingTypeI18nUtil.getChannelGroupLabel(bundle, channelGroupType.getUID(),
+ channelGroupType.getLabel(), locale)
+ : this.thingTypeI18nUtil.getChannelGroupLabel(bundle, thingType.getUID(),
+ channelGroupDefinition.getId(), channelGroupDefinition.getLabel(), locale);
+ final String channelGroupDescription = channelGroupDefinition.getDescription() == null
+ ? this.thingTypeI18nUtil.getChannelGroupDescription(bundle, channelGroupType.getUID(),
+ channelGroupType.getDescription(), locale)
+ : this.thingTypeI18nUtil.getChannelGroupDescription(bundle, thingType.getUID(),
+ channelGroupDefinition.getId(), channelGroupDefinition.getDescription(), locale);
localizedChannelGroupDefinitions.add(new ChannelGroupDefinition(channelGroupDefinition.getId(),
channelGroupDefinition.getTypeUID(), channelGroupLabel, channelGroupDescription));
}
@@ -68,12 +78,12 @@ public ThingType createLocalizedThingType(Bundle bundle, ThingType thingType, Lo
if (thingType instanceof BridgeType) {
final BridgeType bridgeType = (BridgeType) thingType;
return new BridgeType(bridgeType.getUID(), bridgeType.getSupportedBridgeTypeUIDs(), label, description,
- thingType.isListed(), localizedChannelDefinitions, localizedChannelGroupDefinitions,
- thingType.getProperties(), bridgeType.getConfigDescriptionURI());
+ thingType.isListed(), thingType.getRepresentationProperty(), localizedChannelDefinitions,
+ localizedChannelGroupDefinitions, thingType.getProperties(), bridgeType.getConfigDescriptionURI());
} else {
return new ThingType(thingType.getUID(), thingType.getSupportedBridgeTypeUIDs(), label, description,
- thingType.isListed(), localizedChannelDefinitions, localizedChannelGroupDefinitions,
- thingType.getProperties(), thingType.getConfigDescriptionURI());
+ thingType.isListed(), thingType.getRepresentationProperty(), localizedChannelDefinitions,
+ localizedChannelGroupDefinitions, thingType.getProperties(), thingType.getConfigDescriptionURI());
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/i18n/ThingTypeI18nUtil.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/i18n/ThingTypeI18nUtil.java
index 3e1f9c8742c..54a072c5de5 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/i18n/ThingTypeI18nUtil.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/i18n/ThingTypeI18nUtil.java
@@ -9,8 +9,8 @@
import java.util.Locale;
-import org.eclipse.smarthome.core.i18n.TranslationProvider;
import org.eclipse.smarthome.core.i18n.I18nUtil;
+import org.eclipse.smarthome.core.i18n.TranslationProvider;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelTypeUID;
@@ -22,6 +22,7 @@
* not a constant.
*
* @author Dennis Nobel - Initial contribution
+ * @author Laurent Garnier - add translation for channel group label and channel group description
*/
public class ThingTypeI18nUtil {
@@ -45,16 +46,30 @@ public String getChannelGroupDescription(Bundle bundle, ChannelGroupTypeUID chan
return i18nProvider.getText(bundle, key, defaultDescription, locale);
}
+ public String getChannelGroupDescription(Bundle bundle, ThingTypeUID thingTypeUID, String channelGroupId,
+ String defaultDescription, Locale locale) {
+ String key = I18nUtil.isConstant(defaultDescription) ? I18nUtil.stripConstant(defaultDescription)
+ : inferThingTypeKey(thingTypeUID, channelGroupId, "description");
+ return i18nProvider.getText(bundle, key, defaultDescription, locale);
+ }
+
+ public String getChannelLabel(Bundle bundle, ChannelTypeUID channelTypeUID, String defaultLabel, Locale locale) {
+ String key = I18nUtil.isConstant(defaultLabel) ? I18nUtil.stripConstant(defaultLabel)
+ : inferChannelKey(channelTypeUID, "label");
+ return i18nProvider.getText(bundle, key, defaultLabel, locale);
+ }
+
public String getChannelGroupLabel(Bundle bundle, ChannelGroupTypeUID channelGroupTypeUID, String defaultLabel,
Locale locale) {
- String key = I18nUtil.isConstant(defaultLabel) ? I18nUtil.stripConstant(defaultLabel) : inferChannelKey(
- channelGroupTypeUID, "label");
+ String key = I18nUtil.isConstant(defaultLabel) ? I18nUtil.stripConstant(defaultLabel)
+ : inferChannelKey(channelGroupTypeUID, "label");
return i18nProvider.getText(bundle, key, defaultLabel, locale);
}
- public String getChannelLabel(Bundle bundle, ChannelTypeUID channelTypeUID, String defaultLabel, Locale locale) {
- String key = I18nUtil.isConstant(defaultLabel) ? I18nUtil.stripConstant(defaultLabel) : inferChannelKey(
- channelTypeUID, "label");
+ public String getChannelGroupLabel(Bundle bundle, ThingTypeUID thingTypeUID, String channelGroupId,
+ String defaultLabel, Locale locale) {
+ String key = I18nUtil.isConstant(defaultLabel) ? I18nUtil.stripConstant(defaultLabel)
+ : inferThingTypeKey(thingTypeUID, channelGroupId, "label");
return i18nProvider.getText(bundle, key, defaultLabel, locale);
}
@@ -67,8 +82,8 @@ public String getChannelStateOption(Bundle bundle, ChannelTypeUID channelTypeUID
public String getChannelStatePattern(Bundle bundle, ChannelTypeUID channelTypeUID, String defaultPattern,
Locale locale) {
- String key = I18nUtil.isConstant(defaultPattern) ? I18nUtil.stripConstant(defaultPattern) : inferChannelKey(
- channelTypeUID, "state.pattern");
+ String key = I18nUtil.isConstant(defaultPattern) ? I18nUtil.stripConstant(defaultPattern)
+ : inferChannelKey(channelTypeUID, "state.pattern");
return i18nProvider.getText(bundle, key, defaultPattern, locale);
}
@@ -79,8 +94,8 @@ public String getDescription(Bundle bundle, ThingTypeUID thingTypeUID, String de
}
public String getLabel(Bundle bundle, ThingTypeUID thingTypeUID, String defaultLabel, Locale locale) {
- String key = I18nUtil.isConstant(defaultLabel) ? I18nUtil.stripConstant(defaultLabel) : inferThingTypeKey(
- thingTypeUID, "label");
+ String key = I18nUtil.isConstant(defaultLabel) ? I18nUtil.stripConstant(defaultLabel)
+ : inferThingTypeKey(thingTypeUID, "label");
return i18nProvider.getText(bundle, key, defaultLabel, locale);
}
@@ -97,4 +112,9 @@ private String inferThingTypeKey(ThingTypeUID thingTypeUID, String lastSegment)
return "thing-type." + thingTypeUID.getBindingId() + "." + thingTypeUID.getId() + "." + lastSegment;
}
+ private String inferThingTypeKey(ThingTypeUID thingTypeUID, String channelGroupId, String lastSegment) {
+ return "thing-type." + thingTypeUID.getBindingId() + "." + thingTypeUID.getId() + ".group." + channelGroupId
+ + "." + lastSegment;
+ }
+
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/Activator.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/Activator.java
index 429a9e05eb6..c19db1f432f 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/Activator.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/Activator.java
@@ -15,6 +15,10 @@
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+/**
+ *
+ * @author Denis Nobel - Initial contribution
+ */
public class Activator implements BundleActivator {
public static class ChannelTypeRegistryBinder {
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/BridgeImpl.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/BridgeImpl.java
index b721b9d6a5b..b730ec1aa76 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/BridgeImpl.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/BridgeImpl.java
@@ -21,6 +21,10 @@
import com.google.common.collect.ImmutableList;
+/**
+ *
+ * @author Denis Nobel - Initial contribution
+ */
public class BridgeImpl extends ThingImpl implements Bridge {
private transient List things = new CopyOnWriteArrayList<>();
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingFactoryHelper.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingFactoryHelper.java
index 23aeaafdb49..7b0a1da80d0 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingFactoryHelper.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingFactoryHelper.java
@@ -10,6 +10,7 @@
import java.math.BigDecimal;
import java.net.URI;
import java.util.List;
+
import org.eclipse.smarthome.config.core.ConfigDescription;
import org.eclipse.smarthome.config.core.ConfigDescriptionParameter;
import org.eclipse.smarthome.config.core.ConfigDescriptionParameter.Type;
@@ -28,6 +29,7 @@
import org.eclipse.smarthome.core.thing.type.TypeResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import com.google.common.collect.Lists;
/**
@@ -41,7 +43,7 @@
*/
public class ThingFactoryHelper {
- private static Logger logger = LoggerFactory.getLogger(ThingFactory.class);
+ private static Logger logger = LoggerFactory.getLogger(ThingFactoryHelper.class);
/**
* Create {@link Channel} instances for the given Thing.
@@ -157,8 +159,8 @@ public static Object getDefaultValueAsCorrectType(Type parameterType, String def
return null;
}
} catch (NumberFormatException ex) {
- LoggerFactory.getLogger(ThingFactory.class).warn("Could not parse default value '" + defaultValue
- + "' as type '" + parameterType + "': " + ex.getMessage(), ex);
+ LoggerFactory.getLogger(ThingFactory.class).warn("Could not parse default value '{}' as type '{}': {}",
+ defaultValue, parameterType, ex.getMessage(), ex);
return null;
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingManager.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingManager.java
index d6a7637ffb5..a8af488a6fd 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingManager.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingManager.java
@@ -307,8 +307,13 @@ public void run() {
// Register the new Handler - ThingManager.updateThing() is going to take care of that
thingRegistry.update(thing);
+ ThingHandler handler = thing.getHandler();
+ String handlerString = "NO HANDLER";
+ if (handler != null) {
+ handlerString = handler.toString();
+ }
logger.debug("Changed ThingType of Thing {} to {}. New ThingHandler is {}.",
- thing.getUID().toString(), thing.getThingTypeUID(), thing.getHandler().toString());
+ thing.getUID().toString(), thing.getThingTypeUID(), handlerString);
} finally {
lock.unlock();
}
@@ -385,9 +390,8 @@ public Void call() throws Exception {
logger.error("Exception occurred while calling handler: {}", ex.getMessage(), ex);
}
} else {
- logger.debug(
- "Not delegating command '{}' for item '{}' to handler for channel '{}', "
- + "because handler is not initialized (thing must be in status UNKNOWN, ONLINE or OFFLINE).",
+ logger.debug("Not delegating command '{}' for item '{}' to handler for channel '{}', "
+ + "because handler is not initialized (thing must be in status UNKNOWN, ONLINE or OFFLINE).",
command, itemName, channelUID);
}
} else {
@@ -424,7 +428,12 @@ protected void receiveUpdate(ItemStateEvent updateEvent) {
SafeMethodCaller.call(new SafeMethodCaller.ActionWithException() {
@Override
public Void call() throws Exception {
- handler.handleUpdate(channelUID, newState);
+ if (newState != null) {
+ handler.handleUpdate(channelUID, newState);
+ } else {
+ throw new IllegalStateException(
+ "Trying to set state to null on channel " + channelUID);
+ }
return null;
}
});
@@ -435,9 +444,8 @@ public Void call() throws Exception {
logger.error("Exception occurred while calling handler: {}", ex.getMessage(), ex);
}
} else {
- logger.debug(
- "Not delegating update '{}' for item '{}' to handler for channel '{}', "
- + "because handler is not initialized (thing must be in status UNKNOWN, ONLINE or OFFLINE).",
+ logger.debug("Not delegating update '{}' for item '{}' to handler for channel '{}', "
+ + "because handler is not initialized (thing must be in status UNKNOWN, ONLINE or OFFLINE).",
newState, itemName, channelUID);
}
} else {
@@ -544,7 +552,7 @@ public Void call() throws Exception {
registerAndInitializeHandler(thing, getThingHandlerFactory(thing));
}
- if (oldThing != thing) {
+ if (oldThing != thing && oldThing != null) {
oldThing.setHandler(null);
}
} finally {
@@ -653,9 +661,14 @@ private void initializeHandler(Thing thing) {
thing.getUID());
return;
}
- if (thing.getHandler().getThing() != thing) {
- logger.debug("The model of {} is inconsistent [thing.getHandler().getThing() != thing]",
- thing.getUID());
+ ThingHandler handler = thing.getHandler();
+ if (handler == null) {
+ throw new IllegalStateException("Handler should not be null here");
+ } else {
+ if (handler.getThing() != thing) {
+ logger.debug("The model of {} is inconsistent [thing.getHandler().getThing() != thing]",
+ thing.getUID());
+ }
}
ThingType thingType = getThingType(thing);
applyDefaultConfiguration(thing, thingType);
@@ -708,7 +721,8 @@ private ConfigDescription resolve(URI configDescriptionURI, Locale locale) {
}
return configDescriptionRegistry != null
- ? configDescriptionRegistry.getConfigDescription(configDescriptionURI, locale) : null;
+ ? configDescriptionRegistry.getConfigDescription(configDescriptionURI, locale)
+ : null;
}
private List getRequiredParameters(ConfigDescription description) {
@@ -787,7 +801,9 @@ private void doUnregisterHandler(final Thing thing, final ThingHandlerFactory th
public Void call() throws Exception {
ThingHandler thingHandler = thing.getHandler();
thingHandlerFactory.unregisterHandler(thing);
- thingHandler.setCallback(null);
+ if (thingHandler != null) {
+ thingHandler.setCallback(null);
+ }
thing.setHandler(null);
setThingStatus(thing,
buildStatusInfo(ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_MISSING_ERROR));
@@ -899,7 +915,10 @@ public void run() {
try {
BridgeHandler bridgeHandler = bridge.getHandler();
if (bridgeHandler != null) {
- bridgeHandler.childHandlerInitialized(thing.getHandler(), thing);
+ ThingHandler thingHandler = thing.getHandler();
+ if (thingHandler != null) {
+ bridgeHandler.childHandlerInitialized(thingHandler, thing);
+ }
}
} catch (Exception e) {
logger.error(
@@ -1135,7 +1154,7 @@ private void setThingStatus(Thing thing, ThingStatusInfo thingStatusInfo) {
ThingEventFactory.createStatusInfoChangedEvent(thing.getUID(), newStatusInfo, oldStatusInfo));
}
} catch (Exception ex) {
- logger.error("Could not post 'ThingStatusInfoEvent' event: " + ex.getMessage(), ex);
+ logger.error("Could not post 'ThingStatusInfoEvent' event: {}", ex.getMessage(), ex);
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingRegistryImpl.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingRegistryImpl.java
index b58a9ab04ff..99d19f5237a 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingRegistryImpl.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingRegistryImpl.java
@@ -13,6 +13,7 @@
import java.util.Map.Entry;
import java.util.concurrent.CopyOnWriteArrayList;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.common.registry.AbstractRegistry;
import org.eclipse.smarthome.core.common.registry.Provider;
@@ -62,18 +63,6 @@ public void addThingTracker(ThingTracker thingTracker) {
thingTrackers.add(thingTracker);
}
- @Override
- public Thing get(final ThingUID uid) {
- for (final Map.Entry, Collection> entry : elementMap.entrySet()) {
- for (final Thing thing : entry.getValue()) {
- if (uid.equals(thing.getUID())) {
- return thing;
- }
- }
- }
- return null;
- }
-
@Override
public Channel getChannel(ChannelUID channelUID) {
ThingUID thingUID = channelUID.getThingUID();
@@ -85,7 +74,7 @@ public Channel getChannel(ChannelUID channelUID) {
}
@Override
- public void updateConfiguration(ThingUID thingUID, Map configurationParameters) {
+ public void updateConfiguration(ThingUID thingUID, Map<@NonNull String, Object> configurationParameters) {
Thing thing = get(thingUID);
if (thing != null) {
ThingHandler thingHandler = thing.getHandler();
@@ -224,8 +213,8 @@ private void notifyTrackers(Thing thing, ThingTrackerEvent event) {
break;
}
} catch (Exception ex) {
- logger.error("Could not inform the ThingTracker '" + thingTracker + "' about the '" + event.name()
- + "' event!", ex);
+ logger.error("Could not inform the ThingTracker '{}' about the '{}' event!", thingTracker, event.name(),
+ ex);
}
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/AbstractLinkRegistry.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/AbstractLinkRegistry.java
index 29a9ceeb7e2..73663fbacd1 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/AbstractLinkRegistry.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/AbstractLinkRegistry.java
@@ -7,9 +7,7 @@
*/
package org.eclipse.smarthome.core.thing.link;
-import java.util.Collection;
import java.util.LinkedHashSet;
-import java.util.Map;
import java.util.Set;
import org.eclipse.smarthome.core.common.registry.AbstractRegistry;
@@ -85,16 +83,4 @@ public Set getLinks(UID uid) {
return links;
}
- @Override
- public L get(final String key) {
- for (final Map.Entry, Collection> entry : elementMap.entrySet()) {
- for (final L link : entry.getValue()) {
- if (key.equals(link.getUID())) {
- return link;
- }
- }
- }
- return null;
- }
-
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/ManagedItemChannelLinkProvider.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/ManagedItemChannelLinkProvider.java
index 9ba6b42e1fc..555d8716346 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/ManagedItemChannelLinkProvider.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/ManagedItemChannelLinkProvider.java
@@ -19,8 +19,8 @@
* @author Dennis Nobel - Initial contribution
*
*/
-public class ManagedItemChannelLinkProvider extends DefaultAbstractManagedProvider implements
- ItemChannelLinkProvider {
+public class ManagedItemChannelLinkProvider extends DefaultAbstractManagedProvider
+ implements ItemChannelLinkProvider {
@Override
protected String getStorageName() {
@@ -32,11 +32,6 @@ protected String keyToString(String key) {
return key;
}
- @Override
- protected String getKey(ItemChannelLink element) {
- return element.getUID();
- }
-
public void removeLinksForThing(ThingUID thingUID) {
Collection itemChannelLinks = getAll();
for (ItemChannelLink itemChannelLink : itemChannelLinks) {
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/ManagedItemThingLinkProvider.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/ManagedItemThingLinkProvider.java
index 43e274130df..cfb920e3b64 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/ManagedItemThingLinkProvider.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/ManagedItemThingLinkProvider.java
@@ -16,13 +16,8 @@
* @author Dennis Nobel - Initial contribution
*
*/
-public class ManagedItemThingLinkProvider extends DefaultAbstractManagedProvider implements
- ItemThingLinkProvider {
-
- @Override
- protected String getKey(ItemThingLink element) {
- return element.getUID();
- }
+public class ManagedItemThingLinkProvider extends DefaultAbstractManagedProvider
+ implements ItemThingLinkProvider {
@Override
protected String getStorageName() {
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/ThingLinkManager.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/ThingLinkManager.java
index 06308e6422d..078dc4f8428 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/ThingLinkManager.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/link/ThingLinkManager.java
@@ -263,7 +263,7 @@ private void informHandlerAboutLinkedChannel(Thing thing, Channel channel) {
try {
handler.channelLinked(channel.getUID());
} catch (Exception ex) {
- logger.error("Exception occurred while informing handler:" + ex.getMessage(), ex);
+ logger.error("Exception occurred while informing handler: {}", ex.getMessage(), ex);
}
} else {
logger.trace("Can not inform handler about linked channel, because no handler is assigned to the thing {}.",
@@ -282,7 +282,7 @@ private void informHandlerAboutUnlinkedChannel(Thing thing, Channel channel) {
try {
handler.channelUnlinked(channel.getUID());
} catch (Exception ex) {
- logger.error("Exception occurred while informing handler:" + ex.getMessage(), ex);
+ logger.error("Exception occurred while informing handler: {}", ex.getMessage(), ex);
}
} else {
logger.trace(
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/type/BridgeType.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/type/BridgeType.java
index f9ccacbd801..f87a4f12ab5 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/type/BridgeType.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/type/BridgeType.java
@@ -24,6 +24,7 @@
*
* @author Michael Grammling - Initial Contribution
* @author Thomas Höfer - Added thing and thing type properties
+ * @author Andre Fuechsel - Added representationProperty
*/
public class BridgeType extends ThingType {
@@ -32,7 +33,7 @@ public class BridgeType extends ThingType {
*/
public BridgeType(String bindingId, String thingTypeId, String label) throws IllegalArgumentException {
- this(new ThingTypeUID(bindingId, thingTypeId), null, label, null, true, null, null, null, null);
+ this(new ThingTypeUID(bindingId, thingTypeId), null, label, null, true, null, null, null, null, null);
}
/**
@@ -66,7 +67,7 @@ public BridgeType(ThingTypeUID uid, List supportedBridgeTypeUIDs, String
List channelDefinitions, List channelGroupDefinitions,
Map properties, URI configDescriptionURI) throws IllegalArgumentException {
- this(uid, supportedBridgeTypeUIDs, label, description, true, channelDefinitions, channelGroupDefinitions,
+ this(uid, supportedBridgeTypeUIDs, label, description, true, null, channelDefinitions, channelGroupDefinitions,
properties, configDescriptionURI);
}
@@ -85,13 +86,13 @@ public BridgeType(ThingTypeUID uid, List supportedBridgeTypeUIDs, String
* @param description the human readable description for the according type
* (could be null or empty)
*
- * @param listed detemines whether it should be displayed for manually pairing or not
+ * @param listed determines whether it should be displayed for manually pairing or not
*
* @param channelDefinitions the channels this Bridge type provides (could be null or empty)
*
* @param channelGroupDefinitions the channel groups defining the channels this Bridge
* type provides (could be null or empty)
- *
+ *
* @param properties the properties this Bridge type provides (could be null)
*
* @param configDescriptionURI the link to the concrete ConfigDescription (could be null)
@@ -104,8 +105,48 @@ public BridgeType(ThingTypeUID uid, List supportedBridgeTypeUIDs, String
List channelGroupDefinitions, Map properties,
URI configDescriptionURI) throws IllegalArgumentException {
- super(uid, supportedBridgeTypeUIDs, label, description, listed, channelDefinitions, channelGroupDefinitions,
- properties, configDescriptionURI);
+ this(uid, supportedBridgeTypeUIDs, label, description, listed, null, channelDefinitions,
+ channelGroupDefinitions, properties, configDescriptionURI);
+ }
+
+ /**
+ * Creates a new instance of this class with the specified parameters.
+ *
+ * @param uid the unique identifier which identifies this Bridge type within
+ * the overall system (must neither be null, nor empty)
+ *
+ * @param supportedBridgeTypeUIDs the unique identifiers to the bridges this Bridge type
+ * supports (could be null or empty)
+ *
+ * @param label the human readable label for the according type
+ * (must neither be null nor empty)
+ *
+ * @param description the human readable description for the according type
+ * (could be null or empty)
+ *
+ * @param listed determines whether it should be displayed for manually pairing or not
+ *
+ * @param representationProperty name of the property that uniquely identifies this Thing
+ *
+ * @param channelDefinitions the channels this Bridge type provides (could be null or empty)
+ *
+ * @param channelGroupDefinitions the channel groups defining the channels this Bridge
+ * type provides (could be null or empty)
+ *
+ * @param properties the properties this Bridge type provides (could be null)
+ *
+ * @param configDescriptionURI the link to the concrete ConfigDescription (could be null)
+ *
+ * @throws IllegalArgumentException if the UID is null or empty,
+ * or the the meta information is null
+ */
+ public BridgeType(ThingTypeUID uid, List supportedBridgeTypeUIDs, String label, String description,
+ boolean listed, String representationProperty, List channelDefinitions,
+ List channelGroupDefinitions, Map properties,
+ URI configDescriptionURI) throws IllegalArgumentException {
+
+ super(uid, supportedBridgeTypeUIDs, label, description, listed, representationProperty, channelDefinitions,
+ channelGroupDefinitions, properties, configDescriptionURI);
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/type/ChannelGroupType.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/type/ChannelGroupType.java
index 6a1fa78cae8..6b69680b1e6 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/type/ChannelGroupType.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/type/ChannelGroupType.java
@@ -24,8 +24,11 @@ public class ChannelGroupType extends AbstractDescriptionType {
private final boolean advanced;
private final List channelDefinitions;
+ private final String category;
/**
+ * Deprecated: Will be removed before 1.0 release in favor for constructor with category
+ *
* Creates a new instance of this class with the specified parameters.
*
* @param uid the unique identifier which identifies this channel group type within the
@@ -44,12 +47,50 @@ public class ChannelGroupType extends AbstractDescriptionType {
*
* @throws IllegalArgumentException if the UID is null, or the label is null or empty
*/
+ @Deprecated
public ChannelGroupType(ChannelGroupTypeUID uid, boolean advanced, String label, String description,
List channelDefinitions) throws IllegalArgumentException {
super(uid, label, description);
this.advanced = advanced;
+ this.category = null;
+
+ if (channelDefinitions != null) {
+ this.channelDefinitions = Collections.unmodifiableList(channelDefinitions);
+ } else {
+ this.channelDefinitions = Collections.unmodifiableList(new ArrayList(0));
+ }
+ }
+
+ /**
+ * Creates a new instance of this class with the specified parameters.
+ *
+ * @param uid the unique identifier which identifies this channel group type within the
+ * overall system (must neither be null, nor empty)
+ *
+ * @param advanced true if this channel group type contains advanced features, otherwise false
+ *
+ * @param label the human readable label for the according type
+ * (must neither be null nor empty)
+ *
+ * @param description the human readable description for the according type
+ * (could be null or empty)
+ *
+ * @param category the category of this channel group type, e.g. Temperature (could be null or empty)
+ *
+ * @param channelDefinitions the channel definitions this channel group forms
+ * (could be null or empty)
+ *
+ * @throws IllegalArgumentException if the UID is null, or the label is null or empty
+ */
+ public ChannelGroupType(ChannelGroupTypeUID uid, boolean advanced, String label, String description,
+ String category, List channelDefinitions) throws IllegalArgumentException {
+
+ super(uid, label, description);
+
+ this.advanced = advanced;
+ this.category = category;
if (channelDefinitions != null) {
this.channelDefinitions = Collections.unmodifiableList(channelDefinitions);
@@ -62,7 +103,7 @@ public ChannelGroupType(ChannelGroupTypeUID uid, boolean advanced, String label,
* Returns {@code true} if this {@link ChannelGroupType} contains advanced functionalities
* which should be typically not shown in the basic view of user interfaces,
* otherwise {@code false}.
- *
+ *
* @return true if this channel group contains advanced functionalities, otherwise false
*/
public boolean isAdvanced() {
@@ -80,6 +121,10 @@ public List getChannelDefinitions() {
return channelDefinitions;
}
+ public String getCategory() {
+ return this.category;
+ }
+
@Override
public ChannelGroupTypeUID getUID() {
return (ChannelGroupTypeUID) super.getUID();
diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/type/ThingType.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/type/ThingType.java
index a9fe52fb8d4..68ade675328 100644
--- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/type/ThingType.java
+++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/type/ThingType.java
@@ -14,6 +14,8 @@
import java.util.List;
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.config.core.ConfigDescription;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
@@ -30,21 +32,23 @@
* @author Dennis Nobel - Initial Contribution
* @author Thomas Höfer - Added thing and thing type properties
* @author Simon Kaufmann - Added listed field
+ * @author Andre Fuechsel - Added representationProperty field
*/
public class ThingType extends AbstractDescriptionType {
private final List channelGroupDefinitions;
private final List channelDefinitions;
private final List supportedBridgeTypeUIDs;
- private final Map properties;
- private URI configDescriptionURI;
- private boolean listed;
+ private final Map<@NonNull String, String> properties;
+ private final String representationProperty;
+ private final URI configDescriptionURI;
+ private final boolean listed;
/**
* @see ThingType#ThingType(ThingTypeUID, List, String, String, List, List, Map, URI)
*/
public ThingType(String bindingId, String thingTypeId, String label) throws IllegalArgumentException {
- this(new ThingTypeUID(bindingId, thingTypeId), null, label, null, true, null, null, null, null);
+ this(new ThingTypeUID(bindingId, thingTypeId), null, label, null, true, null, null, null, null, null);
}
/**
@@ -77,7 +81,7 @@ public ThingType(String bindingId, String thingTypeId, String label) throws Ille
public ThingType(ThingTypeUID uid, List supportedBridgeTypeUIDs, String label, String description,
List channelDefinitions, List channelGroupDefinitions,
Map properties, URI configDescriptionURI) throws IllegalArgumentException {
- this(uid, supportedBridgeTypeUIDs, label, description, true, channelDefinitions, channelGroupDefinitions,
+ this(uid, supportedBridgeTypeUIDs, label, description, true, null, channelDefinitions, channelGroupDefinitions,
properties, configDescriptionURI);
}
@@ -94,9 +98,9 @@ public ThingType(ThingTypeUID uid, List supportedBridgeTypeUIDs, String
* (must neither be null nor empty)
*
* @param description the human readable description for the according type
- * (could be null or empty)6
+ * (could be null or empty)
*
- * @param listed detemines whether it should be listed for manually pairing or not
+ * @param listed determines whether it should be listed for manually pairing or not
*
* @param channelDefinitions the channels this Thing type provides (could be null or empty)
*
@@ -114,11 +118,52 @@ public ThingType(ThingTypeUID uid, List supportedBridgeTypeUIDs, String
boolean listed, List channelDefinitions,
List channelGroupDefinitions, Map properties,
URI configDescriptionURI) throws IllegalArgumentException {
+ this(uid, supportedBridgeTypeUIDs, label, description, listed, null, channelDefinitions,
+ channelGroupDefinitions, properties, configDescriptionURI);
+ }
+
+ /**
+ * Creates a new instance of this class with the specified parameters.
+ *
+ * @param uid the unique identifier which identifies this Thing type within the overall system
+ * (must neither be null, nor empty)
+ *
+ * @param supportedBridgeTypeUIDs the unique identifiers of the bridges this Thing type supports
+ * (could be null or empty)
+ *
+ * @param label the human readable label for the according type
+ * (must neither be null nor empty)
+ *
+ * @param description the human readable description for the according type
+ * (could be null or empty)
+ *
+ * @param listed determines whether it should be listed for manually pairing or not
+ *
+ * @param representationProperty name of the property that uniquely identifies this Thing
+ *
+ * @param channelDefinitions the channels this Thing type provides (could be null or empty)
+ *
+ * @param channelGroupDefinitions the channel groups defining the channels this Thing type
+ * provides (could be null or empty)
+ *
+ * @param properties the properties this Thing type provides (could be null)
+ *
+ * @param configDescriptionURI the link to the concrete ConfigDescription (could be null)
+ *
+ * @throws IllegalArgumentException
+ * if the UID is null or empty, or the the meta information is null
+ */
+ public ThingType(ThingTypeUID uid, List supportedBridgeTypeUIDs, String label, String description,
+ boolean listed, String representationProperty, List channelDefinitions,
+ List channelGroupDefinitions, Map properties,
+ URI configDescriptionURI) throws IllegalArgumentException {
super(uid, label, description);
this.listed = listed;
+ this.representationProperty = representationProperty;
+
if (supportedBridgeTypeUIDs != null) {
this.supportedBridgeTypeUIDs = Collections.unmodifiableList(supportedBridgeTypeUIDs);
} else {
@@ -215,7 +260,7 @@ public URI getConfigDescriptionURI() {
*
* @return the properties for this {@link ThingType} (not null)
*/
- public Map getProperties() {
+ public @NonNull Map<@NonNull String, String> getProperties() {
return properties;
}
@@ -251,10 +296,24 @@ public ChannelTypeUID getChannelTypeUID(ChannelUID channelUID) {
return null;
}
+ /**
+ * Check, if things of this thing type should be listed for manually pairing or not.
+ *
+ * @return {@code true}, if manual pairing is allowed
+ */
public boolean isListed() {
return listed;
}
+ /**
+ * Get the name of the representation property of this thing type. May be {code null}.
+ *
+ * @return representation property name or {@code null}
+ */
+ public @Nullable String getRepresentationProperty() {
+ return representationProperty;
+ }
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
diff --git a/bundles/core/org.eclipse.smarthome.core.transform/src/main/java/org/eclipse/smarthome/core/transform/TransformationHelper.java b/bundles/core/org.eclipse.smarthome.core.transform/src/main/java/org/eclipse/smarthome/core/transform/TransformationHelper.java
index e3fc125147e..d2119dc174e 100644
--- a/bundles/core/org.eclipse.smarthome.core.transform/src/main/java/org/eclipse/smarthome/core/transform/TransformationHelper.java
+++ b/bundles/core/org.eclipse.smarthome.core.transform/src/main/java/org/eclipse/smarthome/core/transform/TransformationHelper.java
@@ -17,6 +17,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ *
+ * @author Kai Kreuzer - Initial contribution
+ */
public class TransformationHelper {
private final static Logger logger = LoggerFactory.getLogger(TransformationHelper.class);
@@ -26,19 +30,18 @@ public class TransformationHelper {
/**
* determines whether a pattern refers to a transformation service
- *
+ *
* @param pattern the pattern to check
* @return true, if the pattern contains a transformation
*/
static public boolean isTransform(String pattern) {
- return EXTRACT_TRANSFORMFUNCTION_PATTERN.matcher(pattern).matches();
+ return EXTRACT_TRANSFORMFUNCTION_PATTERN.matcher(pattern).matches();
}
-
/**
* Queries the OSGi service registry for a service that provides a transformation service of
* a given transformation type (e.g. REGEX, XSLT, etc.)
- *
+ *
* @param transformationType the desired transformation type
* @return a service instance or null, if none could be found
*/
@@ -47,15 +50,17 @@ static public TransformationService getTransformationService(BundleContext conte
Logger logger = LoggerFactory.getLogger(TransformationHelper.class);
String filter = "(smarthome.transform=" + transformationType + ")";
try {
- Collection> refs = context.getServiceReferences(
- TransformationService.class, filter);
+ Collection> refs = context
+ .getServiceReferences(TransformationService.class, filter);
if (refs != null && refs.size() > 0) {
return context.getService(refs.iterator().next());
} else {
- logger.warn("Cannot get service reference for transformation service of type " + transformationType);
+ logger.warn("Cannot get service reference for transformation service of type {}",
+ transformationType);
}
} catch (InvalidSyntaxException e) {
- logger.warn("Cannot get service reference for transformation service of type " + transformationType, e);
+ logger.warn("Cannot get service reference for transformation service of type {}", transformationType,
+ e);
}
}
return null;
@@ -63,7 +68,7 @@ static public TransformationService getTransformationService(BundleContext conte
/**
* Transforms a state string using transformation functions within a given pattern.
- *
+ *
* @param context a valid bundle context, required for accessing the services
* @param stateDescPattern the pattern that contains the transformation instructions
* @param state the state to be formatted before being passed into the transformation function
@@ -77,23 +82,22 @@ public static String transform(BundleContext context, String stateDescPattern, S
String value = matcher.group(3);
TransformationService transformation = TransformationHelper.getTransformationService(context, type);
if (transformation != null) {
- value = String.format(value, state);
+ value = String.format(value, state);
try {
pattern = transformation.transform(pattern, value);
} catch (TransformationException e) {
- logger.warn("transformation throws exception [transformation=" + transformation + ", value="
- + value + "]", e);
+ logger.warn("transformation throws exception [transformation={}, value={}]", transformation, value,
+ e);
pattern = state;
}
} else {
- logger.warn(
- "couldn't transform value because transformationService of type '{}' is unavailable",
+ logger.warn("couldn't transform value because transformationService of type '{}' is unavailable",
type);
pattern = state;
}
return pattern;
} else {
- return state;
+ return state;
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core.transform/src/main/java/org/eclipse/smarthome/core/transform/actions/Transformation.java b/bundles/core/org.eclipse.smarthome.core.transform/src/main/java/org/eclipse/smarthome/core/transform/actions/Transformation.java
index 31815cb268d..66ba190c71b 100644
--- a/bundles/core/org.eclipse.smarthome.core.transform/src/main/java/org/eclipse/smarthome/core/transform/actions/Transformation.java
+++ b/bundles/core/org.eclipse.smarthome.core.transform/src/main/java/org/eclipse/smarthome/core/transform/actions/Transformation.java
@@ -25,7 +25,7 @@ public class Transformation {
/**
* Applies a transformation of a given type with some function to a value.
- *
+ *
* @param type the transformation type, e.g. REGEX or MAP
* @param function the function to call, this value depends on the transformation type
* @param value the value to apply the transformation to
@@ -35,18 +35,18 @@ public class Transformation {
*/
public static String transform(String type, String function, String value) {
String result;
- TransformationService service = TransformationHelper.getTransformationService(
- TransformationActivator.getContext(), type);
+ TransformationService service = TransformationHelper
+ .getTransformationService(TransformationActivator.getContext(), type);
Logger logger = LoggerFactory.getLogger(Transformation.class);
if (service != null) {
try {
result = service.transform(function, value);
} catch (TransformationException e) {
- logger.error("Error executing the transformation '" + type + "': " + e.getMessage());
+ logger.error("Error executing the transformation '{}': {}", type, e.getMessage());
result = value;
}
} else {
- logger.warn("No transformation service '" + type + "' could be found.");
+ logger.warn("No transformation service '{}' could be found.", type);
result = value;
}
return result;
diff --git a/bundles/core/org.eclipse.smarthome.core.voice/META-INF/MANIFEST.MF b/bundles/core/org.eclipse.smarthome.core.voice/META-INF/MANIFEST.MF
index 6149032ece8..2c3b39e9479 100644
--- a/bundles/core/org.eclipse.smarthome.core.voice/META-INF/MANIFEST.MF
+++ b/bundles/core/org.eclipse.smarthome.core.voice/META-INF/MANIFEST.MF
@@ -18,6 +18,8 @@ Import-Package: org.apache.commons.collections.map,
org.eclipse.smarthome.core.items.events,
org.eclipse.smarthome.core.library.types,
org.eclipse.smarthome.core.types,
+ org.eclipse.smarthome.core.voice,
+ org.eclipse.smarthome.core.voice.text,
org.eclipse.smarthome.io.console,
org.eclipse.smarthome.io.console.extensions,
org.osgi.framework,
diff --git a/bundles/core/org.eclipse.smarthome.core/ESH-INF/config/networkinterface.xml b/bundles/core/org.eclipse.smarthome.core/ESH-INF/config/networkinterface.xml
new file mode 100644
index 00000000000..f82fe5c61bd
--- /dev/null
+++ b/bundles/core/org.eclipse.smarthome.core/ESH-INF/config/networkinterface.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+ A subnet (e.g. 192.168.1.0/24)
+ true
+
+
+
+
diff --git a/bundles/core/org.eclipse.smarthome.core/META-INF/MANIFEST.MF b/bundles/core/org.eclipse.smarthome.core/META-INF/MANIFEST.MF
index 472baeaea7b..1a088d990aa 100644
--- a/bundles/core/org.eclipse.smarthome.core/META-INF/MANIFEST.MF
+++ b/bundles/core/org.eclipse.smarthome.core/META-INF/MANIFEST.MF
@@ -28,7 +28,7 @@ Ignore-Package: org.eclipse.smarthome.core.internal.items,org.eclipse.smarthome.
nal,org.eclipse.smarthome.core.internal.events,org.eclipse.smarthome.core.internal.loggin
g
Bundle-Name: Eclipse SmartHome Core
-Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 0.9.0.qualifier
Bundle-ManifestVersion: 2
@@ -38,12 +38,16 @@ Import-Package: com.google.common.base,
com.google.gson,
org.apache.commons.io,
org.apache.commons.lang,
+ org.eclipse.jdt.annotation;resolution:=optional,
+ org.eclipse.smarthome.core.auth,
org.eclipse.smarthome.core.binding,
org.eclipse.smarthome.core.binding.dto,
+ org.eclipse.smarthome.core.cache,
org.eclipse.smarthome.core.common,
org.eclipse.smarthome.core.common.osgi,
org.eclipse.smarthome.core.common.registry,
org.eclipse.smarthome.core.events,
+ org.eclipse.smarthome.core.extension,
org.eclipse.smarthome.core.i18n,
org.eclipse.smarthome.core.items,
org.eclipse.smarthome.core.items.dto,
@@ -51,6 +55,8 @@ Import-Package: com.google.common.base,
org.eclipse.smarthome.core.library,
org.eclipse.smarthome.core.library.items,
org.eclipse.smarthome.core.library.types,
+ org.eclipse.smarthome.core.net,
+ org.eclipse.smarthome.core.scheduler,
org.eclipse.smarthome.core.service,
org.eclipse.smarthome.core.storage,
org.eclipse.smarthome.core.types,
diff --git a/bundles/core/org.eclipse.smarthome.core/OSGI-INF/.gitignore b/bundles/core/org.eclipse.smarthome.core/OSGI-INF/.gitignore
new file mode 100644
index 00000000000..422f92361c5
--- /dev/null
+++ b/bundles/core/org.eclipse.smarthome.core/OSGI-INF/.gitignore
@@ -0,0 +1 @@
+/org.eclipse.smarthome.network.xml
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/SafeMethodCaller.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/SafeMethodCaller.java
index d927fe36090..147dcb678be 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/SafeMethodCaller.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/SafeMethodCaller.java
@@ -119,14 +119,14 @@ public static V call(Action action, int timeout) {
String className = stackTraceElement.getClassName();
String methodName = stackTraceElement.getMethodName();
- getLogger().error("Exception occurred while calling '" + methodName + "' at '" + className + "'", ex);
+ getLogger().error("Exception occurred while calling '{}' at '{}'", methodName, className, ex);
} else {
getLogger().error("Exception occurred while calling action", ex);
}
return null;
} catch (TimeoutException ex) {
getLogger().error(
- "Timeout occurred while calling method. Execution took longer than " + timeout + " milliseconds.",
+ "Timeout occurred while calling method. Execution took longer than {} milliseconds.", timeout,
ex);
return null;
} catch (Throwable throwable) {
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/osgi/ResourceBundleClassLoader.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/osgi/ResourceBundleClassLoader.java
index 73bb7a27a30..7e818bf3a58 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/osgi/ResourceBundleClassLoader.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/osgi/ResourceBundleClassLoader.java
@@ -15,7 +15,7 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
@@ -31,11 +31,10 @@
*
* @author Michael Grammling - Initial Contribution
* @author Martin Herbst - UTF-8 replaced by ISO-8859-1 to follow Java standards
+ *
*/
public class ResourceBundleClassLoader extends ClassLoader {
- private static final Charset SUPPORTED_CHARSET = Charset.forName("ISO-8859-1");
-
private Bundle bundle;
private String path;
private String filePattern;
@@ -115,7 +114,7 @@ public InputStream getResourceAsStream(String name) {
if (resourceURL != null) {
try (InputStream resourceStream = resourceURL.openStream()) {
if (resourceStream != null) {
- try (Reader resourceReader = new InputStreamReader(resourceStream, SUPPORTED_CHARSET)) {
+ try (Reader resourceReader = new InputStreamReader(resourceStream, StandardCharsets.ISO_8859_1)) {
Properties props = new Properties();
props.load(resourceReader);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/osgi/ServiceBinder.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/osgi/ServiceBinder.java
index 110dad45f71..efc15359c29 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/osgi/ServiceBinder.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/osgi/ServiceBinder.java
@@ -195,7 +195,7 @@ private void injectService(Method method, Object object, Object service) {
method.invoke(object);
}
} catch (Exception ex) {
- logger.error("Error while executing inject method: " + ex.getMessage(), ex);
+ logger.error("Error while executing inject method: {}", ex.getMessage(), ex);
}
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractManagedProvider.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractManagedProvider.java
index 83614f11241..64072d9cba6 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractManagedProvider.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractManagedProvider.java
@@ -9,6 +9,7 @@
import java.util.Collection;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.storage.Storage;
import org.eclipse.smarthome.core.storage.StorageService;
import org.slf4j.Logger;
@@ -46,11 +47,6 @@ public abstract class AbstractManagedProvider, K, PE>
@Override
public void add(E element) {
-
- if (element == null) {
- throw new IllegalArgumentException("Cannot add null element");
- }
-
String keyAsString = getKeyAsString(element);
if (storage.get(keyAsString) != null) {
throw new IllegalArgumentException(
@@ -67,9 +63,13 @@ public Collection getAll() {
final Function toElementList = new Function() {
@Override
public E apply(String elementKey) {
- PE persistableElement = storage.get(elementKey);
- if (persistableElement != null) {
- return toElement(elementKey, persistableElement);
+ if (elementKey != null) {
+ PE persistableElement = storage.get(elementKey);
+ if (persistableElement != null) {
+ return toElement(elementKey, persistableElement);
+ } else {
+ return null;
+ }
} else {
return null;
}
@@ -101,11 +101,6 @@ public E get(K key) {
@Override
public E remove(K key) {
-
- if (key == null) {
- throw new IllegalArgumentException("Cannot remove null element");
- }
-
String keyAsString = keyToString(key);
PE persistableElement = storage.remove(keyAsString);
if (persistableElement != null) {
@@ -122,11 +117,6 @@ public E remove(K key) {
@Override
public E update(E element) {
-
- if (element == null) {
- throw new IllegalArgumentException("Cannot update null element");
- }
-
String key = getKeyAsString(element);
if (storage.get(key) != null) {
PE persistableElement = storage.put(key, toPersistableElement(element));
@@ -142,19 +132,10 @@ public E update(E element) {
return null;
}
- private String getKeyAsString(E element) {
- return keyToString(getKey(element));
+ private @NonNull String getKeyAsString(@NonNull E element) {
+ return keyToString(element.getUID());
}
- /**
- * Returns the key for a given element
- *
- * @param element
- * element
- * @return key (must not be null)
- */
- protected abstract K getKey(E element);
-
/**
* Returns the name of storage, that is used to persist the elements.
*
@@ -169,7 +150,7 @@ private String getKeyAsString(E element) {
* key
* @return string representation of the key
*/
- protected abstract String keyToString(K key);
+ protected abstract @NonNull String keyToString(@NonNull K key);
protected void setStorageService(StorageService storageService) {
this.storage = storageService.getStorage(getStorageName(), this.getClass().getClassLoader());
@@ -183,7 +164,7 @@ protected void setStorageService(StorageService storageService) {
* persistable element
* @return original element
*/
- protected abstract E toElement(String key, PE persistableElement);
+ protected abstract E toElement(@NonNull String key, @NonNull PE persistableElement);
/**
* Converts the original element into an element that can be persisted.
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractProvider.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractProvider.java
index f35fce1da02..0a4bc9f67bc 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractProvider.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractProvider.java
@@ -60,8 +60,7 @@ private void notifyListeners(E oldElement, E element, EventType eventType) {
break;
}
} catch (Exception ex) {
- logger.error("Could not inform the listener '" + listener + "' about the '" + eventType.name()
- + "' event!: " + ex.getMessage(), ex);
+ logger.error("Could not inform the listener '{}' about the '{}' event!: {}", listener, eventType.name(), ex.getMessage(), ex);
}
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractRegistry.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractRegistry.java
index 614dffb1ec7..1ca204fbc6b 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractRegistry.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractRegistry.java
@@ -14,6 +14,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.events.Event;
import org.eclipse.smarthome.core.events.EventPublisher;
import org.osgi.framework.BundleContext;
@@ -29,6 +30,7 @@
* @author Dennis Nobel - Initial contribution
* @author Stefan Bußweiler - Migration to new event mechanism
* @author Victor Toni - provide elements as {@link Stream}
+ * @author Kai Kreuzer - switched to parameterized logging
*
* @param
* type of the element
@@ -118,11 +120,17 @@ public void added(Provider provider, E element) {
Collection elements = elementMap.get(provider);
if (elements != null) {
try {
+ K uid = element.getUID();
+ if (uid != null && get(uid) != null) {
+ logger.warn("{} with key '{}' already exists! Failed to add a second with the same UID!",
+ element.getClass().getName(), uid);
+ return;
+ }
onAddElement(element);
elements.add(element);
notifyListenersAboutAddedElement(element);
} catch (Exception ex) {
- logger.warn("Could not add element: " + ex.getMessage(), ex);
+ logger.warn("Could not add element: {}", ex.getMessage(), ex);
}
}
}
@@ -132,8 +140,9 @@ public void addRegistryChangeListener(RegistryChangeListener listener) {
listeners.add(listener);
}
+ @SuppressWarnings("null")
@Override
- public Collection getAll() {
+ public Collection<@NonNull E> getAll() {
return stream().collect(Collectors.toList());
}
@@ -153,7 +162,7 @@ public void removed(Provider provider, E element) {
elements.remove(element);
notifyListenersAboutRemovedElement(element);
} catch (Exception ex) {
- logger.warn("Could not remove element: " + ex.getMessage(), ex);
+ logger.warn("Could not remove element: {}", ex.getMessage(), ex);
}
}
}
@@ -166,16 +175,28 @@ public void removeRegistryChangeListener(RegistryChangeListener listener) {
@Override
public void updated(Provider provider, E oldElement, E element) {
Collection elements = elementMap.get(provider);
- if (elements != null) {
+ if (elements != null && elements.contains(oldElement) && oldElement.getUID().equals(element.getUID())) {
try {
onUpdateElement(oldElement, element);
elements.remove(oldElement);
elements.add(element);
notifyListenersAboutUpdatedElement(oldElement, element);
} catch (Exception ex) {
- logger.warn("Could not update element: " + ex.getMessage(), ex);
+ logger.warn("Could not update element: {}", ex.getMessage(), ex);
+ }
+ }
+ }
+
+ @Override
+ public E get(K key) {
+ for (final Map.Entry, Collection> entry : elementMap.entrySet()) {
+ for (final E element : entry.getValue()) {
+ if (key.equals(element.getUID())) {
+ return element;
+ }
}
}
+ return null;
}
@Override
@@ -223,8 +244,8 @@ protected void notifyListeners(E oldElement, E element, EventType eventType) {
break;
}
} catch (Throwable throwable) {
- logger.error("Could not inform the listener '" + listener + "' about the '" + eventType.name()
- + "' event!: " + throwable.getMessage(), throwable);
+ logger.error("Could not inform the listener '{}' about the '{}' event: {}", listener, eventType.name(),
+ throwable.getMessage(), throwable);
}
}
}
@@ -254,11 +275,17 @@ protected void addProvider(Provider provider) {
elementMap.put(provider, elements);
for (E element : elementsOfProvider) {
try {
+ K uid = element.getUID();
+ if (uid != null && get(uid) != null) {
+ logger.warn("{} with key'{}' already exists! Failed to add a second with the same UID!",
+ element.getClass().getName(), uid);
+ continue;
+ }
onAddElement(element);
elements.add(element);
notifyListenersAboutAddedElement(element);
} catch (Exception ex) {
- logger.warn("Could not add element: " + ex.getMessage(), ex);
+ logger.warn("Could not add element: {}", ex.getMessage(), ex);
}
}
logger.debug("Provider '{}' has been added.", provider.getClass().getName());
@@ -327,7 +354,7 @@ protected void removeProvider(Provider provider) {
onRemoveElement(element);
notifyListenersAboutRemovedElement(element);
} catch (Exception ex) {
- logger.warn("Could not remove element: " + ex.getMessage(), ex);
+ logger.warn("Could not remove element: {}", ex.getMessage(), ex);
}
}
@@ -362,7 +389,7 @@ protected void postEvent(Event event) {
try {
eventPublisher.post(event);
} catch (Exception ex) {
- logger.error("Could not post event of type '" + event.getType() + "'.", ex);
+ logger.error("Could not post event of type '{}'.", event.getType(), ex);
}
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/ManagedProvider.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/ManagedProvider.java
index 283deb61609..82fcd3c0eac 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/ManagedProvider.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/ManagedProvider.java
@@ -7,6 +7,8 @@
*/
package org.eclipse.smarthome.core.common.registry;
+import org.eclipse.jdt.annotation.NonNull;
+
/**
* The {@link ManagedProvider} is a specific {@link Provider} that enables to
* add, remove and update elements at runtime.
@@ -26,7 +28,7 @@ public interface ManagedProvider, K> extends Provider<
* @param element
* element to be added
*/
- void add(E element);
+ void add(@NonNull E element);
/**
* Removes an element and returns the removed element.
@@ -36,7 +38,7 @@ public interface ManagedProvider, K> extends Provider<
* @return element that was removed, or null if no element with the given
* key exists
*/
- E remove(K key);
+ E remove(@NonNull K key);
/**
* Updates an element.
@@ -46,7 +48,7 @@ public interface ManagedProvider, K> extends Provider<
* @return returns the old element or null if no element with the same key
* exists
*/
- E update(E element);
+ E update(@NonNull E element);
/**
* Returns an element for the given key or null if no element for the given
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/Registry.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/Registry.java
index ff1958a2b7c..e2a72d56fb2 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/Registry.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/Registry.java
@@ -10,12 +10,16 @@
import java.util.Collection;
import java.util.stream.Stream;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+
/**
* The {@link Registry} interface represents a registry for elements of the type
* E. The concrete sub interfaces are registered as OSGi services.
*
* @author Dennis Nobel - Initial contribution
* @author Victor Toni - provide elements as {@link Stream}
+ * @author Kai Kreuzer - added null annotations
*
* @param type of the elements in the registry
*/
@@ -26,14 +30,15 @@ public interface Registry, K> {
*
* @param listener registry change listener
*/
- void addRegistryChangeListener(RegistryChangeListener listener);
+ void addRegistryChangeListener(@NonNull RegistryChangeListener listener);
/**
* Returns a collection of all elements in the registry.
*
* @return collection of all elements in the registry
*/
- Collection getAll();
+ @NonNull
+ Collection<@NonNull E> getAll();
/**
* Returns a stream of all elements in the registry.
@@ -49,7 +54,7 @@ public interface Registry, K> {
* key of the element
* @return element or null if no element was found
*/
- public E get(K key);
+ public @Nullable E get(K key);
/**
* Removes a {@link RegistryChangeListener} from the registry.
@@ -57,7 +62,7 @@ public interface Registry, K> {
* @param listener
* registry change listener
*/
- void removeRegistryChangeListener(RegistryChangeListener listener);
+ void removeRegistryChangeListener(@NonNull RegistryChangeListener listener);
/**
* Adds the given element to the according {@link ManagedProvider}.
@@ -68,7 +73,7 @@ public interface Registry, K> {
* @throws IllegalStateException
* if no ManagedProvider is available
*/
- public E add(E element);
+ public @NonNull E add(@NonNull E element);
/**
* Updates the given element at the according {@link ManagedProvider}.
@@ -80,7 +85,7 @@ public interface Registry, K> {
* @throws IllegalStateException
* if no ManagedProvider is available
*/
- public E update(E element);
+ public @Nullable E update(@NonNull E element);
/**
* Removes the given element from the according {@link ManagedProvider}.
@@ -92,5 +97,5 @@ public interface Registry, K> {
* @throws IllegalStateException
* if no ManagedProvider is available
*/
- public E remove(K key);
+ public @Nullable E remove(@NonNull K key);
}
\ No newline at end of file
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/i18n/I18nUtil.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/i18n/I18nUtil.java
index 99dbc6ea441..66536cfad4d 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/i18n/I18nUtil.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/i18n/I18nUtil.java
@@ -7,6 +7,10 @@
*/
package org.eclipse.smarthome.core.i18n;
+/**
+ *
+ * @author Denis Nobel - Initial contribution
+ */
public class I18nUtil {
/** The 'text' pattern (prefix) which marks constants. */
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/CoreActivator.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/CoreActivator.java
index be666a4a307..2041b94d9aa 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/CoreActivator.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/CoreActivator.java
@@ -14,6 +14,8 @@
/**
* The activator class controls the plug-in life cycle
+ *
+ * @author Thomas Eichstädt-Engelen - Initial contribution
*/
public class CoreActivator implements BundleActivator {
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/events/OSGiEventManager.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/events/OSGiEventManager.java
index 18ca5bd355d..5d9fd1dc9bd 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/events/OSGiEventManager.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/events/OSGiEventManager.java
@@ -10,6 +10,7 @@
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import java.util.Arrays;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.Hashtable;
@@ -148,7 +149,7 @@ public void handleEvent(org.osgi.service.event.Event osgiEvent) {
} else {
logger.error(
"The handled OSGi event is invalid. Expect properties as string named 'type', 'payload' and 'topic'. "
- + "Received event properties are: " + osgiEvent.getPropertyNames());
+ + "Received event properties are: {}", Arrays.toString(osgiEvent.getPropertyNames()));
}
}
@@ -164,7 +165,7 @@ private void handleEvent(final String type, final String payload, final String t
}
}
} else {
- logger.warn("Could not find an Event Factory for the event type '" + type + "'.");
+ logger.warn("Could not find an Event Factory for the event type '{}'.", type);
}
}
@@ -175,7 +176,7 @@ private Event createESHEvent(final EventFactory eventFactory, final String type,
eshEvent = eventFactory.createEvent(type, topic, payload, source);
} catch (Exception e) {
logger.error("Creation of ESH-Event failed, "
- + "because one of the registered event factories has thrown an exception: " + e.getMessage(), e);
+ + "because one of the registered event factories has thrown an exception: {}", e.getMessage(), e);
}
return eshEvent;
}
@@ -198,8 +199,8 @@ public Void call() throws Exception {
logger.warn("Dispatching event to subscriber '{}' takes more than {}ms.", eventSubscriber.toString(),
SafeMethodCaller.DEFAULT_TIMEOUT);
} catch (Throwable t) {
- logger.error("Dispatching/filtering event for subscriber '" + EventSubscriber.class.getName()
- + "' failed: " + t.getMessage(), t);
+ logger.error("Dispatching/filtering event for subscriber '{}' failed: {}",
+ EventSubscriber.class.getName(), t.getMessage(), t);
}
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/i18n/ResourceBundleTracker.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/i18n/ResourceBundleTracker.java
index 2c7e24e7c92..7716cf00f56 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/i18n/ResourceBundleTracker.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/i18n/ResourceBundleTracker.java
@@ -140,15 +140,17 @@ private boolean isFragmentBundle(Bundle bundle) {
}
/**
- * This method adds the localization resources provided by this OSGi bundle parameter, accordingly
- * of that the resource bundle is detected.
+ * This method adds the localization resources provided by this OSGi bundle parameter if the bundle is not in
+ * UNINSTALLED state.
*
* @param bundle the OSGi bundle that was detected
*/
private void addResourceBundle(Bundle bundle) {
- LanguageResourceBundleManager languageResource = new LanguageResourceBundleManager(localeProvider, bundle);
- if (languageResource.containsResources()) {
- this.bundleLanguageResourceMap.put(bundle, languageResource);
+ if (bundle.getState() != Bundle.UNINSTALLED) {
+ LanguageResourceBundleManager languageResource = new LanguageResourceBundleManager(localeProvider, bundle);
+ if (languageResource.containsResources()) {
+ this.bundleLanguageResourceMap.put(bundle, languageResource);
+ }
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/items/ItemRegistryImpl.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/items/ItemRegistryImpl.java
index 886961f9bfc..c3817a2c6a8 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/items/ItemRegistryImpl.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/items/ItemRegistryImpl.java
@@ -12,10 +12,8 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
-import java.util.Map;
import org.eclipse.smarthome.core.common.registry.AbstractRegistry;
-import org.eclipse.smarthome.core.common.registry.Provider;
import org.eclipse.smarthome.core.events.EventPublisher;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.items.GroupItem;
@@ -29,8 +27,6 @@
import org.eclipse.smarthome.core.items.events.ItemEventFactory;
import org.eclipse.smarthome.core.types.StateDescriptionProvider;
import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* This is the main implementing class of the {@link ItemRegistry} interface. It
@@ -44,8 +40,6 @@
*/
public class ItemRegistryImpl extends AbstractRegistry implements ItemRegistry {
- private final Logger logger = LoggerFactory.getLogger(ItemRegistryImpl.class);
-
private List stateDescriptionProviders = Collections
.synchronizedList(new ArrayList());
@@ -63,18 +57,6 @@ public Item getItem(String name) throws ItemNotFoundException {
}
}
- @Override
- public Item get(final String itemName) {
- for (final Map.Entry, Collection> entry : elementMap.entrySet()) {
- for (final Item item : entry.getValue()) {
- if (itemName.equals(item.getName())) {
- return item;
- }
- }
- }
- return null;
- }
-
@Override
public Item getItemByPattern(String name) throws ItemNotFoundException, ItemNotUniqueException {
Collection items = getItems(name);
@@ -87,8 +69,13 @@ public Item getItemByPattern(String name) throws ItemNotFoundException, ItemNotU
throw new ItemNotUniqueException(name, items);
}
- return items.iterator().next();
+ Item item = items.iterator().next();
+ if (item == null) {
+ throw new ItemNotFoundException(name);
+ } else {
+ return item;
+ }
}
@Override
@@ -125,13 +112,15 @@ public Collection getItems(String pattern) {
private void addToGroupItems(Item item, List groupItemNames) {
for (String groupName : groupItemNames) {
- try {
- Item groupItem = getItem(groupName);
- if (groupItem instanceof GroupItem) {
- ((GroupItem) groupItem).addMember(item);
+ if (groupName != null) {
+ try {
+ Item groupItem = getItem(groupName);
+ if (groupItem instanceof GroupItem) {
+ ((GroupItem) groupItem).addMember(item);
+ }
+ } catch (ItemNotFoundException e) {
+ // the group might not yet be registered, let's ignore this
}
- } catch (ItemNotFoundException e) {
- // the group might not yet be registered, let's ignore this
}
}
}
@@ -184,13 +173,15 @@ private void addMembersToGroupItem(GroupItem groupItem) {
private void removeFromGroupItems(Item item, List groupItemNames) {
for (String groupName : groupItemNames) {
- try {
- Item groupItem = getItem(groupName);
- if (groupItem instanceof GroupItem) {
- ((GroupItem) groupItem).removeMember(item);
+ if (groupName != null) {
+ try {
+ Item groupItem = getItem(groupName);
+ if (groupItem instanceof GroupItem) {
+ ((GroupItem) groupItem).removeMember(item);
+ }
+ } catch (ItemNotFoundException e) {
+ // the group might not yet be registered, let's ignore this
}
- } catch (ItemNotFoundException e) {
- // the group might not yet be registered, let's ignore this
}
}
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/items/ItemUpdater.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/items/ItemUpdater.java
index 77a93464267..8832630cdf5 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/items/ItemUpdater.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/internal/items/ItemUpdater.java
@@ -69,8 +69,8 @@ protected void receiveUpdate(ItemStateEvent updateEvent) {
if (isAccepted) {
item.setState(newState);
} else {
- logger.debug("Received update of a not accepted type (" + newState.getClass().getSimpleName()
- + ") for item " + itemName);
+ logger.debug("Received update of a not accepted type ({}) for item {}",
+ newState.getClass().getSimpleName(), itemName);
}
} catch (ItemNotFoundException e) {
logger.debug("Received update for non-existing item: {}", e.getMessage());
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/GenericItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/GenericItem.java
index 3749badc309..4ae84e143cd 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/GenericItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/GenericItem.java
@@ -19,6 +19,7 @@
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutorService;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.common.ThreadPoolManager;
import org.eclipse.smarthome.core.events.EventPublisher;
import org.eclipse.smarthome.core.items.events.ItemEventFactory;
@@ -27,6 +28,7 @@
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.StateDescription;
import org.eclipse.smarthome.core.types.StateDescriptionProvider;
+import org.eclipse.smarthome.core.types.StateOption;
import org.eclipse.smarthome.core.types.UnDefType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,8 +62,10 @@ abstract public class GenericItem implements ActiveItem {
protected Set tags = new HashSet();
+ @NonNull
final protected String name;
+ @NonNull
final protected String type;
protected State state = UnDefType.NULL;
@@ -72,7 +76,7 @@ abstract public class GenericItem implements ActiveItem {
private List stateDescriptionProviders;
- public GenericItem(String type, String name) {
+ public GenericItem(@NonNull String type, @NonNull String name) {
this.name = name;
this.type = type;
}
@@ -315,11 +319,7 @@ public boolean equals(Object obj) {
} else if (!label.equals(other.label)) {
return false;
}
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
+ if (!name.equals(other.name)) {
return false;
}
if (tags == null) {
@@ -329,11 +329,7 @@ public boolean equals(Object obj) {
} else if (!tags.equals(other.tags)) {
return false;
}
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
+ if (!type.equals(other.type)) {
return false;
}
return true;
@@ -401,15 +397,32 @@ public StateDescription getStateDescription() {
@Override
public StateDescription getStateDescription(Locale locale) {
+ StateDescription result = null;
+ List stateOptions = Collections.emptyList();
if (stateDescriptionProviders != null) {
for (StateDescriptionProvider stateDescriptionProvider : stateDescriptionProviders) {
StateDescription stateDescription = stateDescriptionProvider.getStateDescription(this.name, locale);
- if (stateDescription != null) {
- return stateDescription;
+
+ // as long as no valid StateDescription is provided we reassign here:
+ if (result == null) {
+ result = stateDescription;
+ }
+
+ // if the current StateDescription does provide options and we don't already have some, we pick them up
+ // here
+ if (stateDescription != null && !stateDescription.getOptions().isEmpty() && stateOptions.isEmpty()) {
+ stateOptions = stateDescription.getOptions();
}
}
}
- return null;
+
+ // we recreate the StateDescription if we found a valid one and state options are given:
+ if (result != null && !stateOptions.isEmpty()) {
+ result = new StateDescription(result.getMinimum(), result.getMaximum(), result.getStep(),
+ result.getPattern(), result.isReadOnly(), stateOptions);
+ }
+
+ return result;
}
/**
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/GroupItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/GroupItem.java
index 22f776e0fc3..0a8665601e8 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/GroupItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/GroupItem.java
@@ -16,6 +16,7 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.items.events.ItemEventFactory;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.State;
@@ -25,8 +26,13 @@
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
+/**
+ *
+ * @author Kai Kreuzer - Initial contribution
+ */
public class GroupItem extends GenericItem implements StateChangeListener {
+ @NonNull
public static final String TYPE = "Group";
private final Logger logger = LoggerFactory.getLogger(GroupItem.class);
@@ -42,11 +48,11 @@ public class GroupItem extends GenericItem implements StateChangeListener {
*
* @param name name of the group
*/
- public GroupItem(String name) {
+ public GroupItem(@NonNull String name) {
this(name, null, null);
}
- public GroupItem(String name, GenericItem baseItem) {
+ public GroupItem(@NonNull String name, GenericItem baseItem) {
// only baseItem but no function set -> use Equality
this(name, baseItem, new GroupFunction.Equality());
}
@@ -58,7 +64,7 @@ public GroupItem(String name, GenericItem baseItem) {
* @param baseItem type of items in the group
* @param function function to calculate group status out of member status
*/
- public GroupItem(String name, GenericItem baseItem, GroupFunction function) {
+ public GroupItem(@NonNull String name, GenericItem baseItem, GroupFunction function) {
super(TYPE, name);
// we only allow GroupItem with BOTH, baseItem AND function set, or NONE of them set
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/Item.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/Item.java
index 06003b9b03a..daa64cd78b9 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/Item.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/Item.java
@@ -11,6 +11,7 @@
import java.util.Locale;
import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.common.registry.Identifiable;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.PercentType;
@@ -51,14 +52,14 @@ public interface Item extends Identifiable {
*
* @return the name of the item
*/
- public String getName();
+ public @NonNull String getName();
/**
* returns the item type as defined by {@link ItemFactory}s
*
* @return the item type
*/
- public String getType();
+ public @NonNull String getType();
/**
*
@@ -128,14 +129,16 @@ public interface Item extends Identifiable {
public String getCategory();
/**
- * Returns the state description (uses the default locale).
+ * Returns the first provided state description (uses the default locale).
+ * If options are defined on the channel, they are included in the returned state description.
*
* @return state description (can be null)
*/
public StateDescription getStateDescription();
/**
- * Returns the state description for a given locale.
+ * Returns the first provided state description for a given locale.
+ * If options are defined on the channel, they are included in the returned state description.
*
* @param locale
* locale (can be null)
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ItemFactory.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ItemFactory.java
index ffbe6ac22a7..6979ad87719 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ItemFactory.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ItemFactory.java
@@ -7,6 +7,8 @@
*/
package org.eclipse.smarthome.core.items;
+import org.eclipse.jdt.annotation.NonNull;
+
/**
* This Factory creates concrete instances of the known ItemTypes.
*
@@ -16,17 +18,17 @@ public interface ItemFactory {
/**
* Creates a new Item instance of type itemTypeName and the name itemName
- *
+ *
* @param itemTypeName
* @param itemName
- *
+ *
* @return a new Item of type itemTypeName or null if no matching class is known.
*/
- GenericItem createItem(String itemTypeName, String itemName);
+ GenericItem createItem(@NonNull String itemTypeName, @NonNull String itemName);
/**
* Returns the list of all supported ItemTypes of this Factory.
- *
+ *
* @return the supported ItemTypes
*/
String[] getSupportedItemTypes();
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ItemRegistry.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ItemRegistry.java
index 8d17295d48c..f63b0b6f54c 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ItemRegistry.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ItemRegistry.java
@@ -9,6 +9,8 @@
import java.util.Collection;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.common.registry.Registry;
/**
@@ -31,7 +33,7 @@ public interface ItemRegistry extends Registry {
* @return the uniquely identified item
* @throws ItemNotFoundException if no item matches the input
*/
- public Item getItem(String name) throws ItemNotFoundException;
+ public @NonNull Item getItem(String name) throws ItemNotFoundException;
/**
* This method retrieves a single item from the registry.
@@ -42,14 +44,14 @@ public interface ItemRegistry extends Registry {
* @throws ItemNotFoundException if no item matches the input
* @throws ItemNotUniqueException if multiply items match the input
*/
- public Item getItemByPattern(String name) throws ItemNotFoundException, ItemNotUniqueException;
+ public @NonNull Item getItemByPattern(@NonNull String name) throws ItemNotFoundException, ItemNotUniqueException;
/**
* This method retrieves all items that are currently available in the registry
*
* @return a collection of all available items
*/
- public Collection getItems();
+ public @NonNull Collection<@NonNull Item> getItems();
/**
* This method retrieves all items with the given type
@@ -58,14 +60,14 @@ public interface ItemRegistry extends Registry {
* - item type as defined by {@link ItemFactory}s
* @return a collection of all items of the given type
*/
- public Collection getItemsOfType(String type);
+ public @NonNull Collection getItemsOfType(@NonNull String type);
/**
* This method retrieves all items that match a given search pattern
*
* @return a collection of all items matching the search pattern
*/
- public Collection getItems(String pattern);
+ public @NonNull Collection<@NonNull Item> getItems(@NonNull String pattern);
/**
* Returns list of items which contains all of the given tags.
@@ -74,7 +76,7 @@ public interface ItemRegistry extends Registry {
* - array of tags to be present on the returned items.
* @return list of items which contains all of the given tags.
*/
- public Collection getItemsByTag(String... tags);
+ public @NonNull Collection getItemsByTag(@NonNull String... tags);
/**
* Returns list of items with a certain type containing all of the given tags.
@@ -85,7 +87,7 @@ public interface ItemRegistry extends Registry {
* - array of tags to be present on the returned items.
* @return list of items which contains all of the given tags.
*/
- public Collection getItemsByTagAndType(String type, String... tags);
+ public @NonNull Collection getItemsByTagAndType(@NonNull String type, @NonNull String... tags);
/**
* Returns list of items which contains all of the given tags.
@@ -98,11 +100,12 @@ public interface ItemRegistry extends Registry {
* @return list of items which contains all of the given tags, which is
* filtered by the given type filter.
*/
- public Collection getItemsByTag(Class typeFilter, String... tags);
+ public @NonNull Collection getItemsByTag(@NonNull Class typeFilter,
+ @NonNull String... tags);
/**
* @see ManagedItemProvider#remove(String, boolean)
*/
- public Item remove(String itemName, boolean recursive);
+ public @Nullable Item remove(@NonNull String itemName, boolean recursive);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ManagedItemProvider.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ManagedItemProvider.java
index 7818e11d856..86c07b25cf1 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ManagedItemProvider.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/ManagedItemProvider.java
@@ -19,6 +19,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.common.registry.AbstractManagedProvider;
import org.eclipse.smarthome.core.items.ManagedItemProvider.PersistedItem;
import org.eclipse.smarthome.core.items.dto.GroupFunctionDTO;
@@ -43,11 +44,15 @@ public class ManagedItemProvider extends AbstractManagedProvider groupNames;
- public String itemType;
+ public @NonNull String itemType;
public Set tags;
@@ -61,7 +66,7 @@ public static class PersistedItem {
}
- private static final String ITEM_TYPE_GROUP = "Group";
+ private static final @NonNull String ITEM_TYPE_GROUP = "Group";
private final Logger logger = LoggerFactory.getLogger(ManagedItemProvider.class);
@@ -82,8 +87,7 @@ public static class PersistedItem {
public Item remove(String itemName, boolean recursive) {
Item item = get(itemName);
if (recursive && item instanceof GroupItem) {
- List members = getMemberNamesRecursively((GroupItem) item, getAll());
- for (String member : members) {
+ for (String member : getMemberNamesRecursively((GroupItem) item, getAll())) {
this.remove(member);
}
}
@@ -95,8 +99,8 @@ public Item remove(String itemName, boolean recursive) {
}
}
- private List getMemberNamesRecursively(GroupItem groupItem, Collection allItems) {
- List memberNames = new ArrayList<>();
+ private List<@NonNull String> getMemberNamesRecursively(GroupItem groupItem, Collection allItems) {
+ List<@NonNull String> memberNames = new ArrayList<>();
for (Item item : allItems) {
if (item.getGroupNames().contains(groupItem.getName())) {
memberNames.add(item.getName());
@@ -108,7 +112,7 @@ private List getMemberNamesRecursively(GroupItem groupItem, Collection entry = iterator.next();
String itemName = entry.getKey();
PersistedItem persistedItem = entry.getValue();
+ @SuppressWarnings("null")
ActiveItem item = itemFactory.createItem(persistedItem.itemType, itemName);
if (item != null) {
iterator.remove();
@@ -160,11 +165,6 @@ protected void addItemFactory(ItemFactory itemFactory) {
}
}
- @Override
- protected String getKey(Item element) {
- return element.getName();
- }
-
@Override
protected String getStorageName() {
return Item.class.getName();
@@ -243,7 +243,8 @@ private void configureItem(PersistedItem persistedItem, ActiveItem item) {
@Override
protected PersistedItem toPersistableElement(Item item) {
- PersistedItem persistedItem = new PersistedItem();
+ PersistedItem persistedItem = new PersistedItem(
+ item instanceof GroupItem ? ITEM_TYPE_GROUP : toItemFactoryName(item));
if (item instanceof GroupItem) {
GroupItem groupItem = (GroupItem) item;
@@ -252,13 +253,9 @@ protected PersistedItem toPersistableElement(Item item) {
if (baseItem != null) {
baseItemType = toItemFactoryName(baseItem);
}
- persistedItem.itemType = ITEM_TYPE_GROUP;
persistedItem.baseItemType = baseItemType;
addFunctionToPersisedItem(persistedItem, groupItem);
- } else {
- String itemType = toItemFactoryName(item);
- persistedItem.itemType = itemType;
}
persistedItem.label = item.getLabel();
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/dto/ItemDTOMapper.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/dto/ItemDTOMapper.java
index 41b8a534f8e..32d3a00d6a0 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/dto/ItemDTOMapper.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/items/dto/ItemDTOMapper.java
@@ -156,7 +156,7 @@ public static GroupFunction mapFunction(Item baseItem, GroupFunctionDTO function
break;
default:
LoggerFactory.getLogger(ItemDTOMapper.class)
- .error("Unknown group function '" + function.name + "'. Using Equality instead.");
+ .error("Unknown group function '{}'. Using Equality instead.", function.name);
}
if (groupFunction == null) {
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/CoreItemFactory.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/CoreItemFactory.java
index fe34d0a7f46..6d18fa90da1 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/CoreItemFactory.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/CoreItemFactory.java
@@ -7,6 +7,7 @@
*/
package org.eclipse.smarthome.core.library;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.items.ItemFactory;
import org.eclipse.smarthome.core.library.items.CallItem;
@@ -31,25 +32,21 @@
*/
public class CoreItemFactory implements ItemFactory {
- public static final String CALL = "Call";
- public static final String COLOR = "Color";
- public static final String CONTACT = "Contact";
- public static final String DATETIME = "DateTime";
- public static final String DIMMER = "Dimmer";
- public static final String IMAGE = "Image";
- public static final String LOCATION = "Location";
- public static final String NUMBER = "Number";
- public static final String PLAYER = "Player";
- public static final String ROLLERSHUTTER = "Rollershutter";
- public static final String STRING = "String";
- public static final String SWITCH = "Switch";
+ public static final @NonNull String CALL = "Call";
+ public static final @NonNull String COLOR = "Color";
+ public static final @NonNull String CONTACT = "Contact";
+ public static final @NonNull String DATETIME = "DateTime";
+ public static final @NonNull String DIMMER = "Dimmer";
+ public static final @NonNull String IMAGE = "Image";
+ public static final @NonNull String LOCATION = "Location";
+ public static final @NonNull String NUMBER = "Number";
+ public static final @NonNull String PLAYER = "Player";
+ public static final @NonNull String ROLLERSHUTTER = "Rollershutter";
+ public static final @NonNull String STRING = "String";
+ public static final @NonNull String SWITCH = "Switch";
@Override
public GenericItem createItem(String itemTypeName, String itemName) {
- if (itemTypeName == null) {
- return null;
- }
-
switch (itemTypeName) {
case CALL:
return new CallItem(itemName);
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/internal/CoreLibraryActivator.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/internal/CoreLibraryActivator.java
index 78b5adb09a7..eb9ef02377b 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/internal/CoreLibraryActivator.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/internal/CoreLibraryActivator.java
@@ -10,6 +10,10 @@
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+/**
+ *
+ * @author Kai Kreuzer - Initial contribution
+ */
public class CoreLibraryActivator implements BundleActivator {
@Override
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/CallItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/CallItem.java
index c7d164df3f0..f3591d7fe42 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/CallItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/CallItem.java
@@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.library.types.StringListType;
@@ -34,7 +35,7 @@ public class CallItem extends GenericItem {
acceptedDataTypes.add(UnDefType.class);
}
- public CallItem(String name) {
+ public CallItem(@NonNull String name) {
super(CoreItemFactory.CALL, name);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/ColorItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/ColorItem.java
index 58bb101e6f7..49a33b32db6 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/ColorItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/ColorItem.java
@@ -12,6 +12,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.HSBType;
@@ -47,7 +48,7 @@ public class ColorItem extends DimmerItem {
acceptedCommandTypes.add(RefreshType.class);
}
- public ColorItem(String name) {
+ public ColorItem(@NonNull String name) {
super(CoreItemFactory.COLOR, name);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/ContactItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/ContactItem.java
index 2b882efb388..86ae6941cd1 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/ContactItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/ContactItem.java
@@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.library.types.OpenClosedType;
@@ -38,7 +39,7 @@ public class ContactItem extends GenericItem {
acceptedCommandTypes.add(RefreshType.class);
}
- public ContactItem(String name) {
+ public ContactItem(@NonNull String name) {
super(CoreItemFactory.CONTACT, name);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/DateTimeItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/DateTimeItem.java
index 61f49465fda..e3058de43ed 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/DateTimeItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/DateTimeItem.java
@@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.library.types.DateTimeType;
@@ -39,7 +40,7 @@ public class DateTimeItem extends GenericItem {
acceptedCommandTypes.add(DateTimeType.class);
}
- public DateTimeItem(String name) {
+ public DateTimeItem(@NonNull String name) {
super(CoreItemFactory.DATETIME, name);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/DimmerItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/DimmerItem.java
index 02d053e2570..cde75266745 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/DimmerItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/DimmerItem.java
@@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.library.types.IncreaseDecreaseType;
import org.eclipse.smarthome.core.library.types.OnOffType;
@@ -44,11 +45,11 @@ public class DimmerItem extends SwitchItem {
acceptedCommandTypes.add(RefreshType.class);
}
- public DimmerItem(String name) {
+ public DimmerItem(@NonNull String name) {
super(CoreItemFactory.DIMMER, name);
}
- /* package */ DimmerItem(String type, String name) {
+ /* package */ DimmerItem(@NonNull String type, @NonNull String name) {
super(type, name);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/ImageItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/ImageItem.java
index 1b174964943..b8eed49287b 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/ImageItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/ImageItem.java
@@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.library.types.RawType;
@@ -37,7 +38,7 @@ public class ImageItem extends GenericItem {
acceptedCommandTypes.add(RefreshType.class);
}
- public ImageItem(String name) {
+ public ImageItem(@NonNull String name) {
super(CoreItemFactory.IMAGE, name);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/LocationItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/LocationItem.java
index 83cb32e00eb..2a9b7eeab26 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/LocationItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/LocationItem.java
@@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.library.types.DecimalType;
@@ -40,7 +41,7 @@ public class LocationItem extends GenericItem {
acceptedCommandTypes.add(PointType.class);
}
- public LocationItem(String name) {
+ public LocationItem(@NonNull String name) {
super(CoreItemFactory.LOCATION, name);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/NumberItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/NumberItem.java
index 8096bd6a80f..2800ea68e8d 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/NumberItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/NumberItem.java
@@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.library.types.DecimalType;
@@ -41,7 +42,7 @@ public class NumberItem extends GenericItem {
acceptedCommandTypes.add(RefreshType.class);
}
- public NumberItem(String name) {
+ public NumberItem(@NonNull String name) {
super(CoreItemFactory.NUMBER, name);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/PlayerItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/PlayerItem.java
index 4d75fca41bf..8ac93e6f1b7 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/PlayerItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/PlayerItem.java
@@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.library.types.NextPreviousType;
@@ -42,11 +43,11 @@ public class PlayerItem extends GenericItem {
acceptedCommandTypes.add(RefreshType.class);
}
- public PlayerItem(String name) {
+ public PlayerItem(@NonNull String name) {
super(CoreItemFactory.PLAYER, name);
}
- /* package */ PlayerItem(String type, String name) {
+ /* package */ PlayerItem(@NonNull String type, @NonNull String name) {
super(type, name);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/RollershutterItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/RollershutterItem.java
index fc3314dc118..b92d57fdb10 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/RollershutterItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/RollershutterItem.java
@@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.library.types.PercentType;
@@ -46,7 +47,7 @@ public class RollershutterItem extends GenericItem {
acceptedCommandTypes.add(RefreshType.class);
}
- public RollershutterItem(String name) {
+ public RollershutterItem(@NonNull String name) {
super(CoreItemFactory.ROLLERSHUTTER, name);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/StringItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/StringItem.java
index 22cb94f7ebd..599fc28cffc 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/StringItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/StringItem.java
@@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.library.types.DateTimeType;
@@ -42,7 +43,7 @@ public class StringItem extends GenericItem {
acceptedCommandTypes.add(StringType.class);
}
- public StringItem(String name) {
+ public StringItem(@NonNull String name) {
super(CoreItemFactory.STRING, name);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/SwitchItem.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/SwitchItem.java
index fe1da4e3245..d605286d312 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/SwitchItem.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/items/SwitchItem.java
@@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.library.types.OnOffType;
@@ -39,11 +40,11 @@ public class SwitchItem extends GenericItem {
acceptedCommandTypes.add(RefreshType.class);
}
- public SwitchItem(String name) {
+ public SwitchItem(@NonNull String name) {
super(CoreItemFactory.SWITCH, name);
}
- /* package */ SwitchItem(String type, String name) {
+ /* package */ SwitchItem(@NonNull String type, @NonNull String name) {
super(type, name);
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/DateTimeType.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/DateTimeType.java
index cd830992a90..48622125e4c 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/DateTimeType.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/DateTimeType.java
@@ -17,6 +17,10 @@
import org.eclipse.smarthome.core.types.PrimitiveType;
import org.eclipse.smarthome.core.types.State;
+/**
+ *
+ * @author Kai Kreuzer - Initial contribution
+ */
public class DateTimeType implements PrimitiveType, State, Command {
public static final String DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss";
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/IncreaseDecreaseType.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/IncreaseDecreaseType.java
index 3634c9d90e5..63224b16366 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/IncreaseDecreaseType.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/IncreaseDecreaseType.java
@@ -10,6 +10,10 @@
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.PrimitiveType;
+/**
+ *
+ * @author Kai Kreuzer - Initial contribution
+ */
public enum IncreaseDecreaseType implements PrimitiveType, Command {
INCREASE,
DECREASE;
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/OnOffType.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/OnOffType.java
index e1e2eb4c91f..4dba17a3915 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/OnOffType.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/OnOffType.java
@@ -11,6 +11,10 @@
import org.eclipse.smarthome.core.types.PrimitiveType;
import org.eclipse.smarthome.core.types.State;
+/**
+ *
+ * @author Kai Kreuzer - Initial contribution
+ */
public enum OnOffType implements PrimitiveType, State, Command {
ON,
OFF;
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/OpenClosedType.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/OpenClosedType.java
index b2fa40113eb..644961c91a0 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/OpenClosedType.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/OpenClosedType.java
@@ -11,6 +11,10 @@
import org.eclipse.smarthome.core.types.PrimitiveType;
import org.eclipse.smarthome.core.types.State;
+/**
+ *
+ * @author Kai Kreuzer - Initial contribution
+ */
public enum OpenClosedType implements PrimitiveType, State, Command {
OPEN,
CLOSED;
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/StopMoveType.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/StopMoveType.java
index 524c4873f76..b89ed29fb57 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/StopMoveType.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/StopMoveType.java
@@ -10,6 +10,10 @@
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.PrimitiveType;
+/**
+ *
+ * @author Kai Kreuzer - Initial contribution
+ */
public enum StopMoveType implements PrimitiveType, Command {
STOP,
MOVE;
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/StringListType.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/StringListType.java
index 72db5451955..f0121770b91 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/StringListType.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/StringListType.java
@@ -12,7 +12,6 @@
import java.util.Collections;
import java.util.Formatter;
import java.util.List;
-import java.util.function.Function;
import java.util.stream.Collectors;
import org.eclipse.smarthome.core.types.Command;
@@ -43,9 +42,7 @@ public StringListType(List rows) {
}
public StringListType(StringType... rows) {
- typeDetails = Arrays.stream(rows)
- .map(StringType::toString)
- .collect(Collectors.toList());
+ typeDetails = Arrays.stream(rows).map(StringType::toString).collect(Collectors.toList());
}
public StringListType(String... rows) {
@@ -56,9 +53,7 @@ public StringListType(String... rows) {
* Deserialize the input string, splitting it on every delimiter not preceded by a backslash.
*/
public StringListType(String serialized) {
- typeDetails = Arrays.stream(
- serialized.split(REGEX_SPLITTER))
- .map(s -> s.replace(ESCAPED_DELIMITER, DELIMITER))
+ typeDetails = Arrays.stream(serialized.split(REGEX_SPLITTER)).map(s -> s.replace(ESCAPED_DELIMITER, DELIMITER))
.collect(Collectors.toList());
}
@@ -91,8 +86,7 @@ public String toString() {
@Override
public String toFullString() {
- return typeDetails.stream()
- .map(s -> s.replace(DELIMITER, ESCAPED_DELIMITER))
+ return typeDetails.stream().map(s -> s.replace(DELIMITER, ESCAPED_DELIMITER))
.collect(Collectors.joining(DELIMITER));
}
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/StringType.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/StringType.java
index 9bcf98ecbab..6a0c286529b 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/StringType.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/StringType.java
@@ -13,6 +13,10 @@
import org.eclipse.smarthome.core.types.PrimitiveType;
import org.eclipse.smarthome.core.types.State;
+/**
+ *
+ * @author Kai Kreuzer - Initial contribution
+ */
public class StringType implements PrimitiveType, State, Command {
public final static StringType EMPTY = new StringType();
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/UpDownType.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/UpDownType.java
index 9e464c19fcf..cf0edbc8bae 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/UpDownType.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/UpDownType.java
@@ -13,6 +13,10 @@
import org.eclipse.smarthome.core.types.PrimitiveType;
import org.eclipse.smarthome.core.types.State;
+/**
+ *
+ * @author Kai Kreuzer - Initial contribution
+ */
public enum UpDownType implements PrimitiveType, State, Command {
UP,
DOWN;
diff --git a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/net/NetUtil.java b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/net/NetUtil.java
index b5785cf7958..bbc652eff82 100644
--- a/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/net/NetUtil.java
+++ b/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/net/NetUtil.java
@@ -16,7 +16,13 @@
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+import org.eclipse.jdt.annotation.NonNull;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Modified;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -25,17 +31,63 @@
*
* @author Markus Rathgeb - Initial contribution and API
* @author Mark Herwege - Added methods to find broadcast address(es)
+ * @author Stefan Triller - Converted to OSGi service with primary ipv4 conf
*/
-public class NetUtil {
+@Component(name = "org.eclipse.smarthome.network", property = { "service.config.description.uri=system:network",
+ "service.config.label=Network Settings", "service.config.category=system" })
+public class NetUtil implements NetworkAddressService {
+ private static final String PRIMARY_ADDRESS = "primaryAddress";
private static final Logger LOGGER = LoggerFactory.getLogger(NetUtil.class);
- private NetUtil() {
+ private static final Pattern IPV4_PATTERN = Pattern
+ .compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
+
+ private String primaryAddress;
+
+ @Activate
+ protected void activate(Map props) {
+ modified(props);
+ }
+
+ @Modified
+ public synchronized void modified(Map