forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[homekit] Added support for contact sensors (openhab#4521)
* [homekit] Added support for contact sensors * Changed SwitchItem to ContactItem * Updated documentation for ContactItem Signed-off-by: Philipp Arndt <[email protected]> (github: philipparndt) Signed-off-by: Maximilian Hess <[email protected]>
- Loading branch information
1 parent
5a136ab
commit 445a14e
Showing
5 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ bin.includes = META-INF/,\ | |
lib/org.zeromq.curve25519-java-0.1.0.jar,\ | ||
NOTICE,\ | ||
ESH-INF/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...t/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitContactSensorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright (c) 2010-2019 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.io.homekit.internal.accessories; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.smarthome.core.items.ItemRegistry; | ||
import org.eclipse.smarthome.core.library.items.ContactItem; | ||
import org.eclipse.smarthome.core.library.types.OpenClosedType; | ||
import org.openhab.io.homekit.internal.HomekitAccessoryUpdater; | ||
import org.openhab.io.homekit.internal.HomekitTaggedItem; | ||
|
||
import com.beowulfe.hap.HomekitCharacteristicChangeCallback; | ||
import com.beowulfe.hap.accessories.ContactSensor; | ||
import com.beowulfe.hap.accessories.properties.ContactState; | ||
|
||
/** | ||
* Implements Contact sensor using an Item that provides an On/Off state. | ||
* | ||
* @author Philipp Arndt - Initial contribution | ||
*/ | ||
public class HomekitContactSensorImpl extends AbstractHomekitAccessoryImpl<ContactItem> implements ContactSensor { | ||
|
||
public HomekitContactSensorImpl(HomekitTaggedItem taggedItem, ItemRegistry itemRegistry, | ||
HomekitAccessoryUpdater updater) { | ||
super(taggedItem, itemRegistry, updater, ContactItem.class); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<ContactState> getCurrentState() { | ||
OpenClosedType state = getItem().getStateAs(OpenClosedType.class); | ||
return CompletableFuture | ||
.completedFuture(state == OpenClosedType.CLOSED ? ContactState.DETECTED : ContactState.NOT_DETECTED); | ||
} | ||
|
||
@Override | ||
public void subscribeContactState(HomekitCharacteristicChangeCallback callback) { | ||
getUpdater().subscribe(getItem(), callback); | ||
} | ||
|
||
@Override | ||
public void unsubscribeContactState() { | ||
getUpdater().unsubscribe(getItem()); | ||
} | ||
|
||
} |