[homekit] Checkstyle cleanup (#15450)
* Remove package * java 17 instanceofpattern * EqualsAvoidNullCheck * NoEmptyLineSeparatorCheck * ConstantNameCheck Signed-off-by: lsiepel <leosiepel@gmail.com>
This commit is contained in:
parent
24fa966dc3
commit
a1b79b6b7b
@ -230,8 +230,8 @@ public class HomekitChangeListener implements ItemRegistryChangeListener {
|
|||||||
/*
|
/*
|
||||||
* if metadata of a group item was changed, mark all group member as dirty.
|
* if metadata of a group item was changed, mark all group member as dirty.
|
||||||
*/
|
*/
|
||||||
if (item instanceof GroupItem) {
|
if (item instanceof GroupItem itemAsGroupItem) {
|
||||||
((GroupItem) item).getMembers().forEach(groupMember -> pendingUpdates.add(groupMember.getName()));
|
itemAsGroupItem.getMembers().forEach(groupMember -> pendingUpdates.add(groupMember.getName()));
|
||||||
}
|
}
|
||||||
applyUpdatesDebouncer.call();
|
applyUpdatesDebouncer.call();
|
||||||
}
|
}
|
||||||
@ -386,10 +386,9 @@ public class HomekitChangeListener implements ItemRegistryChangeListener {
|
|||||||
@Nullable Map<String, Object> configuration) {
|
@Nullable Map<String, Object> configuration) {
|
||||||
if (accessoryTypes.size() > 1 && configuration != null) {
|
if (accessoryTypes.size() > 1 && configuration != null) {
|
||||||
final @Nullable Object value = configuration.get(HomekitTaggedItem.PRIMARY_SERVICE);
|
final @Nullable Object value = configuration.get(HomekitTaggedItem.PRIMARY_SERVICE);
|
||||||
if (value instanceof String) {
|
if (value instanceof String valueAsString) {
|
||||||
return accessoryTypes.stream()
|
return accessoryTypes.stream().filter(aType -> valueAsString.equalsIgnoreCase(aType.getKey().getTag()))
|
||||||
.filter(aType -> ((String) value).equalsIgnoreCase(aType.getKey().getTag())).findAny()
|
.findAny().orElse(accessoryTypes.get(0)).getKey();
|
||||||
.orElse(accessoryTypes.get(0)).getKey();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// no primary accessory found or there is only one type, so return the first type from the list
|
// no primary accessory found or there is only one type, so return the first type from the list
|
||||||
@ -513,8 +512,8 @@ public class HomekitChangeListener implements ItemRegistryChangeListener {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
return (instance == 1);
|
return (instance == 1);
|
||||||
}
|
}
|
||||||
if (value instanceof Number) {
|
if (value instanceof Number valueAsNumber) {
|
||||||
return (instance == ((Number) value).intValue());
|
return (instance == valueAsNumber.intValue());
|
||||||
}
|
}
|
||||||
logger.warn("Unrecognized instance tag {} ({}) for item {}; assigning to default instance.", value,
|
logger.warn("Unrecognized instance tag {} ({}) for item {}; assigning to default instance.", value,
|
||||||
value.getClass(), item.getName());
|
value.getClass(), item.getName());
|
||||||
|
|||||||
@ -60,8 +60,7 @@ public class HomekitOHItemProxy {
|
|||||||
private int delay = DEFAULT_DELAY;
|
private int delay = DEFAULT_DELAY;
|
||||||
|
|
||||||
public static Item getBaseItem(Item item) {
|
public static Item getBaseItem(Item item) {
|
||||||
if (item instanceof GroupItem) {
|
if (item instanceof GroupItem groupItem) {
|
||||||
final GroupItem groupItem = (GroupItem) item;
|
|
||||||
final Item baseItem = groupItem.getBaseItem();
|
final Item baseItem = groupItem.getBaseItem();
|
||||||
if (baseItem != null) {
|
if (baseItem != null) {
|
||||||
return baseItem;
|
return baseItem;
|
||||||
@ -110,8 +109,8 @@ public class HomekitOHItemProxy {
|
|||||||
|| ((dimmerMode == DIMMER_MODE_FILTER_ON_EXCEPT_BRIGHTNESS_100) && (currentOnState != OnOffType.ON)
|
|| ((dimmerMode == DIMMER_MODE_FILTER_ON_EXCEPT_BRIGHTNESS_100) && (currentOnState != OnOffType.ON)
|
||||||
&& ((brightness == null) || (brightness.intValue() == 100)))) {
|
&& ((brightness == null) || (brightness.intValue() == 100)))) {
|
||||||
logger.trace("send OnOff command for item {} with value {}", item, on);
|
logger.trace("send OnOff command for item {} with value {}", item, on);
|
||||||
if (item instanceof GroupItem) {
|
if (item instanceof GroupItem groupItem) {
|
||||||
((GroupItem) item).send(on);
|
groupItem.send(on);
|
||||||
} else {
|
} else {
|
||||||
((DimmerItem) item).send(on);
|
((DimmerItem) item).send(on);
|
||||||
}
|
}
|
||||||
@ -120,8 +119,8 @@ public class HomekitOHItemProxy {
|
|||||||
|
|
||||||
// if hue or saturation present, send an HSBType state update. no filter applied for HUE & Saturation
|
// if hue or saturation present, send an HSBType state update. no filter applied for HUE & Saturation
|
||||||
if ((hue != null) || (saturation != null)) {
|
if ((hue != null) || (saturation != null)) {
|
||||||
if (baseItem instanceof ColorItem) {
|
if (baseItem instanceof ColorItem colorItem) {
|
||||||
sendHSBCommand((ColorItem) item, hue, saturation, brightness);
|
sendHSBCommand(colorItem, hue, saturation, brightness);
|
||||||
}
|
}
|
||||||
} else if ((brightness != null) && (baseItem instanceof DimmerItem)) {
|
} else if ((brightness != null) && (baseItem instanceof DimmerItem)) {
|
||||||
// sends brightness:
|
// sends brightness:
|
||||||
@ -132,10 +131,10 @@ public class HomekitOHItemProxy {
|
|||||||
if ((dimmerMode == DIMMER_MODE_NORMAL) || (dimmerMode == DIMMER_MODE_FILTER_ON)
|
if ((dimmerMode == DIMMER_MODE_NORMAL) || (dimmerMode == DIMMER_MODE_FILTER_ON)
|
||||||
|| (brightness.intValue() < 100) || (currentOnState == OnOffType.ON)) {
|
|| (brightness.intValue() < 100) || (currentOnState == OnOffType.ON)) {
|
||||||
logger.trace("send Brightness command for item {} with value {}", item, brightness);
|
logger.trace("send Brightness command for item {} with value {}", item, brightness);
|
||||||
if (item instanceof ColorItem) {
|
if (item instanceof ColorItem colorItem) {
|
||||||
sendHSBCommand((ColorItem) item, hue, saturation, brightness);
|
sendHSBCommand(colorItem, hue, saturation, brightness);
|
||||||
} else if (item instanceof GroupItem) {
|
} else if (item instanceof GroupItem groupItem) {
|
||||||
((GroupItem) item).send(brightness);
|
groupItem.send(brightness);
|
||||||
} else {
|
} else {
|
||||||
((DimmerItem) item).send(brightness);
|
((DimmerItem) item).send(brightness);
|
||||||
}
|
}
|
||||||
@ -152,8 +151,8 @@ public class HomekitOHItemProxy {
|
|||||||
final PercentType targetSaturation = saturation != null ? saturation : currentState.getSaturation();
|
final PercentType targetSaturation = saturation != null ? saturation : currentState.getSaturation();
|
||||||
final PercentType targetBrightness = brightness != null ? brightness : currentState.getBrightness();
|
final PercentType targetBrightness = brightness != null ? brightness : currentState.getBrightness();
|
||||||
final HSBType command = new HSBType(targetHue, targetSaturation, targetBrightness);
|
final HSBType command = new HSBType(targetHue, targetSaturation, targetBrightness);
|
||||||
if (item instanceof GroupItem) {
|
if (item instanceof GroupItem groupItem) {
|
||||||
((GroupItem) item).send(command);
|
groupItem.send(command);
|
||||||
} else {
|
} else {
|
||||||
((ColorItem) item).send(command);
|
((ColorItem) item).send(command);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -112,8 +112,8 @@ public class HomekitTaggedItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGroup() {
|
public boolean isGroup() {
|
||||||
return (isAccessory() && (proxyItem.getItem() instanceof GroupItem)
|
return (isAccessory() && (proxyItem.getItem() instanceof GroupItem groupItem)
|
||||||
&& ((GroupItem) proxyItem.getItem()).getBaseItem() == null);
|
&& groupItem.getBaseItem() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HomekitAccessoryType getAccessoryType() {
|
public HomekitAccessoryType getAccessoryType() {
|
||||||
@ -177,11 +177,11 @@ public class HomekitTaggedItem {
|
|||||||
* @param command
|
* @param command
|
||||||
*/
|
*/
|
||||||
public void send(DecimalType command) {
|
public void send(DecimalType command) {
|
||||||
if (getItem() instanceof GroupItem && getBaseItem() instanceof NumberItem) {
|
if (getItem() instanceof GroupItem groupItem && getBaseItem() instanceof NumberItem) {
|
||||||
((GroupItem) getItem()).send(command);
|
groupItem.send(command);
|
||||||
return;
|
return;
|
||||||
} else if (getItem() instanceof NumberItem) {
|
} else if (getItem() instanceof NumberItem numberItem) {
|
||||||
((NumberItem) getItem()).send(command);
|
numberItem.send(command);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.warn("Received DecimalType command for item {} that doesn't support it. This is probably a bug.",
|
logger.warn("Received DecimalType command for item {} that doesn't support it. This is probably a bug.",
|
||||||
@ -194,11 +194,11 @@ public class HomekitTaggedItem {
|
|||||||
* @param command
|
* @param command
|
||||||
*/
|
*/
|
||||||
public void send(QuantityType command) {
|
public void send(QuantityType command) {
|
||||||
if (getItem() instanceof GroupItem && getBaseItem() instanceof NumberItem) {
|
if (getItem() instanceof GroupItem groupItem && getBaseItem() instanceof NumberItem) {
|
||||||
((GroupItem) getItem()).send(command);
|
groupItem.send(command);
|
||||||
return;
|
return;
|
||||||
} else if (getItem() instanceof NumberItem) {
|
} else if (getItem() instanceof NumberItem numberItem) {
|
||||||
((NumberItem) getItem()).send(command);
|
numberItem.send(command);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.warn("Received QuantityType command for item {} that doesn't support it. This is probably a bug.",
|
logger.warn("Received QuantityType command for item {} that doesn't support it. This is probably a bug.",
|
||||||
@ -211,11 +211,11 @@ public class HomekitTaggedItem {
|
|||||||
* @param command
|
* @param command
|
||||||
*/
|
*/
|
||||||
public void send(OnOffType command) {
|
public void send(OnOffType command) {
|
||||||
if (getItem() instanceof GroupItem && getBaseItem() instanceof SwitchItem) {
|
if (getItem() instanceof GroupItem groupItem && getBaseItem() instanceof SwitchItem) {
|
||||||
((GroupItem) getItem()).send(command);
|
groupItem.send(command);
|
||||||
return;
|
return;
|
||||||
} else if (getItem() instanceof SwitchItem) {
|
} else if (getItem() instanceof SwitchItem switchItem) {
|
||||||
((SwitchItem) getItem()).send(command);
|
switchItem.send(command);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.warn("Received OnOffType command for item {} that doesn't support it. This is probably a bug.",
|
logger.warn("Received OnOffType command for item {} that doesn't support it. This is probably a bug.",
|
||||||
@ -226,11 +226,11 @@ public class HomekitTaggedItem {
|
|||||||
* Send IncreaseDecreaseType command to a DimmerItem (or a Group:Dimmer)
|
* Send IncreaseDecreaseType command to a DimmerItem (or a Group:Dimmer)
|
||||||
*/
|
*/
|
||||||
public void send(IncreaseDecreaseType command) {
|
public void send(IncreaseDecreaseType command) {
|
||||||
if (getItem() instanceof GroupItem && getBaseItem() instanceof DimmerItem) {
|
if (getItem() instanceof GroupItem groupItem && getBaseItem() instanceof DimmerItem) {
|
||||||
((GroupItem) getItem()).send(command);
|
groupItem.send(command);
|
||||||
return;
|
return;
|
||||||
} else if (getItem() instanceof DimmerItem) {
|
} else if (getItem() instanceof DimmerItem dimmerItem) {
|
||||||
((DimmerItem) getItem()).send(command);
|
dimmerItem.send(command);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.warn(
|
logger.warn(
|
||||||
@ -244,15 +244,15 @@ public class HomekitTaggedItem {
|
|||||||
* @param command
|
* @param command
|
||||||
*/
|
*/
|
||||||
public void send(PercentType command) {
|
public void send(PercentType command) {
|
||||||
if (getItem() instanceof GroupItem
|
if (getItem() instanceof GroupItem groupItem
|
||||||
&& (getBaseItem() instanceof DimmerItem || getBaseItem() instanceof RollershutterItem)) {
|
&& (getBaseItem() instanceof DimmerItem || getBaseItem() instanceof RollershutterItem)) {
|
||||||
((GroupItem) getItem()).send(command);
|
groupItem.send(command);
|
||||||
return;
|
return;
|
||||||
} else if (getItem() instanceof DimmerItem) {
|
} else if (getItem() instanceof DimmerItem dimmerItem) {
|
||||||
((DimmerItem) getItem()).send(command);
|
dimmerItem.send(command);
|
||||||
return;
|
return;
|
||||||
} else if (getItem() instanceof RollershutterItem) {
|
} else if (getItem() instanceof RollershutterItem rollerShutterItem) {
|
||||||
((RollershutterItem) getItem()).send(command);
|
rollerShutterItem.send(command);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.warn("Received PercentType command for item {} that doesn't support it. This is probably a bug.",
|
logger.warn("Received PercentType command for item {} that doesn't support it. This is probably a bug.",
|
||||||
@ -265,11 +265,11 @@ public class HomekitTaggedItem {
|
|||||||
* @param command
|
* @param command
|
||||||
*/
|
*/
|
||||||
public void send(StringType command) {
|
public void send(StringType command) {
|
||||||
if (getItem() instanceof GroupItem && getBaseItem() instanceof StringItem) {
|
if (getItem() instanceof GroupItem groupItem && getBaseItem() instanceof StringItem) {
|
||||||
((GroupItem) getItem()).send(command);
|
groupItem.send(command);
|
||||||
return;
|
return;
|
||||||
} else if (getItem() instanceof StringItem) {
|
} else if (getItem() instanceof StringItem stringItem) {
|
||||||
((StringItem) getItem()).send(command);
|
stringItem.send(command);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.warn("Received StringType command for item {} that doesn't support it. This is probably a bug.",
|
logger.warn("Received StringType command for item {} that doesn't support it. This is probably a bug.",
|
||||||
@ -350,8 +350,8 @@ public class HomekitTaggedItem {
|
|||||||
return (T) value;
|
return (T) value;
|
||||||
}
|
}
|
||||||
// fix for different handling of numbers via .items and via mainUI, see #1904
|
// fix for different handling of numbers via .items and via mainUI, see #1904
|
||||||
if ((value instanceof BigDecimal) && (defaultValue instanceof Double)) {
|
if ((value instanceof BigDecimal valueAsBigDecimal) && (defaultValue instanceof Double)) {
|
||||||
return (T) Double.valueOf(((BigDecimal) value).doubleValue());
|
return (T) Double.valueOf(valueAsBigDecimal.doubleValue());
|
||||||
}
|
}
|
||||||
if ((value instanceof Double) && (defaultValue instanceof BigDecimal)) {
|
if ((value instanceof Double) && (defaultValue instanceof BigDecimal)) {
|
||||||
return (T) BigDecimal.valueOf(((Double) value).doubleValue());
|
return (T) BigDecimal.valueOf(((Double) value).doubleValue());
|
||||||
@ -386,12 +386,11 @@ public class HomekitTaggedItem {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
if (value instanceof Boolean) {
|
if (value instanceof Boolean valueAsBoolean) {
|
||||||
return (Boolean) value;
|
return valueAsBoolean;
|
||||||
}
|
}
|
||||||
if (value instanceof String) {
|
if (value instanceof String valueString) {
|
||||||
final String valueString = (String) value;
|
return "yes".equalsIgnoreCase(valueString) || "true".equalsIgnoreCase(valueString);
|
||||||
return valueString.equalsIgnoreCase("yes") || valueString.equalsIgnoreCase("true");
|
|
||||||
}
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
@ -451,7 +450,7 @@ public class HomekitTaggedItem {
|
|||||||
// not convertible? just assume it's in the item's unit
|
// not convertible? just assume it's in the item's unit
|
||||||
if (convertedValue == null) {
|
if (convertedValue == null) {
|
||||||
Unit unit;
|
Unit unit;
|
||||||
if (getBaseItem() instanceof NumberItem && (unit = ((NumberItem) getBaseItem()).getUnit()) != null) {
|
if (getBaseItem() instanceof NumberItem numberItem && (unit = numberItem.getUnit()) != null) {
|
||||||
var bdValue = new BigDecimal(stringValue);
|
var bdValue = new BigDecimal(stringValue);
|
||||||
parsedValue = new QuantityType(bdValue, unit);
|
parsedValue = new QuantityType(bdValue, unit);
|
||||||
if (relativeConversion) {
|
if (relativeConversion) {
|
||||||
@ -474,12 +473,12 @@ public class HomekitTaggedItem {
|
|||||||
private void parseConfiguration() {
|
private void parseConfiguration() {
|
||||||
if (configuration != null) {
|
if (configuration != null) {
|
||||||
final @Nullable Object dimmerModeConfig = configuration.get(DIMMER_MODE);
|
final @Nullable Object dimmerModeConfig = configuration.get(DIMMER_MODE);
|
||||||
if (dimmerModeConfig instanceof String) {
|
if (dimmerModeConfig instanceof String dimmerModeConfigAsString) {
|
||||||
HomekitDimmerMode.valueOfTag((String) dimmerModeConfig).ifPresent(proxyItem::setDimmerMode);
|
HomekitDimmerMode.valueOfTag(dimmerModeConfigAsString).ifPresent(proxyItem::setDimmerMode);
|
||||||
}
|
}
|
||||||
final @Nullable Object delayConfig = configuration.get(DELAY);
|
final @Nullable Object delayConfig = configuration.get(DELAY);
|
||||||
if (delayConfig instanceof Number) {
|
if (delayConfig instanceof Number delayConfigNumber) {
|
||||||
proxyItem.setDelay(((Number) delayConfig).intValue());
|
proxyItem.setDelay(delayConfigNumber.intValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -218,7 +218,6 @@ public abstract class AbstractHomekitAccessoryImpl implements HomekitAccessory {
|
|||||||
} else {
|
} else {
|
||||||
logger.warn("Mandatory characteristic {} not found at accessory {}. ", characteristic,
|
logger.warn("Mandatory characteristic {} not found at accessory {}. ", characteristic,
|
||||||
accessory.getItem().getName());
|
accessory.getItem().getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,20 +87,20 @@ abstract class AbstractHomekitPositionAccessoryImpl extends AbstractHomekitAcces
|
|||||||
getCharacteristic(TARGET_POSITION).ifPresentOrElse(taggedItem -> {
|
getCharacteristic(TARGET_POSITION).ifPresentOrElse(taggedItem -> {
|
||||||
final Item item = taggedItem.getItem();
|
final Item item = taggedItem.getItem();
|
||||||
final int targetPosition = convertPosition(value, openPosition);
|
final int targetPosition = convertPosition(value, openPosition);
|
||||||
if (item instanceof RollershutterItem) {
|
if (item instanceof RollershutterItem itemAsRollerShutterItem) {
|
||||||
// HomeKit home app never sends STOP. we emulate stop if we receive 100% or 0% while the blind is moving
|
// HomeKit home app never sends STOP. we emulate stop if we receive 100% or 0% while the blind is moving
|
||||||
if (emulateState && (targetPosition == 100 && emulatedState == PositionStateEnum.DECREASING)
|
if (emulateState && (targetPosition == 100 && emulatedState == PositionStateEnum.DECREASING)
|
||||||
|| ((targetPosition == 0 && emulatedState == PositionStateEnum.INCREASING))) {
|
|| ((targetPosition == 0 && emulatedState == PositionStateEnum.INCREASING))) {
|
||||||
if (emulateStopSameDirection) {
|
if (emulateStopSameDirection) {
|
||||||
// some blinds devices do not support "STOP" but would stop if receive UP/DOWN while moving
|
// some blinds devices do not support "STOP" but would stop if receive UP/DOWN while moving
|
||||||
((RollershutterItem) item)
|
itemAsRollerShutterItem
|
||||||
.send(emulatedState == PositionStateEnum.INCREASING ? UpDownType.UP : UpDownType.DOWN);
|
.send(emulatedState == PositionStateEnum.INCREASING ? UpDownType.UP : UpDownType.DOWN);
|
||||||
} else {
|
} else {
|
||||||
((RollershutterItem) item).send(StopMoveType.STOP);
|
itemAsRollerShutterItem.send(StopMoveType.STOP);
|
||||||
}
|
}
|
||||||
emulatedState = PositionStateEnum.STOPPED;
|
emulatedState = PositionStateEnum.STOPPED;
|
||||||
} else {
|
} else {
|
||||||
((RollershutterItem) item).send(new PercentType(targetPosition));
|
itemAsRollerShutterItem.send(new PercentType(targetPosition));
|
||||||
if (emulateState) {
|
if (emulateState) {
|
||||||
@Nullable
|
@Nullable
|
||||||
PercentType currentPosition = item.getStateAs(PercentType.class);
|
PercentType currentPosition = item.getStateAs(PercentType.class);
|
||||||
@ -110,16 +110,19 @@ abstract class AbstractHomekitPositionAccessoryImpl extends AbstractHomekitAcces
|
|||||||
: PositionStateEnum.DECREASING;
|
: PositionStateEnum.DECREASING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (item instanceof DimmerItem) {
|
} else if (item instanceof DimmerItem itemAsDimmerItem) {
|
||||||
((DimmerItem) item).send(new PercentType(targetPosition));
|
itemAsDimmerItem.send(new PercentType(targetPosition));
|
||||||
} else if (item instanceof NumberItem) {
|
} else if (item instanceof NumberItem itemAsNumberItem) {
|
||||||
((NumberItem) item).send(new DecimalType(targetPosition));
|
itemAsNumberItem.send(new DecimalType(targetPosition));
|
||||||
} else if (item instanceof GroupItem && ((GroupItem) item).getBaseItem() instanceof RollershutterItem) {
|
} else if (item instanceof GroupItem itemAsGroupItem
|
||||||
((GroupItem) item).send(new PercentType(targetPosition));
|
&& itemAsGroupItem.getBaseItem() instanceof RollershutterItem) {
|
||||||
} else if (item instanceof GroupItem && ((GroupItem) item).getBaseItem() instanceof DimmerItem) {
|
itemAsGroupItem.send(new PercentType(targetPosition));
|
||||||
((GroupItem) item).send(new PercentType(targetPosition));
|
} else if (item instanceof GroupItem itemAsGroupItem
|
||||||
} else if (item instanceof GroupItem && ((GroupItem) item).getBaseItem() instanceof NumberItem) {
|
&& itemAsGroupItem.getBaseItem() instanceof DimmerItem) {
|
||||||
((GroupItem) item).send(new DecimalType(targetPosition));
|
itemAsGroupItem.send(new PercentType(targetPosition));
|
||||||
|
} else if (item instanceof GroupItem itemAsGroupItem
|
||||||
|
&& itemAsGroupItem.getBaseItem() instanceof NumberItem) {
|
||||||
|
itemAsGroupItem.send(new DecimalType(targetPosition));
|
||||||
} else {
|
} else {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Unsupported item type for characteristic {} at accessory {}. Expected Rollershutter, Dimmer or Number item, got {}",
|
"Unsupported item type for characteristic {} at accessory {}. Expected Rollershutter, Dimmer or Number item, got {}",
|
||||||
|
|||||||
@ -100,11 +100,11 @@ public class BooleanItemReader {
|
|||||||
} else if (state instanceof StringType) {
|
} else if (state instanceof StringType) {
|
||||||
return state.toString().equalsIgnoreCase("Open") || state.toString().equalsIgnoreCase("Opened");
|
return state.toString().equalsIgnoreCase("Open") || state.toString().equalsIgnoreCase("Opened");
|
||||||
} else if (localTrueThresheold != null) {
|
} else if (localTrueThresheold != null) {
|
||||||
if (state instanceof DecimalType) {
|
if (state instanceof DecimalType stateAsDecimalType) {
|
||||||
final boolean result = ((DecimalType) state).toBigDecimal().compareTo(localTrueThresheold) > 0;
|
final boolean result = stateAsDecimalType.toBigDecimal().compareTo(localTrueThresheold) > 0;
|
||||||
return result ^ invertThreshold;
|
return result ^ invertThreshold;
|
||||||
} else if (state instanceof QuantityType) {
|
} else if (state instanceof QuantityType stateAsQuantityType) {
|
||||||
final boolean result = ((QuantityType<?>) state).toBigDecimal().compareTo(localTrueThresheold) > 0;
|
final boolean result = stateAsQuantityType.toBigDecimal().compareTo(localTrueThresheold) > 0;
|
||||||
return result ^ invertThreshold;
|
return result ^ invertThreshold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,10 +118,10 @@ public class BooleanItemReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setValue(Boolean value) {
|
void setValue(Boolean value) {
|
||||||
if (item instanceof SwitchItem) {
|
if (item instanceof SwitchItem switchItem) {
|
||||||
((SwitchItem) item).send(value ? trueOnOffValue : getOffValue(trueOnOffValue));
|
switchItem.send(value ? trueOnOffValue : getOffValue(trueOnOffValue));
|
||||||
} else if (item instanceof GroupItem) {
|
} else if (item instanceof GroupItem groupItem) {
|
||||||
((GroupItem) item).send(value ? trueOnOffValue : getOffValue(trueOnOffValue));
|
groupItem.send(value ? trueOnOffValue : getOffValue(trueOnOffValue));
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Cannot set value {} for item {}. Only Switch and Group items are supported.", value, item);
|
logger.debug("Cannot set value {} for item {}. Only Switch and Group items are supported.", value, item);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,7 +62,7 @@ import io.github.hapjava.characteristics.impl.common.NameCharacteristic;
|
|||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class HomekitAccessoryFactory {
|
public class HomekitAccessoryFactory {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(HomekitAccessoryFactory.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(HomekitAccessoryFactory.class);
|
||||||
public static final String METADATA_KEY = "homekit"; // prefix for HomeKit meta information in items.xml
|
public static final String METADATA_KEY = "homekit"; // prefix for HomeKit meta information in items.xml
|
||||||
|
|
||||||
/** List of mandatory attributes for each accessory type. **/
|
/** List of mandatory attributes for each accessory type. **/
|
||||||
@ -192,12 +192,12 @@ public class HomekitAccessoryFactory {
|
|||||||
HomekitAccessoryUpdater updater, HomekitSettings settings, Set<HomekitTaggedItem> ancestorServices)
|
HomekitAccessoryUpdater updater, HomekitSettings settings, Set<HomekitTaggedItem> ancestorServices)
|
||||||
throws HomekitException {
|
throws HomekitException {
|
||||||
final HomekitAccessoryType accessoryType = taggedItem.getAccessoryType();
|
final HomekitAccessoryType accessoryType = taggedItem.getAccessoryType();
|
||||||
logger.trace("Constructing {} of accessory type {}", taggedItem.getName(), accessoryType.getTag());
|
LOGGER.trace("Constructing {} of accessory type {}", taggedItem.getName(), accessoryType.getTag());
|
||||||
final List<HomekitTaggedItem> foundCharacteristics = getMandatoryCharacteristicsFromItem(taggedItem,
|
final List<HomekitTaggedItem> foundCharacteristics = getMandatoryCharacteristicsFromItem(taggedItem,
|
||||||
metadataRegistry);
|
metadataRegistry);
|
||||||
final List<HomekitCharacteristicType> mandatoryCharacteristics = getRequiredCharacteristics(taggedItem);
|
final List<HomekitCharacteristicType> mandatoryCharacteristics = getRequiredCharacteristics(taggedItem);
|
||||||
if (foundCharacteristics.size() < mandatoryCharacteristics.size()) {
|
if (foundCharacteristics.size() < mandatoryCharacteristics.size()) {
|
||||||
logger.warn("Accessory of type {} must have following characteristics {}. Found only {}",
|
LOGGER.warn("Accessory of type {} must have following characteristics {}. Found only {}",
|
||||||
accessoryType.getTag(), mandatoryCharacteristics, foundCharacteristics);
|
accessoryType.getTag(), mandatoryCharacteristics, foundCharacteristics);
|
||||||
throw new HomekitException("Missing mandatory characteristics");
|
throw new HomekitException("Missing mandatory characteristics");
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ public class HomekitAccessoryFactory {
|
|||||||
.get(accessoryType);
|
.get(accessoryType);
|
||||||
if (accessoryImplClass != null) {
|
if (accessoryImplClass != null) {
|
||||||
if (ancestorServices.contains(taggedItem)) {
|
if (ancestorServices.contains(taggedItem)) {
|
||||||
logger.warn("Item {} has already been created. Perhaps you have circular Homekit accessory groups?",
|
LOGGER.warn("Item {} has already been created. Perhaps you have circular Homekit accessory groups?",
|
||||||
taggedItem.getName());
|
taggedItem.getName());
|
||||||
throw new HomekitException("Circular accessory references");
|
throw new HomekitException("Circular accessory references");
|
||||||
}
|
}
|
||||||
@ -221,12 +221,12 @@ public class HomekitAccessoryFactory {
|
|||||||
addLinkedServices(taggedItem, accessoryImpl, metadataRegistry, updater, settings, ancestorServices);
|
addLinkedServices(taggedItem, accessoryImpl, metadataRegistry, updater, settings, ancestorServices);
|
||||||
return accessoryImpl;
|
return accessoryImpl;
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Unsupported HomeKit type: {}", accessoryType.getTag());
|
LOGGER.warn("Unsupported HomeKit type: {}", accessoryType.getTag());
|
||||||
throw new HomekitException("Unsupported HomeKit type: " + accessoryType);
|
throw new HomekitException("Unsupported HomeKit type: " + accessoryType);
|
||||||
}
|
}
|
||||||
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException
|
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException
|
||||||
| InvocationTargetException e) {
|
| InvocationTargetException e) {
|
||||||
logger.warn("Cannot instantiate accessory implementation for accessory {}", accessoryType.getTag(), e);
|
LOGGER.warn("Cannot instantiate accessory implementation for accessory {}", accessoryType.getTag(), e);
|
||||||
throw new HomekitException("Cannot instantiate accessory implementation for accessory " + accessoryType);
|
throw new HomekitException("Cannot instantiate accessory implementation for accessory " + accessoryType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,9 +281,9 @@ public class HomekitAccessoryFactory {
|
|||||||
public static List<GroupItem> getAccessoryGroups(Item item, ItemRegistry itemRegistry,
|
public static List<GroupItem> getAccessoryGroups(Item item, ItemRegistry itemRegistry,
|
||||||
MetadataRegistry metadataRegistry) {
|
MetadataRegistry metadataRegistry) {
|
||||||
return item.getGroupNames().stream().flatMap(name -> {
|
return item.getGroupNames().stream().flatMap(name -> {
|
||||||
final @Nullable Item groupItem = itemRegistry.get(name);
|
final @Nullable Item itemFromRegistry = itemRegistry.get(name);
|
||||||
if (groupItem instanceof GroupItem) {
|
if (itemFromRegistry instanceof GroupItem groupItem) {
|
||||||
return Stream.of((GroupItem) groupItem);
|
return Stream.of(groupItem);
|
||||||
} else {
|
} else {
|
||||||
return Stream.empty();
|
return Stream.empty();
|
||||||
}
|
}
|
||||||
@ -308,7 +308,7 @@ public class HomekitAccessoryFactory {
|
|||||||
} else {
|
} else {
|
||||||
addMandatoryCharacteristics(taggedItem, collectedCharacteristics, taggedItem.getItem(), metadataRegistry);
|
addMandatoryCharacteristics(taggedItem, collectedCharacteristics, taggedItem.getItem(), metadataRegistry);
|
||||||
}
|
}
|
||||||
logger.trace("Mandatory characteristics: {}", collectedCharacteristics);
|
LOGGER.trace("Mandatory characteristics: {}", collectedCharacteristics);
|
||||||
return collectedCharacteristics;
|
return collectedCharacteristics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,7 +391,7 @@ public class HomekitAccessoryFactory {
|
|||||||
accessory.getUpdater());
|
accessory.getUpdater());
|
||||||
accessory.addCharacteristic(optionalItem, characteristic);
|
accessory.addCharacteristic(optionalItem, characteristic);
|
||||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | HomekitException e) {
|
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | HomekitException e) {
|
||||||
logger.warn("Unsupported optional HomeKit characteristic: type {}, characteristic type {}",
|
LOGGER.warn("Unsupported optional HomeKit characteristic: type {}, characteristic type {}",
|
||||||
accessory.getPrimaryService(), type.getTag());
|
accessory.getPrimaryService(), type.getTag());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -449,13 +449,13 @@ public class HomekitAccessoryFactory {
|
|||||||
var accessoryTypes = characteristicTypes.stream().filter(HomekitAccessoryFactory::isRootAccessory)
|
var accessoryTypes = characteristicTypes.stream().filter(HomekitAccessoryFactory::isRootAccessory)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
logger.trace("accessory types for {} are {}", groupMember.getName(), accessoryTypes);
|
LOGGER.trace("accessory types for {} are {}", groupMember.getName(), accessoryTypes);
|
||||||
if (accessoryTypes.isEmpty()) {
|
if (accessoryTypes.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accessoryTypes.size() > 1) {
|
if (accessoryTypes.size() > 1) {
|
||||||
logger.warn("Item {} is a HomeKit sub-accessory, but multiple accessory types are not allowed.",
|
LOGGER.warn("Item {} is a HomeKit sub-accessory, but multiple accessory types are not allowed.",
|
||||||
groupMember.getName());
|
groupMember.getName());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -463,7 +463,7 @@ public class HomekitAccessoryFactory {
|
|||||||
final @Nullable Map<String, Object> itemConfiguration = getItemConfiguration(groupMember, metadataRegistry);
|
final @Nullable Map<String, Object> itemConfiguration = getItemConfiguration(groupMember, metadataRegistry);
|
||||||
|
|
||||||
final var accessoryType = accessoryTypes.iterator().next().getKey();
|
final var accessoryType = accessoryTypes.iterator().next().getKey();
|
||||||
logger.trace("Item {} is a HomeKit sub-accessory of type {}.", groupMember.getName(), accessoryType);
|
LOGGER.trace("Item {} is a HomeKit sub-accessory of type {}.", groupMember.getName(), accessoryType);
|
||||||
final var itemProxy = new HomekitOHItemProxy(groupMember);
|
final var itemProxy = new HomekitOHItemProxy(groupMember);
|
||||||
final var subTaggedItem = new HomekitTaggedItem(itemProxy, accessoryType, itemConfiguration);
|
final var subTaggedItem = new HomekitTaggedItem(itemProxy, accessoryType, itemConfiguration);
|
||||||
final var subAccessory = create(subTaggedItem, metadataRegistry, updater, settings, ancestorServices);
|
final var subAccessory = create(subTaggedItem, metadataRegistry, updater, settings, ancestorServices);
|
||||||
@ -507,7 +507,7 @@ public class HomekitAccessoryFactory {
|
|||||||
.forEach(characteristic -> characteristicItems.put(characteristic.getValue(),
|
.forEach(characteristic -> characteristicItems.put(characteristic.getValue(),
|
||||||
(GenericItem) taggedItem.getItem()));
|
(GenericItem) taggedItem.getItem()));
|
||||||
}
|
}
|
||||||
logger.trace("Optional characteristics for item {}: {}", taggedItem.getName(), characteristicItems.values());
|
LOGGER.trace("Optional characteristics for item {}: {}", taggedItem.getName(), characteristicItems.values());
|
||||||
return Collections.unmodifiableMap(characteristicItems);
|
return Collections.unmodifiableMap(characteristicItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -151,7 +151,6 @@ import io.github.hapjava.characteristics.impl.windowcovering.CurrentVerticalTilt
|
|||||||
import io.github.hapjava.characteristics.impl.windowcovering.HoldPositionCharacteristic;
|
import io.github.hapjava.characteristics.impl.windowcovering.HoldPositionCharacteristic;
|
||||||
import io.github.hapjava.characteristics.impl.windowcovering.TargetHorizontalTiltAngleCharacteristic;
|
import io.github.hapjava.characteristics.impl.windowcovering.TargetHorizontalTiltAngleCharacteristic;
|
||||||
import io.github.hapjava.characteristics.impl.windowcovering.TargetVerticalTiltAngleCharacteristic;
|
import io.github.hapjava.characteristics.impl.windowcovering.TargetVerticalTiltAngleCharacteristic;
|
||||||
import tech.units.indriya.unit.UnitDimension;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an optional characteristics .
|
* Creates an optional characteristics .
|
||||||
@ -160,10 +159,10 @@ import tech.units.indriya.unit.UnitDimension;
|
|||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class HomekitCharacteristicFactory {
|
public class HomekitCharacteristicFactory {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(HomekitCharacteristicFactory.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(HomekitCharacteristicFactory.class);
|
||||||
|
|
||||||
// List of optional characteristics and corresponding method to create them.
|
// List of optional characteristics and corresponding method to create them.
|
||||||
private static final Map<HomekitCharacteristicType, BiFunction<HomekitTaggedItem, HomekitAccessoryUpdater, Characteristic>> optional = new HashMap<HomekitCharacteristicType, BiFunction<HomekitTaggedItem, HomekitAccessoryUpdater, Characteristic>>() {
|
private static final Map<HomekitCharacteristicType, BiFunction<HomekitTaggedItem, HomekitAccessoryUpdater, Characteristic>> OPTIONAL = new HashMap<HomekitCharacteristicType, BiFunction<HomekitTaggedItem, HomekitAccessoryUpdater, Characteristic>>() {
|
||||||
{
|
{
|
||||||
put(NAME, HomekitCharacteristicFactory::createNameCharacteristic);
|
put(NAME, HomekitCharacteristicFactory::createNameCharacteristic);
|
||||||
put(BATTERY_LOW_STATUS, HomekitCharacteristicFactory::createStatusLowBatteryCharacteristic);
|
put(BATTERY_LOW_STATUS, HomekitCharacteristicFactory::createStatusLowBatteryCharacteristic);
|
||||||
@ -234,9 +233,9 @@ public class HomekitCharacteristicFactory {
|
|||||||
public static @Nullable Characteristic createNullableCharacteristic(HomekitTaggedItem item,
|
public static @Nullable Characteristic createNullableCharacteristic(HomekitTaggedItem item,
|
||||||
HomekitAccessoryUpdater updater) {
|
HomekitAccessoryUpdater updater) {
|
||||||
final @Nullable HomekitCharacteristicType type = item.getCharacteristicType();
|
final @Nullable HomekitCharacteristicType type = item.getCharacteristicType();
|
||||||
logger.trace("Create characteristic {}", item);
|
LOGGER.trace("Create characteristic {}", item);
|
||||||
if (optional.containsKey(type)) {
|
if (OPTIONAL.containsKey(type)) {
|
||||||
return optional.get(type).apply(item, updater);
|
return OPTIONAL.get(type).apply(item, updater);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -255,7 +254,7 @@ public class HomekitCharacteristicFactory {
|
|||||||
return characteristic;
|
return characteristic;
|
||||||
}
|
}
|
||||||
final @Nullable HomekitCharacteristicType type = item.getCharacteristicType();
|
final @Nullable HomekitCharacteristicType type = item.getCharacteristicType();
|
||||||
logger.warn("Unsupported optional characteristic from item {}. Accessory type {}, characteristic type {}",
|
LOGGER.warn("Unsupported optional characteristic from item {}. Accessory type {}, characteristic type {}",
|
||||||
item.getName(), item.getAccessoryType(), type.getTag());
|
item.getName(), item.getAccessoryType(), type.getTag());
|
||||||
throw new HomekitException(
|
throw new HomekitException(
|
||||||
"Unsupported optional characteristic. Characteristic type \"" + type.getTag() + "\"");
|
"Unsupported optional characteristic. Characteristic type \"" + type.getTag() + "\"");
|
||||||
@ -328,7 +327,7 @@ public class HomekitCharacteristicFactory {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
logger.debug("Created {} mapping for item {} ({}): {}", klazz.getSimpleName(), item.getName(),
|
LOGGER.debug("Created {} mapping for item {} ({}): {}", klazz.getSimpleName(), item.getName(),
|
||||||
item.getBaseItem().getClass().getSimpleName(), map);
|
item.getBaseItem().getClass().getSimpleName(), map);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@ -355,7 +354,7 @@ public class HomekitCharacteristicFactory {
|
|||||||
*/
|
*/
|
||||||
public static <T> T getKeyFromMapping(HomekitTaggedItem item, Map<T, String> mapping, T defaultValue) {
|
public static <T> T getKeyFromMapping(HomekitTaggedItem item, Map<T, String> mapping, T defaultValue) {
|
||||||
final State state = item.getItem().getState();
|
final State state = item.getItem().getState();
|
||||||
logger.trace("getKeyFromMapping: characteristic {}, state {}, mapping {}", item.getAccessoryType().getTag(),
|
LOGGER.trace("getKeyFromMapping: characteristic {}, state {}, mapping {}", item.getAccessoryType().getTag(),
|
||||||
state, mapping);
|
state, mapping);
|
||||||
|
|
||||||
String value;
|
String value;
|
||||||
@ -370,7 +369,7 @@ public class HomekitCharacteristicFactory {
|
|||||||
// We specifically want DecimalType, but _not_ PercentType or HSBType, so don't use instanceof
|
// We specifically want DecimalType, but _not_ PercentType or HSBType, so don't use instanceof
|
||||||
value = Integer.toString(((DecimalType) state).intValue());
|
value = Integer.toString(((DecimalType) state).intValue());
|
||||||
} else {
|
} else {
|
||||||
logger.warn(
|
LOGGER.warn(
|
||||||
"Wrong value type {} ({}) for {} characteristic of the item {}. Expected StringItem, NumberItem, or SwitchItem.",
|
"Wrong value type {} ({}) for {} characteristic of the item {}. Expected StringItem, NumberItem, or SwitchItem.",
|
||||||
state.toString(), state.getClass().getSimpleName(), item.getAccessoryType().getTag(),
|
state.toString(), state.getClass().getSimpleName(), item.getAccessoryType().getTag(),
|
||||||
item.getName());
|
item.getName());
|
||||||
@ -379,7 +378,7 @@ public class HomekitCharacteristicFactory {
|
|||||||
|
|
||||||
return mapping.entrySet().stream().filter(entry -> value.equalsIgnoreCase(entry.getValue())).findAny()
|
return mapping.entrySet().stream().filter(entry -> value.equalsIgnoreCase(entry.getValue())).findAny()
|
||||||
.map(Map.Entry::getKey).orElseGet(() -> {
|
.map(Map.Entry::getKey).orElseGet(() -> {
|
||||||
logger.warn(
|
LOGGER.warn(
|
||||||
"Wrong value {} for {} characteristic of the item {}. Expected one of following {}. Returning {}.",
|
"Wrong value {} for {} characteristic of the item {}. Expected one of following {}. Returning {}.",
|
||||||
state.toString(), item.getAccessoryType().getTag(), item.getName(), mapping.values(),
|
state.toString(), item.getAccessoryType().getTag(), item.getName(), mapping.values(),
|
||||||
defaultValue);
|
defaultValue);
|
||||||
@ -414,15 +413,15 @@ public class HomekitCharacteristicFactory {
|
|||||||
private static int getIntFromItem(HomekitTaggedItem taggedItem, int defaultValue) {
|
private static int getIntFromItem(HomekitTaggedItem taggedItem, int defaultValue) {
|
||||||
int value = defaultValue;
|
int value = defaultValue;
|
||||||
final State state = taggedItem.getItem().getState();
|
final State state = taggedItem.getItem().getState();
|
||||||
if (state instanceof PercentType) {
|
if (state instanceof PercentType stateAsPercentType) {
|
||||||
value = ((PercentType) state).intValue();
|
value = stateAsPercentType.intValue();
|
||||||
} else if (state instanceof DecimalType) {
|
} else if (state instanceof DecimalType stateAsDecimalType) {
|
||||||
value = ((DecimalType) state).intValue();
|
value = stateAsDecimalType.intValue();
|
||||||
} else if (state instanceof UnDefType) {
|
} else if (state instanceof UnDefType) {
|
||||||
logger.debug("Item state {} is UNDEF {}. Returning default value {}", state, taggedItem.getName(),
|
LOGGER.debug("Item state {} is UNDEF {}. Returning default value {}", state, taggedItem.getName(),
|
||||||
defaultValue);
|
defaultValue);
|
||||||
} else {
|
} else {
|
||||||
logger.warn(
|
LOGGER.warn(
|
||||||
"Item state {} is not supported for {}. Only PercentType and DecimalType (0/100) are supported.",
|
"Item state {} is not supported for {}. Only PercentType and DecimalType (0/100) are supported.",
|
||||||
state, taggedItem.getName());
|
state, taggedItem.getName());
|
||||||
}
|
}
|
||||||
@ -433,8 +432,8 @@ public class HomekitCharacteristicFactory {
|
|||||||
private static int getAngleFromItem(HomekitTaggedItem taggedItem, int defaultValue) {
|
private static int getAngleFromItem(HomekitTaggedItem taggedItem, int defaultValue) {
|
||||||
int value = defaultValue;
|
int value = defaultValue;
|
||||||
final State state = taggedItem.getItem().getState();
|
final State state = taggedItem.getItem().getState();
|
||||||
if (state instanceof PercentType) {
|
if (state instanceof PercentType stateAsPercentType) {
|
||||||
value = (int) ((((PercentType) state).intValue() * 90.0) / 50.0 - 90.0);
|
value = (int) ((stateAsPercentType.intValue() * 90.0) / 50.0 - 90.0);
|
||||||
} else {
|
} else {
|
||||||
value = getIntFromItem(taggedItem, defaultValue);
|
value = getIntFromItem(taggedItem, defaultValue);
|
||||||
}
|
}
|
||||||
@ -451,9 +450,8 @@ public class HomekitCharacteristicFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state instanceof QuantityType<?>) {
|
if (state instanceof QuantityType<?> qt) {
|
||||||
final QuantityType<?> qt = (QuantityType<?>) state;
|
if (qt.getDimension().equals(SIUnits.CELSIUS.getDimension())) {
|
||||||
if (qt.getDimension().equals(UnitDimension.TEMPERATURE)) {
|
|
||||||
return qt.toUnit(SIUnits.CELSIUS).doubleValue();
|
return qt.toUnit(SIUnits.CELSIUS).doubleValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -488,7 +486,7 @@ public class HomekitCharacteristicFactory {
|
|||||||
if (taggedItem.getBaseItem() instanceof NumberItem) {
|
if (taggedItem.getBaseItem() instanceof NumberItem) {
|
||||||
taggedItem.send(new DecimalType(value));
|
taggedItem.send(new DecimalType(value));
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Item type {} is not supported for {}. Only NumberItem is supported.",
|
LOGGER.warn("Item type {} is not supported for {}. Only NumberItem is supported.",
|
||||||
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -501,7 +499,7 @@ public class HomekitCharacteristicFactory {
|
|||||||
} else if (taggedItem.getBaseItem() instanceof DimmerItem) {
|
} else if (taggedItem.getBaseItem() instanceof DimmerItem) {
|
||||||
taggedItem.send(new PercentType(value));
|
taggedItem.send(new PercentType(value));
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Item type {} is not supported for {}. Only DimmerItem and NumberItem are supported.",
|
LOGGER.warn("Item type {} is not supported for {}. Only DimmerItem and NumberItem are supported.",
|
||||||
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -515,7 +513,7 @@ public class HomekitCharacteristicFactory {
|
|||||||
value = (int) (value * 50.0 / 90.0 + 50.0);
|
value = (int) (value * 50.0 / 90.0 + 50.0);
|
||||||
taggedItem.send(new PercentType(value));
|
taggedItem.send(new PercentType(value));
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Item type {} is not supported for {}. Only DimmerItem and NumberItem are supported.",
|
LOGGER.warn("Item type {} is not supported for {}. Only DimmerItem and NumberItem are supported.",
|
||||||
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -526,12 +524,12 @@ public class HomekitCharacteristicFactory {
|
|||||||
return () -> {
|
return () -> {
|
||||||
final State state = taggedItem.getItem().getState();
|
final State state = taggedItem.getItem().getState();
|
||||||
double value = defaultValue;
|
double value = defaultValue;
|
||||||
if (state instanceof PercentType) {
|
if (state instanceof PercentType stateAsPercentType) {
|
||||||
value = ((PercentType) state).doubleValue();
|
value = stateAsPercentType.doubleValue();
|
||||||
} else if (state instanceof DecimalType) {
|
} else if (state instanceof DecimalType stateAsDecimalType) {
|
||||||
value = ((DecimalType) state).doubleValue();
|
value = stateAsDecimalType.doubleValue();
|
||||||
} else if (state instanceof QuantityType) {
|
} else if (state instanceof QuantityType stateAsQuantityType) {
|
||||||
value = ((QuantityType) state).doubleValue();
|
value = stateAsQuantityType.doubleValue();
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(value);
|
return CompletableFuture.completedFuture(value);
|
||||||
};
|
};
|
||||||
@ -544,7 +542,7 @@ public class HomekitCharacteristicFactory {
|
|||||||
} else if (taggedItem.getBaseItem() instanceof DimmerItem) {
|
} else if (taggedItem.getBaseItem() instanceof DimmerItem) {
|
||||||
taggedItem.send(new PercentType(value.intValue()));
|
taggedItem.send(new PercentType(value.intValue()));
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Item type {} is not supported for {}. Only Number and Dimmer type are supported.",
|
LOGGER.warn("Item type {} is not supported for {}. Only Number and Dimmer type are supported.",
|
||||||
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -563,7 +561,7 @@ public class HomekitCharacteristicFactory {
|
|||||||
if (taggedItem.getBaseItem() instanceof NumberItem) {
|
if (taggedItem.getBaseItem() instanceof NumberItem) {
|
||||||
taggedItem.send(new DecimalType(convertFromCelsius(value)));
|
taggedItem.send(new DecimalType(convertFromCelsius(value)));
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Item type {} is not supported for {}. Only Number type is supported.",
|
LOGGER.warn("Item type {} is not supported for {}. Only Number type is supported.",
|
||||||
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -638,7 +636,7 @@ public class HomekitCharacteristicFactory {
|
|||||||
HomekitAccessoryUpdater updater) {
|
HomekitAccessoryUpdater updater) {
|
||||||
final Item item = taggedItem.getBaseItem();
|
final Item item = taggedItem.getBaseItem();
|
||||||
if (!(item instanceof SwitchItem || item instanceof RollershutterItem)) {
|
if (!(item instanceof SwitchItem || item instanceof RollershutterItem)) {
|
||||||
logger.warn(
|
LOGGER.warn(
|
||||||
"Item {} cannot be used for the HoldPosition characteristic; only SwitchItem and RollershutterItem are supported. Hold requests will be ignored.",
|
"Item {} cannot be used for the HoldPosition characteristic; only SwitchItem and RollershutterItem are supported. Hold requests will be ignored.",
|
||||||
item.getName());
|
item.getName());
|
||||||
}
|
}
|
||||||
@ -648,10 +646,10 @@ public class HomekitCharacteristicFactory {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item instanceof SwitchItem) {
|
if (item instanceof SwitchItem switchItem) {
|
||||||
((SwitchItem) item).send(OnOffType.ON);
|
switchItem.send(OnOffType.ON);
|
||||||
} else if (item instanceof RollershutterItem) {
|
} else if (item instanceof RollershutterItem rollerShutterItem) {
|
||||||
((RollershutterItem) item).send(StopMoveType.STOP);
|
rollerShutterItem.send(StopMoveType.STOP);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -743,15 +741,15 @@ public class HomekitCharacteristicFactory {
|
|||||||
return new HueCharacteristic(() -> {
|
return new HueCharacteristic(() -> {
|
||||||
double value = 0.0;
|
double value = 0.0;
|
||||||
State state = taggedItem.getItem().getState();
|
State state = taggedItem.getItem().getState();
|
||||||
if (state instanceof HSBType) {
|
if (state instanceof HSBType stateAsHSBType) {
|
||||||
value = ((HSBType) state).getHue().doubleValue();
|
value = stateAsHSBType.getHue().doubleValue();
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(value);
|
return CompletableFuture.completedFuture(value);
|
||||||
}, (hue) -> {
|
}, (hue) -> {
|
||||||
if (taggedItem.getBaseItem() instanceof ColorItem) {
|
if (taggedItem.getBaseItem() instanceof ColorItem) {
|
||||||
taggedItem.sendCommandProxy(HomekitCommandType.HUE_COMMAND, new DecimalType(hue));
|
taggedItem.sendCommandProxy(HomekitCommandType.HUE_COMMAND, new DecimalType(hue));
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Item type {} is not supported for {}. Only Color type is supported.",
|
LOGGER.warn("Item type {} is not supported for {}. Only Color type is supported.",
|
||||||
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
||||||
}
|
}
|
||||||
}, getSubscriber(taggedItem, HUE, updater), getUnsubscriber(taggedItem, HUE, updater));
|
}, getSubscriber(taggedItem, HUE, updater), getUnsubscriber(taggedItem, HUE, updater));
|
||||||
@ -762,17 +760,17 @@ public class HomekitCharacteristicFactory {
|
|||||||
return new BrightnessCharacteristic(() -> {
|
return new BrightnessCharacteristic(() -> {
|
||||||
int value = 0;
|
int value = 0;
|
||||||
final State state = taggedItem.getItem().getState();
|
final State state = taggedItem.getItem().getState();
|
||||||
if (state instanceof HSBType) {
|
if (state instanceof HSBType stateAsHSBType) {
|
||||||
value = ((HSBType) state).getBrightness().intValue();
|
value = stateAsHSBType.getBrightness().intValue();
|
||||||
} else if (state instanceof PercentType) {
|
} else if (state instanceof PercentType stateAsPercentType) {
|
||||||
value = ((PercentType) state).intValue();
|
value = stateAsPercentType.intValue();
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(value);
|
return CompletableFuture.completedFuture(value);
|
||||||
}, (brightness) -> {
|
}, (brightness) -> {
|
||||||
if (taggedItem.getBaseItem() instanceof DimmerItem) {
|
if (taggedItem.getBaseItem() instanceof DimmerItem) {
|
||||||
taggedItem.sendCommandProxy(HomekitCommandType.BRIGHTNESS_COMMAND, new PercentType(brightness));
|
taggedItem.sendCommandProxy(HomekitCommandType.BRIGHTNESS_COMMAND, new PercentType(brightness));
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Item type {} is not supported for {}. Only ColorItem and DimmerItem are supported.",
|
LOGGER.warn("Item type {} is not supported for {}. Only ColorItem and DimmerItem are supported.",
|
||||||
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
||||||
}
|
}
|
||||||
}, getSubscriber(taggedItem, BRIGHTNESS, updater), getUnsubscriber(taggedItem, BRIGHTNESS, updater));
|
}, getSubscriber(taggedItem, BRIGHTNESS, updater), getUnsubscriber(taggedItem, BRIGHTNESS, updater));
|
||||||
@ -783,10 +781,10 @@ public class HomekitCharacteristicFactory {
|
|||||||
return new SaturationCharacteristic(() -> {
|
return new SaturationCharacteristic(() -> {
|
||||||
double value = 0.0;
|
double value = 0.0;
|
||||||
State state = taggedItem.getItem().getState();
|
State state = taggedItem.getItem().getState();
|
||||||
if (state instanceof HSBType) {
|
if (state instanceof HSBType stateAsHSBType) {
|
||||||
value = ((HSBType) state).getSaturation().doubleValue();
|
value = stateAsHSBType.getSaturation().doubleValue();
|
||||||
} else if (state instanceof PercentType) {
|
} else if (state instanceof PercentType stateAsPercentType) {
|
||||||
value = ((PercentType) state).doubleValue();
|
value = stateAsPercentType.doubleValue();
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(value);
|
return CompletableFuture.completedFuture(value);
|
||||||
}, (saturation) -> {
|
}, (saturation) -> {
|
||||||
@ -794,7 +792,7 @@ public class HomekitCharacteristicFactory {
|
|||||||
taggedItem.sendCommandProxy(HomekitCommandType.SATURATION_COMMAND,
|
taggedItem.sendCommandProxy(HomekitCommandType.SATURATION_COMMAND,
|
||||||
new PercentType(saturation.intValue()));
|
new PercentType(saturation.intValue()));
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Item type {} is not supported for {}. Only Color type is supported.",
|
LOGGER.warn("Item type {} is not supported for {}. Only Color type is supported.",
|
||||||
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
taggedItem.getBaseItem().getType(), taggedItem.getName());
|
||||||
}
|
}
|
||||||
}, getSubscriber(taggedItem, SATURATION, updater), getUnsubscriber(taggedItem, SATURATION, updater));
|
}, getSubscriber(taggedItem, SATURATION, updater), getUnsubscriber(taggedItem, SATURATION, updater));
|
||||||
@ -826,17 +824,16 @@ public class HomekitCharacteristicFactory {
|
|||||||
return new ColorTemperatureCharacteristic(minValue, maxValue, () -> {
|
return new ColorTemperatureCharacteristic(minValue, maxValue, () -> {
|
||||||
int value = finalMinValue;
|
int value = finalMinValue;
|
||||||
final State state = taggedItem.getItem().getState();
|
final State state = taggedItem.getItem().getState();
|
||||||
if (state instanceof QuantityType<?>) {
|
if (state instanceof QuantityType<?> qt) {
|
||||||
// Number:Temperature
|
// Number:Temperature
|
||||||
QuantityType<?> qt = (QuantityType<?>) state;
|
|
||||||
qt = qt.toInvertibleUnit(Units.MIRED);
|
qt = qt.toInvertibleUnit(Units.MIRED);
|
||||||
if (qt == null) {
|
if (qt == null) {
|
||||||
logger.warn("Item {}'s state '{}' is not convertible to mireds.", taggedItem.getName(), state);
|
LOGGER.warn("Item {}'s state '{}' is not convertible to mireds.", taggedItem.getName(), state);
|
||||||
} else {
|
} else {
|
||||||
value = qt.intValue();
|
value = qt.intValue();
|
||||||
}
|
}
|
||||||
} else if (state instanceof PercentType) {
|
} else if (state instanceof PercentType stateAsPercentType) {
|
||||||
double percent = ((PercentType) state).doubleValue();
|
double percent = stateAsPercentType.doubleValue();
|
||||||
// invert so that 0% == coolest
|
// invert so that 0% == coolest
|
||||||
if (inverted) {
|
if (inverted) {
|
||||||
percent = 100.0 - percent;
|
percent = 100.0 - percent;
|
||||||
@ -845,8 +842,8 @@ public class HomekitCharacteristicFactory {
|
|||||||
// Dimmer
|
// Dimmer
|
||||||
// scale to the originally configured range
|
// scale to the originally configured range
|
||||||
value = (int) (percent * range / 100) + finalMinValue;
|
value = (int) (percent * range / 100) + finalMinValue;
|
||||||
} else if (state instanceof DecimalType) {
|
} else if (state instanceof DecimalType stateAsDecimalType) {
|
||||||
value = ((DecimalType) state).intValue();
|
value = stateAsDecimalType.intValue();
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(value);
|
return CompletableFuture.completedFuture(value);
|
||||||
}, (value) -> {
|
}, (value) -> {
|
||||||
@ -927,10 +924,10 @@ public class HomekitCharacteristicFactory {
|
|||||||
final @Nullable Map<String, Object> itemConfiguration = taggedItem.getConfiguration();
|
final @Nullable Map<String, Object> itemConfiguration = taggedItem.getConfiguration();
|
||||||
if ((value == 0) && (itemConfiguration != null)) { // check for default duration
|
if ((value == 0) && (itemConfiguration != null)) { // check for default duration
|
||||||
final Object duration = itemConfiguration.get(HomekitValveImpl.CONFIG_DEFAULT_DURATION);
|
final Object duration = itemConfiguration.get(HomekitValveImpl.CONFIG_DEFAULT_DURATION);
|
||||||
if (duration instanceof BigDecimal) {
|
if (duration instanceof BigDecimal durationAsBigDecimal) {
|
||||||
value = ((BigDecimal) duration).intValue();
|
value = durationAsBigDecimal.intValue();
|
||||||
if (taggedItem.getItem() instanceof NumberItem) {
|
if (taggedItem.getItem() instanceof NumberItem taggedNumberItem) {
|
||||||
((NumberItem) taggedItem.getItem()).setState(new DecimalType(value));
|
taggedNumberItem.setState(new DecimalType(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,8 +25,6 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.io.homekit.internal.HomekitCharacteristicType;
|
import org.openhab.io.homekit.internal.HomekitCharacteristicType;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import io.github.hapjava.characteristics.Characteristic;
|
import io.github.hapjava.characteristics.Characteristic;
|
||||||
import io.github.hapjava.characteristics.impl.airquality.AirQualityCharacteristic;
|
import io.github.hapjava.characteristics.impl.airquality.AirQualityCharacteristic;
|
||||||
@ -70,10 +68,9 @@ import io.github.hapjava.characteristics.impl.thermostat.TargetHeatingCoolingSta
|
|||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class HomekitMetadataCharacteristicFactory {
|
public class HomekitMetadataCharacteristicFactory {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(HomekitMetadataCharacteristicFactory.class);
|
|
||||||
|
|
||||||
// List of optional characteristics that can be set via metadata, and the corresponding method to create them.
|
// List of optional characteristics that can be set via metadata, and the corresponding method to create them.
|
||||||
private static final Map<HomekitCharacteristicType, Function<Object, Characteristic>> optional = new HashMap<>() {
|
private static final Map<HomekitCharacteristicType, Function<Object, Characteristic>> OPTIONAL = new HashMap<>() {
|
||||||
{
|
{
|
||||||
put(ACTIVE_IDENTIFIER, HomekitMetadataCharacteristicFactory::createActiveIdentifierCharacteristic);
|
put(ACTIVE_IDENTIFIER, HomekitMetadataCharacteristicFactory::createActiveIdentifierCharacteristic);
|
||||||
put(ACTIVE_STATUS, HomekitMetadataCharacteristicFactory::createActiveStatusCharacteristic);
|
put(ACTIVE_STATUS, HomekitMetadataCharacteristicFactory::createActiveStatusCharacteristic);
|
||||||
@ -103,16 +100,16 @@ public class HomekitMetadataCharacteristicFactory {
|
|||||||
|
|
||||||
public static Optional<Characteristic> createCharacteristic(String characteristic, Object value) {
|
public static Optional<Characteristic> createCharacteristic(String characteristic, Object value) {
|
||||||
var type = HomekitCharacteristicType.valueOfTag(characteristic);
|
var type = HomekitCharacteristicType.valueOfTag(characteristic);
|
||||||
if (type.isEmpty() || !optional.containsKey(type.get())) {
|
if (type.isEmpty() || !OPTIONAL.containsKey(type.get())) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
return Optional.of(optional.get(type.get()).apply(value));
|
return Optional.of(OPTIONAL.get(type.get()).apply(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Supplier<CompletableFuture<Integer>> getInteger(Object value) {
|
private static Supplier<CompletableFuture<Integer>> getInteger(Object value) {
|
||||||
int intValue;
|
int intValue;
|
||||||
if (value instanceof BigDecimal) {
|
if (value instanceof BigDecimal valueAsBigDecimal) {
|
||||||
intValue = ((BigDecimal) value).intValue();
|
intValue = valueAsBigDecimal.intValue();
|
||||||
} else if (value instanceof Float) {
|
} else if (value instanceof Float) {
|
||||||
intValue = ((Float) value).intValue();
|
intValue = ((Float) value).intValue();
|
||||||
} else if (value instanceof Integer) {
|
} else if (value instanceof Integer) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user