]> git.basschouten.com Git - openhab-addons.git/commitdiff
Support Colour item and Group item with a state (#9111)
authorMike Major <mike_j_major@hotmail.com>
Mon, 23 Nov 2020 18:15:56 +0000 (18:15 +0000)
committerGitHub <noreply@github.com>
Mon, 23 Nov 2020 18:15:56 +0000 (19:15 +0100)
Signed-off-by: Mike Major <mike_j_major@hotmail.com>
bundles/org.openhab.persistence.rrd4j/README.md
bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java

index 86395eee7883e3cff2bccb67f9d6a3a033b2b8ae..b77c4981b83f1a3e798d46a31a18221bb70fa1a3 100644 (file)
@@ -12,7 +12,7 @@ This service cannot be directly queried, because of its data compression, which
 
 NOTE: rrd4j is for storing numerical data only.
 It cannot store complex data types.
-The supported item types are therefore only `Switch` (internally mapped to 0/1), `Dimmer`, `Number`, `Contact` (internally mapped to 0/1) and `Rollershutter`.
+The supported item types are therefore only `Switch` (internally mapped to 0/1), `Dimmer`, `Number`, `Contact` (internally mapped to 0/1), `Rollershutter` and `Color` (only brightness component stored).
 
 ## Configuration
 
index 6e1a6615abd429a173aef0fcae10f67d51d5b827..cc68989b3ceaf41d2feb51f15fb7dcc075134bc8 100644 (file)
@@ -38,11 +38,13 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.core.OpenHAB;
 import org.openhab.core.common.NamedThreadFactory;
+import org.openhab.core.items.GroupItem;
 import org.openhab.core.items.Item;
 import org.openhab.core.items.ItemNotFoundException;
 import org.openhab.core.items.ItemRegistry;
 import org.openhab.core.items.ItemUtil;
 import org.openhab.core.library.CoreItemFactory;
+import org.openhab.core.library.items.ColorItem;
 import org.openhab.core.library.items.ContactItem;
 import org.openhab.core.library.items.DimmerItem;
 import org.openhab.core.library.items.NumberItem;
@@ -96,7 +98,7 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
     private static final String DEFAULT_QUANTIFIABLE = "default_quantifiable";
 
     private static final Set<String> SUPPORTED_TYPES = Set.of(CoreItemFactory.SWITCH, CoreItemFactory.CONTACT,
-            CoreItemFactory.DIMMER, CoreItemFactory.NUMBER, CoreItemFactory.ROLLERSHUTTER);
+            CoreItemFactory.DIMMER, CoreItemFactory.NUMBER, CoreItemFactory.ROLLERSHUTTER, CoreItemFactory.COLOR);
 
     private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(3,
             new NamedThreadFactory("RRD4j"));
@@ -400,11 +402,15 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
     private State mapToState(double value, @Nullable Item item, @Nullable Unit unit) {
+        if (item instanceof GroupItem) {
+            item = ((GroupItem) item).getBaseItem();
+        }
+
         if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
             return value == 0.0d ? OnOffType.OFF : OnOffType.ON;
         } else if (item instanceof ContactItem) {
             return value == 0.0d ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
-        } else if (item instanceof DimmerItem || item instanceof RollershutterItem) {
+        } else if (item instanceof DimmerItem || item instanceof RollershutterItem || item instanceof ColorItem) {
             // make sure Items that need PercentTypes instead of DecimalTypes do receive the right information
             return new PercentType((int) Math.round(value * 100));
         } else if (item instanceof NumberItem) {
@@ -418,6 +424,13 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
     }
 
     private boolean isSupportedItemType(Item item) {
+        if (item instanceof GroupItem) {
+            final Item baseItem = ((GroupItem) item).getBaseItem();
+            if (baseItem != null) {
+                item = baseItem;
+            }
+        }
+
         return SUPPORTED_TYPES.contains(ItemUtil.getMainItemType(item.getType()));
     }