[homekit] support Rollershutter items for HoldPosition (#14045)
* [homekit] support Rollershutter items for HoldPosition just send STOP to them * [homekit] log a warning for incompatible HoldPosition items Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
@@ -29,9 +29,11 @@ import javax.measure.Unit;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.items.GenericItem;
|
||||
import org.openhab.core.items.Item;
|
||||
import org.openhab.core.library.items.ColorItem;
|
||||
import org.openhab.core.library.items.DimmerItem;
|
||||
import org.openhab.core.library.items.NumberItem;
|
||||
import org.openhab.core.library.items.RollershutterItem;
|
||||
import org.openhab.core.library.items.StringItem;
|
||||
import org.openhab.core.library.items.SwitchItem;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
@@ -40,6 +42,7 @@ import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.library.types.OpenClosedType;
|
||||
import org.openhab.core.library.types.PercentType;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.library.types.StopMoveType;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
import org.openhab.core.library.unit.ImperialUnits;
|
||||
import org.openhab.core.library.unit.SIUnits;
|
||||
@@ -471,7 +474,24 @@ public class HomekitCharacteristicFactory {
|
||||
|
||||
private static HoldPositionCharacteristic createHoldPositionCharacteristic(HomekitTaggedItem taggedItem,
|
||||
HomekitAccessoryUpdater updater) {
|
||||
return new HoldPositionCharacteristic(value -> ((SwitchItem) taggedItem.getItem()).send(OnOffType.from(value)));
|
||||
final Item item = taggedItem.getBaseItem();
|
||||
if (!(item instanceof SwitchItem || item instanceof RollershutterItem)) {
|
||||
logger.warn(
|
||||
"Item {} cannot be used for the HoldPosition characteristic; only SwitchItem and RollershutterItem are supported. Hold requests will be ignored.",
|
||||
item.getName());
|
||||
}
|
||||
|
||||
return new HoldPositionCharacteristic(value -> {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item instanceof SwitchItem) {
|
||||
((SwitchItem) item).send(OnOffType.ON);
|
||||
} else if (item instanceof RollershutterItem) {
|
||||
((RollershutterItem) item).send(StopMoveType.STOP);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static CarbonMonoxideLevelCharacteristic createCarbonMonoxideLevelCharacteristic(
|
||||
|
||||
Reference in New Issue
Block a user