Support Colour item and Group item with a state (#9111)
Signed-off-by: Mike Major <mike_j_major@hotmail.com>
This commit is contained in:
@@ -12,7 +12,7 @@ This service cannot be directly queried, because of its data compression, which
|
|||||||
|
|
||||||
NOTE: rrd4j is for storing numerical data only.
|
NOTE: rrd4j is for storing numerical data only.
|
||||||
It cannot store complex data types.
|
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
|
## Configuration
|
||||||
|
|
||||||
|
|||||||
@@ -38,11 +38,13 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.core.OpenHAB;
|
import org.openhab.core.OpenHAB;
|
||||||
import org.openhab.core.common.NamedThreadFactory;
|
import org.openhab.core.common.NamedThreadFactory;
|
||||||
|
import org.openhab.core.items.GroupItem;
|
||||||
import org.openhab.core.items.Item;
|
import org.openhab.core.items.Item;
|
||||||
import org.openhab.core.items.ItemNotFoundException;
|
import org.openhab.core.items.ItemNotFoundException;
|
||||||
import org.openhab.core.items.ItemRegistry;
|
import org.openhab.core.items.ItemRegistry;
|
||||||
import org.openhab.core.items.ItemUtil;
|
import org.openhab.core.items.ItemUtil;
|
||||||
import org.openhab.core.library.CoreItemFactory;
|
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.ContactItem;
|
||||||
import org.openhab.core.library.items.DimmerItem;
|
import org.openhab.core.library.items.DimmerItem;
|
||||||
import org.openhab.core.library.items.NumberItem;
|
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 String DEFAULT_QUANTIFIABLE = "default_quantifiable";
|
||||||
|
|
||||||
private static final Set<String> SUPPORTED_TYPES = Set.of(CoreItemFactory.SWITCH, CoreItemFactory.CONTACT,
|
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,
|
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(3,
|
||||||
new NamedThreadFactory("RRD4j"));
|
new NamedThreadFactory("RRD4j"));
|
||||||
@@ -400,11 +402,15 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
|
|||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
private State mapToState(double value, @Nullable Item item, @Nullable Unit unit) {
|
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)) {
|
if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
|
||||||
return value == 0.0d ? OnOffType.OFF : OnOffType.ON;
|
return value == 0.0d ? OnOffType.OFF : OnOffType.ON;
|
||||||
} else if (item instanceof ContactItem) {
|
} else if (item instanceof ContactItem) {
|
||||||
return value == 0.0d ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
|
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
|
// make sure Items that need PercentTypes instead of DecimalTypes do receive the right information
|
||||||
return new PercentType((int) Math.round(value * 100));
|
return new PercentType((int) Math.round(value * 100));
|
||||||
} else if (item instanceof NumberItem) {
|
} else if (item instanceof NumberItem) {
|
||||||
@@ -418,6 +424,13 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSupportedItemType(Item item) {
|
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()));
|
return SUPPORTED_TYPES.contains(ItemUtil.getMainItemType(item.getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user