Skip to content

Commit

Permalink
[homekit] change SECURED=OFF for HomeKit lock (openhab#7984)
Browse files Browse the repository at this point in the history
* [homekit] allow exposing jammed state for a lock

also change SECURED to be ON for SwitchItem
since this is what most real locks (especially ZWave ones) do

Signed-off-by: Cody Cutrer <[email protected]>
Signed-off-by: CSchlipp <[email protected]>
  • Loading branch information
ccutrer authored and CSchlipp committed Jul 26, 2020
1 parent d14eb2c commit 9ce86ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions bundles/org.openhab.io.homekit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ A full list of supported accessory types can be found in the table *below*.
| | | CoolingThresholdTemperature | Number | maximum temperature that must be reached before cooling is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] |
| | | HeatingThresholdTemperature | Number | minimum temperature that must be reached before heating is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] |
| Lock | | | | A Lock Mechanism |
| | LockCurrentState | | Switch | current states of lock mechanism (OFF=SECURED, ON=UNSECURED) |
| | LockTargetState | | Switch | target states of lock mechanism (OFF=SECURED, ON=UNSECURED) |
| | LockCurrentState | | Switch,Number | current state of lock mechanism (1/ON=SECURED, 0/OFF=UNSECURED, 2=JAMMED, 3=UNKNOWN) |
| | LockTargetState | | Switch | target state of lock mechanism (ON=SECURED, OFF=UNSECURED) |
| | | Name | String | Name of the lock |
| Valve | | | | Valve. additional configuration: homekitValveType = ["Generic", "Irrigation", "Shower", "Faucet"] |
| | ActiveStatus | | Switch | accessory current working status. A value of "ON"/"OPEN" indicate that the accessory is active and is functioning without any errors. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
import java.util.concurrent.CompletableFuture;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.items.GenericItem;
import org.eclipse.smarthome.core.items.Item;
import org.eclipse.smarthome.core.library.items.SwitchItem;
import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.types.State;
import org.openhab.io.homekit.internal.HomekitAccessoryUpdater;
import org.openhab.io.homekit.internal.HomekitCharacteristicType;
import org.openhab.io.homekit.internal.HomekitSettings;
Expand Down Expand Up @@ -47,10 +50,14 @@ public HomekitLockImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> man
@Override
public CompletableFuture<LockCurrentStateEnum> getLockCurrentState() {
@Nullable
OnOffType state = getStateAs(HomekitCharacteristicType.LOCK_CURRENT_STATE, OnOffType.class);
if (state != null) {

final State state = getItem(HomekitCharacteristicType.LOCK_CURRENT_STATE, GenericItem.class).getState();
if (state instanceof DecimalType) {
return CompletableFuture.completedFuture(LockCurrentStateEnum.fromCode(
state.as(DecimalType.class).intValue()));
} else if (state instanceof OnOffType) {
return CompletableFuture.completedFuture(
state == OnOffType.OFF ? LockCurrentStateEnum.SECURED : LockCurrentStateEnum.UNSECURED);
state == OnOffType.ON ? LockCurrentStateEnum.SECURED : LockCurrentStateEnum.UNSECURED);
}
return CompletableFuture.completedFuture(LockCurrentStateEnum.UNKNOWN);
}
Expand All @@ -61,7 +68,7 @@ public CompletableFuture<LockTargetStateEnum> getLockTargetState() {
OnOffType state = getStateAs(HomekitCharacteristicType.LOCK_TARGET_STATE, OnOffType.class);
if (state != null) {
return CompletableFuture.completedFuture(
state == OnOffType.OFF ? LockTargetStateEnum.SECURED : LockTargetStateEnum.UNSECURED);
state == OnOffType.ON ? LockTargetStateEnum.SECURED : LockTargetStateEnum.UNSECURED);
}
return CompletableFuture.completedFuture(LockTargetStateEnum.UNSECURED);
// Apple HAP specification has onyl SECURED and UNSECURED values for lock target state.
Expand All @@ -77,13 +84,13 @@ public CompletableFuture<Void> setLockTargetState(final LockTargetStateEnum stat
case SECURED:
// Close the door
if (item instanceof SwitchItem) {
((SwitchItem) item).send(OnOffType.OFF);
((SwitchItem) item).send(OnOffType.ON);
}
break;
case UNSECURED:
// Open the door
if (item instanceof SwitchItem) {
((SwitchItem) item).send(OnOffType.ON);
((SwitchItem) item).send(OnOffType.OFF);
}
break;
default:
Expand Down

0 comments on commit 9ce86ea

Please sign in to comment.