mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 19:55:48 +01:00
Replaced static inline declarations by List.of() method (#1755)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
acdbdfa4d7
commit
172ee2f0ad
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -21,6 +19,7 @@ import org.openhab.core.items.GenericItem;
|
||||
import org.openhab.core.library.CoreItemFactory;
|
||||
import org.openhab.core.library.types.StringListType;
|
||||
import org.openhab.core.types.Command;
|
||||
import org.openhab.core.types.RefreshType;
|
||||
import org.openhab.core.types.State;
|
||||
import org.openhab.core.types.UnDefType;
|
||||
|
||||
@ -33,13 +32,9 @@ import org.openhab.core.types.UnDefType;
|
||||
@NonNullByDefault
|
||||
public class CallItem extends GenericItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<>();
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(StringListType.class);
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
}
|
||||
private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(StringListType.class,
|
||||
UnDefType.class);
|
||||
private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(RefreshType.class);
|
||||
|
||||
public CallItem(String name) {
|
||||
super(CoreItemFactory.CALL, name);
|
||||
@ -47,17 +42,17 @@ public class CallItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return Collections.unmodifiableList(acceptedDataTypes);
|
||||
return ACCEPTED_DATA_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return Collections.unmodifiableList(acceptedCommandTypes);
|
||||
return ACCEPTED_COMMAND_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
if (isAcceptedState(acceptedDataTypes, state)) {
|
||||
if (isAcceptedState(ACCEPTED_DATA_TYPES, state)) {
|
||||
super.setState(state);
|
||||
} else {
|
||||
logSetTypeError(state);
|
||||
|
@ -13,8 +13,6 @@
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -37,21 +35,10 @@ import org.openhab.core.types.UnDefType;
|
||||
@NonNullByDefault
|
||||
public class ColorItem extends DimmerItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<>();
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(HSBType.class);
|
||||
acceptedDataTypes.add(PercentType.class);
|
||||
acceptedDataTypes.add(OnOffType.class);
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
|
||||
acceptedCommandTypes.add(HSBType.class);
|
||||
acceptedCommandTypes.add(PercentType.class);
|
||||
acceptedCommandTypes.add(OnOffType.class);
|
||||
acceptedCommandTypes.add(IncreaseDecreaseType.class);
|
||||
acceptedCommandTypes.add(RefreshType.class);
|
||||
}
|
||||
private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(HSBType.class, PercentType.class,
|
||||
OnOffType.class, UnDefType.class);
|
||||
private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(HSBType.class,
|
||||
PercentType.class, OnOffType.class, IncreaseDecreaseType.class, RefreshType.class);
|
||||
|
||||
public ColorItem(String name) {
|
||||
super(CoreItemFactory.COLOR, name);
|
||||
@ -63,17 +50,17 @@ public class ColorItem extends DimmerItem {
|
||||
|
||||
@Override
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return Collections.unmodifiableList(acceptedDataTypes);
|
||||
return ACCEPTED_DATA_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return Collections.unmodifiableList(acceptedCommandTypes);
|
||||
return ACCEPTED_COMMAND_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
if (isAcceptedState(acceptedDataTypes, state)) {
|
||||
if (isAcceptedState(ACCEPTED_DATA_TYPES, state)) {
|
||||
State currentState = this.state;
|
||||
|
||||
if (currentState instanceof HSBType) {
|
||||
|
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -34,15 +32,9 @@ import org.openhab.core.types.UnDefType;
|
||||
@NonNullByDefault
|
||||
public class ContactItem extends GenericItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<>();
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(OpenClosedType.class);
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
|
||||
acceptedCommandTypes.add(RefreshType.class);
|
||||
}
|
||||
private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(OpenClosedType.class,
|
||||
UnDefType.class);
|
||||
private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(RefreshType.class);
|
||||
|
||||
public ContactItem(String name) {
|
||||
super(CoreItemFactory.CONTACT, name);
|
||||
@ -50,17 +42,17 @@ public class ContactItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return Collections.unmodifiableList(acceptedDataTypes);
|
||||
return ACCEPTED_DATA_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return Collections.unmodifiableList(acceptedCommandTypes);
|
||||
return ACCEPTED_COMMAND_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
if (isAcceptedState(acceptedDataTypes, state)) {
|
||||
if (isAcceptedState(ACCEPTED_DATA_TYPES, state)) {
|
||||
super.setState(state);
|
||||
} else {
|
||||
logSetTypeError(state);
|
||||
|
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -34,16 +32,10 @@ import org.openhab.core.types.UnDefType;
|
||||
@NonNullByDefault
|
||||
public class DateTimeItem extends GenericItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<>();
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(DateTimeType.class);
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
|
||||
acceptedCommandTypes.add(RefreshType.class);
|
||||
acceptedCommandTypes.add(DateTimeType.class);
|
||||
}
|
||||
private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(DateTimeType.class,
|
||||
UnDefType.class);
|
||||
private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(DateTimeType.class,
|
||||
RefreshType.class);
|
||||
|
||||
public DateTimeItem(String name) {
|
||||
super(CoreItemFactory.DATETIME, name);
|
||||
@ -51,12 +43,12 @@ public class DateTimeItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return Collections.unmodifiableList(acceptedDataTypes);
|
||||
return ACCEPTED_DATA_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return Collections.unmodifiableList(acceptedCommandTypes);
|
||||
return ACCEPTED_COMMAND_TYPES;
|
||||
}
|
||||
|
||||
public void send(DateTimeType command) {
|
||||
@ -65,7 +57,7 @@ public class DateTimeItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
if (isAcceptedState(acceptedDataTypes, state)) {
|
||||
if (isAcceptedState(ACCEPTED_DATA_TYPES, state)) {
|
||||
// try conversion
|
||||
State convertedState = state.as(DateTimeType.class);
|
||||
if (convertedState != null) {
|
||||
|
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -36,19 +34,10 @@ import org.openhab.core.types.UnDefType;
|
||||
@NonNullByDefault
|
||||
public class DimmerItem extends SwitchItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<>();
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(PercentType.class);
|
||||
acceptedDataTypes.add(OnOffType.class);
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
|
||||
acceptedCommandTypes.add(PercentType.class);
|
||||
acceptedCommandTypes.add(OnOffType.class);
|
||||
acceptedCommandTypes.add(IncreaseDecreaseType.class);
|
||||
acceptedCommandTypes.add(RefreshType.class);
|
||||
}
|
||||
private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(PercentType.class, OnOffType.class,
|
||||
UnDefType.class);
|
||||
private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(PercentType.class,
|
||||
OnOffType.class, IncreaseDecreaseType.class, RefreshType.class);
|
||||
|
||||
public DimmerItem(String name) {
|
||||
super(CoreItemFactory.DIMMER, name);
|
||||
@ -64,17 +53,17 @@ public class DimmerItem extends SwitchItem {
|
||||
|
||||
@Override
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return Collections.unmodifiableList(acceptedDataTypes);
|
||||
return ACCEPTED_DATA_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return Collections.unmodifiableList(acceptedCommandTypes);
|
||||
return ACCEPTED_COMMAND_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
if (isAcceptedState(acceptedDataTypes, state)) {
|
||||
if (isAcceptedState(ACCEPTED_DATA_TYPES, state)) {
|
||||
// try conversion
|
||||
State convertedState = state.as(PercentType.class);
|
||||
if (convertedState != null) {
|
||||
|
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -33,15 +31,8 @@ import org.openhab.core.types.UnDefType;
|
||||
@NonNullByDefault
|
||||
public class ImageItem extends GenericItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<>();
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(RawType.class);
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
|
||||
acceptedCommandTypes.add(RefreshType.class);
|
||||
}
|
||||
private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(RawType.class, UnDefType.class);
|
||||
private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(RefreshType.class);
|
||||
|
||||
public ImageItem(String name) {
|
||||
super(CoreItemFactory.IMAGE, name);
|
||||
@ -49,17 +40,17 @@ public class ImageItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return Collections.unmodifiableList(acceptedDataTypes);
|
||||
return ACCEPTED_DATA_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return Collections.unmodifiableList(acceptedCommandTypes);
|
||||
return ACCEPTED_COMMAND_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
if (isAcceptedState(acceptedDataTypes, state)) {
|
||||
if (isAcceptedState(ACCEPTED_DATA_TYPES, state)) {
|
||||
super.setState(state);
|
||||
} else {
|
||||
logSetTypeError(state);
|
||||
|
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -36,16 +34,9 @@ import org.openhab.core.types.UnDefType;
|
||||
@NonNullByDefault
|
||||
public class LocationItem extends GenericItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<>();
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(PointType.class);
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
|
||||
acceptedCommandTypes.add(RefreshType.class);
|
||||
acceptedCommandTypes.add(PointType.class);
|
||||
}
|
||||
private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(PointType.class, UnDefType.class);
|
||||
private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(PointType.class,
|
||||
RefreshType.class);
|
||||
|
||||
public LocationItem(String name) {
|
||||
super(CoreItemFactory.LOCATION, name);
|
||||
@ -57,12 +48,12 @@ public class LocationItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return Collections.unmodifiableList(acceptedDataTypes);
|
||||
return ACCEPTED_DATA_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return Collections.unmodifiableList(acceptedCommandTypes);
|
||||
return ACCEPTED_COMMAND_TYPES;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,7 +75,7 @@ public class LocationItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
if (isAcceptedState(acceptedDataTypes, state)) {
|
||||
if (isAcceptedState(ACCEPTED_DATA_TYPES, state)) {
|
||||
super.setState(state);
|
||||
} else {
|
||||
logSetTypeError(state);
|
||||
|
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@ -47,22 +45,14 @@ import org.openhab.core.types.util.UnitUtils;
|
||||
@NonNullByDefault
|
||||
public class NumberItem extends GenericItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<>();
|
||||
private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(DecimalType.class,
|
||||
QuantityType.class, UnDefType.class);
|
||||
private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(DecimalType.class,
|
||||
QuantityType.class, RefreshType.class);
|
||||
|
||||
@Nullable
|
||||
private Class<? extends Quantity<?>> dimension;
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(DecimalType.class);
|
||||
acceptedDataTypes.add(QuantityType.class);
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
|
||||
acceptedCommandTypes.add(DecimalType.class);
|
||||
acceptedCommandTypes.add(QuantityType.class);
|
||||
acceptedCommandTypes.add(RefreshType.class);
|
||||
}
|
||||
|
||||
public NumberItem(String name) {
|
||||
this(CoreItemFactory.NUMBER, name);
|
||||
}
|
||||
@ -78,12 +68,12 @@ public class NumberItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return Collections.unmodifiableList(acceptedDataTypes);
|
||||
return ACCEPTED_DATA_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return Collections.unmodifiableList(acceptedCommandTypes);
|
||||
return ACCEPTED_COMMAND_TYPES;
|
||||
}
|
||||
|
||||
public void send(DecimalType command) {
|
||||
@ -93,13 +83,14 @@ public class NumberItem extends GenericItem {
|
||||
@Override
|
||||
public @Nullable StateDescription getStateDescription(@Nullable Locale locale) {
|
||||
StateDescription stateDescription = super.getStateDescription(locale);
|
||||
if (getDimension() == null && stateDescription != null && stateDescription.getPattern() != null
|
||||
&& stateDescription.getPattern().contains(UnitUtils.UNIT_PLACEHOLDER)) {
|
||||
return StateDescriptionFragmentBuilder.create(stateDescription)
|
||||
.withPattern(stateDescription.getPattern().replaceAll(UnitUtils.UNIT_PLACEHOLDER, "").trim())
|
||||
.build().toStateDescription();
|
||||
if (getDimension() == null && stateDescription != null) {
|
||||
String pattern = stateDescription.getPattern();
|
||||
if (pattern != null && pattern.contains(UnitUtils.UNIT_PLACEHOLDER)) {
|
||||
return StateDescriptionFragmentBuilder.create(stateDescription)
|
||||
.withPattern(pattern.replaceAll(UnitUtils.UNIT_PLACEHOLDER, "").trim()).build()
|
||||
.toStateDescription();
|
||||
}
|
||||
}
|
||||
|
||||
return stateDescription;
|
||||
}
|
||||
|
||||
@ -140,7 +131,7 @@ public class NumberItem extends GenericItem {
|
||||
}
|
||||
}
|
||||
|
||||
if (isAcceptedState(acceptedDataTypes, state)) {
|
||||
if (isAcceptedState(ACCEPTED_DATA_TYPES, state)) {
|
||||
super.setState(state);
|
||||
} else {
|
||||
logSetTypeError(state);
|
||||
|
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -35,19 +33,10 @@ import org.openhab.core.types.UnDefType;
|
||||
@NonNullByDefault
|
||||
public class PlayerItem extends GenericItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<>();
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(PlayPauseType.class);
|
||||
acceptedDataTypes.add(RewindFastforwardType.class);
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
|
||||
acceptedCommandTypes.add(PlayPauseType.class);
|
||||
acceptedCommandTypes.add(RewindFastforwardType.class);
|
||||
acceptedCommandTypes.add(NextPreviousType.class);
|
||||
acceptedCommandTypes.add(RefreshType.class);
|
||||
}
|
||||
private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(PlayPauseType.class,
|
||||
RewindFastforwardType.class, UnDefType.class);
|
||||
private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(PlayPauseType.class,
|
||||
RewindFastforwardType.class, NextPreviousType.class, RefreshType.class);
|
||||
|
||||
public PlayerItem(String name) {
|
||||
super(CoreItemFactory.PLAYER, name);
|
||||
@ -59,12 +48,12 @@ public class PlayerItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return Collections.unmodifiableList(acceptedDataTypes);
|
||||
return ACCEPTED_DATA_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return Collections.unmodifiableList(acceptedCommandTypes);
|
||||
return ACCEPTED_COMMAND_TYPES;
|
||||
}
|
||||
|
||||
public void send(PlayPauseType command) {
|
||||
@ -81,7 +70,7 @@ public class PlayerItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
if (isAcceptedState(acceptedDataTypes, state)) {
|
||||
if (isAcceptedState(ACCEPTED_DATA_TYPES, state)) {
|
||||
super.setState(state);
|
||||
} else {
|
||||
logSetTypeError(state);
|
||||
|
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -37,20 +35,10 @@ import org.openhab.core.types.UnDefType;
|
||||
@NonNullByDefault
|
||||
public class RollershutterItem extends GenericItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<>();
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(PercentType.class);
|
||||
acceptedDataTypes.add(UpDownType.class);
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
|
||||
acceptedCommandTypes.add(UpDownType.class);
|
||||
acceptedCommandTypes.add(StopMoveType.class);
|
||||
acceptedCommandTypes.add(PercentType.class);
|
||||
|
||||
acceptedCommandTypes.add(RefreshType.class);
|
||||
}
|
||||
private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(PercentType.class, UpDownType.class,
|
||||
UnDefType.class);
|
||||
private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(PercentType.class,
|
||||
UpDownType.class, StopMoveType.class, RefreshType.class);
|
||||
|
||||
public RollershutterItem(String name) {
|
||||
super(CoreItemFactory.ROLLERSHUTTER, name);
|
||||
@ -58,12 +46,12 @@ public class RollershutterItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return Collections.unmodifiableList(acceptedDataTypes);
|
||||
return ACCEPTED_DATA_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return Collections.unmodifiableList(acceptedCommandTypes);
|
||||
return ACCEPTED_COMMAND_TYPES;
|
||||
}
|
||||
|
||||
public void send(UpDownType command) {
|
||||
@ -80,7 +68,7 @@ public class RollershutterItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
if (isAcceptedState(acceptedDataTypes, state)) {
|
||||
if (isAcceptedState(ACCEPTED_DATA_TYPES, state)) {
|
||||
// try conversion
|
||||
State convertedState = state.as(PercentType.class);
|
||||
if (convertedState != null) {
|
||||
|
@ -13,7 +13,6 @@
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -37,17 +36,10 @@ import org.openhab.core.types.UnDefType;
|
||||
@NonNullByDefault
|
||||
public class StringItem extends GenericItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<>();
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
acceptedDataTypes.add(StringType.class);
|
||||
acceptedDataTypes.add(DateTimeType.class);
|
||||
|
||||
acceptedCommandTypes.add(RefreshType.class);
|
||||
acceptedCommandTypes.add(StringType.class);
|
||||
}
|
||||
private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(StringType.class,
|
||||
DateTimeType.class, UnDefType.class);
|
||||
private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(StringType.class,
|
||||
RefreshType.class);
|
||||
|
||||
public StringItem(String name) {
|
||||
super(CoreItemFactory.STRING, name);
|
||||
@ -59,12 +51,12 @@ public class StringItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return Collections.unmodifiableList(acceptedDataTypes);
|
||||
return ACCEPTED_DATA_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return Collections.unmodifiableList(acceptedCommandTypes);
|
||||
return ACCEPTED_COMMAND_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -81,7 +73,7 @@ public class StringItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
if (isAcceptedState(acceptedDataTypes, state)) {
|
||||
if (isAcceptedState(ACCEPTED_DATA_TYPES, state)) {
|
||||
super.setState(state);
|
||||
} else {
|
||||
logSetTypeError(state);
|
||||
|
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -34,16 +32,9 @@ import org.openhab.core.types.UnDefType;
|
||||
@NonNullByDefault
|
||||
public class SwitchItem extends GenericItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<>();
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(OnOffType.class);
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
|
||||
acceptedCommandTypes.add(OnOffType.class);
|
||||
acceptedCommandTypes.add(RefreshType.class);
|
||||
}
|
||||
private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(OnOffType.class, UnDefType.class);
|
||||
private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(OnOffType.class,
|
||||
RefreshType.class);
|
||||
|
||||
public SwitchItem(String name) {
|
||||
super(CoreItemFactory.SWITCH, name);
|
||||
@ -59,17 +50,17 @@ public class SwitchItem extends GenericItem {
|
||||
|
||||
@Override
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return Collections.unmodifiableList(acceptedDataTypes);
|
||||
return ACCEPTED_DATA_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return Collections.unmodifiableList(acceptedCommandTypes);
|
||||
return ACCEPTED_COMMAND_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
if (isAcceptedState(acceptedDataTypes, state)) {
|
||||
if (isAcceptedState(ACCEPTED_DATA_TYPES, state)) {
|
||||
super.setState(state);
|
||||
} else {
|
||||
logSetTypeError(state);
|
||||
|
Loading…
Reference in New Issue
Block a user