Skip to content

Add support for LeakSensor and Valve devices #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.beowulfe.hap.accessories;

import com.beowulfe.hap.HomekitCharacteristicChangeCallback;

import java.util.concurrent.CompletableFuture;

import com.beowulfe.hap.HomekitCharacteristicChangeCallback;

/**
* An accessory that runs on batteries. Accessories that run on batteries are able to report
* battery level.
* Do not use. Devices that have battery levels should implement LowBatteryStatusAccessory.
*
* @author Gaston Dombiak
*/
@Deprecated
public interface BatteryAccessory {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.beowulfe.hap.accessories;

import java.util.concurrent.CompletableFuture;

import com.beowulfe.hap.HomekitCharacteristicChangeCallback;

/**
* An accessory that runs on batteries. Accessories that run on batteries are able to report
* battery level.
*
* @author Tim Harper
*/
public interface BatteryStatusAccessory {

/**
* Queries if the device battery level is low; returning a value of true
* will cause a low-battery status to appear in Home for the device.
*
* @return a future that will contain the accessory's low battery state
*/
CompletableFuture<Boolean> getLowBatteryState();

/**
* Subscribes to changes in the battery level.
*
* @param callback the function to call when low battery state changes.
*/
void subscribeLowBatteryState(HomekitCharacteristicChangeCallback callback);

/**
* Unsubscribes from changes in the low battery state.
*/
void unsubscribeLowBatteryState();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* <p>A carbon monoxide sensor reports whether carbon monoxide has been detected or not.</p>
*
* <p>Carbon monoxide sensors that run on batteries will need to implement this interface
* and also implement {@link BatteryAccessory}.</p>
* and also implement {@link BatteryStatusAccessory}.</p>
*
* @author Gaston Dombiak
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* that the door/window is closed.</p>
*
* <p>Contact sensors that run on batteries will need to implement this interface
* and also implement {@link BatteryAccessory}.</p>
* and also implement {@link BatteryStatusAccessory}.</p>
*
* @author Gaston Dombiak
*/
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/com/beowulfe/hap/accessories/LeakSensor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.beowulfe.hap.accessories;

import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;

import com.beowulfe.hap.HomekitAccessory;
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
import com.beowulfe.hap.Service;
import com.beowulfe.hap.impl.services.LeakSensorService;

/**
* <p>
* A leak sensor that reports whether a leak has been detected.
* </p>
*
* <p>
* Leak sensors that run on batteries will need to implement this interface
* and also implement {@link BatteryStatusAccessory}.
* </p>
*
* @author Tim Harper
*/
public interface LeakSensor extends HomekitAccessory {

/**
* Retrieves the state of the leak sensor. If true then leak has been detected.
*
* @return a future that will contain the leak sensor's state
*/
CompletableFuture<Boolean> getLeakDetected();

@Override
default Collection<Service> getServices() {
return Collections.singleton(new LeakSensorService(this));
}

/**
* Subscribes to changes in the leak sensor.
*
* @param callback the function to call when the state changes.
*/
void subscribeLeakDetected(HomekitCharacteristicChangeCallback callback);

/**
* Unsubscribes from changes in the leak sensor.
*/
void unsubscribeLeakDetected();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* {@link LockableLockMechanism}.</p>
*
* <p>Locks that run on batteries will need to implement this interface and also
* implement {@link BatteryAccessory}.</p>
* implement {@link BatteryStatusAccessory}.</p>
*
* @author Andy Lintner
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* <p>A motion sensor that reports whether motion has been detected.</p>
*
* <p>Motion sensors that run on batteries will need to implement this interface
* and also implement {@link BatteryAccessory}.</p>
* and also implement {@link BatteryStatusAccessory}.</p>
*
* @author Gaston Dombiak
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* <p>A smoke sensor reports whether smoke has been detected or not.</p>
*
* <p>Smoke sensors that run on batteries will need to implement this interface
* and also implement {@link BatteryAccessory}.</p>
* and also implement {@link BatteryStatusAccessory}.</p>
*
* @author Gaston Dombiak
*/
Expand Down
99 changes: 99 additions & 0 deletions src/main/java/com/beowulfe/hap/accessories/Valve.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.beowulfe.hap.accessories;

import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;

import com.beowulfe.hap.HomekitAccessory;
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
import com.beowulfe.hap.Service;
import com.beowulfe.hap.accessories.properties.ValveType;
import com.beowulfe.hap.impl.services.ValveService;

/**
* A Valve (sprinkler head, faucet, etc.)
*
* @author Tim Harper
*/
public interface Valve extends HomekitAccessory {

@Override
default Collection<Service> getServices() {
return Collections.singleton(new ValveService(this));
}

/**
* Retrieves the current active state of the valve; Active could mean the valve is open (but not necessarily
* running),
* or that the valve is associated with an active watering program (like a watering program) but is not currently
* running.
*
* To communicate water is flowing through a valve, inUse should be used.
*
* @return a future that will contain the binary state
*/
CompletableFuture<Boolean> getValveActive();

/**
* Sets the valve active state
*
* @param active the binary state to set
* @return a future that completes when the change is made
* @throws Exception when the change cannot be made
*/
CompletableFuture<Void> setValveActive(boolean active) throws Exception;

/**
* Subscribes to changes in the active state of the valve.
*
* @param callback the function to call when the state changes.
*/
void subscribeValveActive(HomekitCharacteristicChangeCallback callback);

/**
* Unsubscribes from changes in the valve active state.
*/
void unsubscribeValveActive();

/**
* Retrieves the current inUse state of the valve; InUse usually means water is flowing through the valve.
*
* To communicate water is flowing through a valve, inUse should be used.
*
* @return a future that will contain the binary state
*/
CompletableFuture<Boolean> getValveInUse();

/**
* Subscribes to changes in the inUse state of the valve.
*
* @param callback the function to call when the state changes.
*/
void subscribeValveInUse(HomekitCharacteristicChangeCallback callback);

/**
* Unsubscribes from changes in the valve inUse state.
*/
void unsubscribeValveInUse();

/**
* Retrieves the valve type.
*
* To communicate water is flowing through a valve, inUse should be used.
*
* @return a future that will contain the binary state
*/
CompletableFuture<ValveType> getValveType();

/**
* Subscribes to changes in the valveType state of the valve.
*
* @param callback the function to call when the state changes.
*/
void subscribeValveType(HomekitCharacteristicChangeCallback callback);

/**
* Unsubscribes from changes in the valveType state light.
*/
void unsubscribeValveType();
}
66 changes: 66 additions & 0 deletions src/main/java/com/beowulfe/hap/accessories/ValveWithTimer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.beowulfe.hap.accessories;

import java.util.concurrent.CompletableFuture;

import com.beowulfe.hap.HomekitCharacteristicChangeCallback;

/**
* Extends {@link Valve} with timer values.
*
* @author Tim Harper
*/
public interface ValveWithTimer extends Valve {

/**
* Retrieves the current duration for which the valve will run
*
* @return a future with the value
*/
CompletableFuture<Integer> getRemainingDuration();

/**
* Subscribes to changes in the duration; note it is not necessary to emit a
* change every second, homekit infers the countdown progress clientside.
*
* @param callback the function when the existing duration has been replaced with a new one.
*/
void subscribeRemainingDuration(HomekitCharacteristicChangeCallback callback);

/**
* Unsubscribes from changes
*/
void unsubscribeRemainingDuration();

/**
* Retrieves the current set duration for which the valve will be scheduled
* to run; this is usually used as the duration to use when the valve is set
* to active.
*
* @return a future with the value
*/
CompletableFuture<Integer> getSetDuration();

/**
* Sets the duration for which the valve will be scheduled to run; this is
* usually used as the duration to use when the valve is set to active.
*
* If the valve is currently running, then Homekit assumes that changing
* this value affects the current remaining duration.
*
* @return a future with the value
*/
CompletableFuture<Void> setSetDuration(int value);

/**
* Subscribes to changes in the set duration
*
* @param callback the function when the value has changed
*/
void subscribeSetDuration(HomekitCharacteristicChangeCallback callback);

/**
* Unsubscribes from changes
*/
void unsubscribeSetDuration();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.beowulfe.hap.accessories.properties;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

import com.beowulfe.hap.accessories.Valve;

/**
* The mode used by a {@link Valve}
*
* @author Tim Harper
*/
public enum ValveType {

GENERIC(0),
IRRIGATION(1),
SHOWER(2),
WATER_FAUCET(3);

private final static Map<Integer, ValveType> reverse;
static {
reverse = Arrays.stream(ValveType.values()).collect(Collectors.toMap(t -> t.getCode(), t -> t));
}

public static ValveType fromCode(Integer code) {
return reverse.get(code);
}

private final int code;

private ValveType(int code) {
this.code = code;
}

public int getCode() {
return code;
}
}
Loading