Class EnumCharacteristic<T extends CharacteristicEnum>
- java.lang.Object
-
- io.github.hapjava.characteristics.impl.base.BaseCharacteristic<java.lang.Integer>
-
- io.github.hapjava.characteristics.impl.base.EnumCharacteristic<T>
-
- All Implemented Interfaces:
Characteristic,EventableCharacteristic
- Direct Known Subclasses:
AccessoryFlagsCharacteristic,ActiveCharacteristic,AirQualityCharacteristic,CarbonDioxideDetectedCharacteristic,CarbonMonoxideDetectedCharacteristic,ChargingStateCharacteristic,ClosedCaptionsCharacteristic,ContactSensorStateCharacteristic,CurrentAirPurifierCharacteristic,CurrentDoorStateCharacteristic,CurrentFanStateCharacteristic,CurrentHeaterCoolerStateCharacteristic,CurrentHeatingCoolingStateCharacteristic,CurrentHumidifierDehumidifierStateCharacteristic,CurrentMediaStateCharacteristic,CurrentSecuritySystemStateCharacteristic,CurrentSlatStateCharacteristic,CurrentVisibilityStateCharacteristic,FilterChangeIndicationCharacteristic,InputDeviceTypeCharacteristic,InputSourceTypeCharacteristic,InUseCharacteristic,IsConfiguredCharacteristic,LeakDetectedStateCharacteristic,LockCurrentStateCharacteristic,LockPhysicalControlsCharacteristic,LockTargetStateCharacteristic,OccupancyDetectedCharacteristic,PictureModeCharacteristic,PositionStateCharacteristic,PowerModeCharacteristic,ProgrammableSwitchEventCharacteristic,ProgramModeCharacteristic,RemoteKeyCharacteristic,RotationDirectionCharacteristic,SecuritySystemAlarmTypeCharacteristic,ServiceLabelNamespaceCharacteristic,SlatTypeCharacteristic,SleepDiscoveryModeCharacteristic,SmokeDetectedCharacteristic,StatusFaultCharacteristic,StatusLowBatteryCharacteristic,StatusTamperedCharacteristic,SwingModeCharacteristic,TargetAirPurifierStateCharacteristic,TargetDoorStateCharacteristic,TargetFanStateCharacteristic,TargetHeaterCoolerStateCharacteristic,TargetHeatingCoolingStateCharacteristic,TargetHumidifierDehumidifierStateCharacteristic,TargetMediaStateCharacteristic,TargetSecuritySystemStateCharacteristic,TargetVisibilityStateCharacteristic,TemperatureDisplayUnitCharacteristic,ValveTypeCharacteristic,VolumeControlTypeCharacteristic,VolumeSelectorCharacteristic
public abstract class EnumCharacteristic<T extends CharacteristicEnum> extends BaseCharacteristic<java.lang.Integer>
Characteristic that exposes an Enum value. Enums are represented as an Integer value in the HomeKit protocol, and classes extending this one must handle the static mapping to an Integer value.- Author:
- Andy Lintner
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Optional<java.util.function.Supplier<java.util.concurrent.CompletableFuture<T>>>getterprotected java.util.Optional<ExceptionalConsumer<T>>setter
-
Constructor Summary
Constructors Constructor Description EnumCharacteristic(java.lang.String type, java.lang.String description, T[] validValues, java.util.Optional<java.util.function.Supplier<java.util.concurrent.CompletableFuture<T>>> getter, java.util.Optional<ExceptionalConsumer<T>> setter, java.util.Optional<java.util.function.Consumer<HomekitCharacteristicChangeCallback>> subscriber, java.util.Optional<java.lang.Runnable> unsubscriber)Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Integerconvert(javax.json.JsonValue jsonValue)Converts from the JSON value to a Java object of the type Tjava.lang.IntegergetDefault()Supplies a default value for the characteristic to send to connected clients when the real value.java.util.concurrent.CompletableFuture<T>getEnumValue()T[]getValidValues()java.util.concurrent.CompletableFuture<java.lang.Integer>getValue()Retrieves the current value of the characteristic.protected java.util.concurrent.CompletableFuture<javax.json.JsonObjectBuilder>makeBuilder(int iid)Creates the JSON serialized form of the accessory for use over the HomeKit Accessory Protocol.voidsetValue(java.lang.Integer value)Update the characteristic value using a new value supplied by the connected client.voidsetValue(T value)-
Methods inherited from class io.github.hapjava.characteristics.impl.base.BaseCharacteristic
getType, setJsonValue, setValue, subscribe, supplyValue, toJson, unsubscribe
-
-
-
-
Field Detail
-
getter
protected java.util.Optional<java.util.function.Supplier<java.util.concurrent.CompletableFuture<T extends CharacteristicEnum>>> getter
-
setter
protected java.util.Optional<ExceptionalConsumer<T extends CharacteristicEnum>> setter
-
-
Constructor Detail
-
EnumCharacteristic
public EnumCharacteristic(java.lang.String type, java.lang.String description, T[] validValues, java.util.Optional<java.util.function.Supplier<java.util.concurrent.CompletableFuture<T>>> getter, java.util.Optional<ExceptionalConsumer<T>> setter, java.util.Optional<java.util.function.Consumer<HomekitCharacteristicChangeCallback>> subscriber, java.util.Optional<java.lang.Runnable> unsubscriber)Default constructor- Parameters:
type- a string containing a UUID that indicates the type of characteristic. Apple defines a set of these, however implementors can create their own as well.description- a description of the characteristic to be passed to the consuming device.validValues- an array of valid values for enum.getter- getter to retrieve the valuesetter- setter to set valuesubscriber- subscriber to subscribe to changesunsubscriber- unsubscriber to unsubscribe from chnages
-
-
Method Detail
-
makeBuilder
protected java.util.concurrent.CompletableFuture<javax.json.JsonObjectBuilder> makeBuilder(int iid)
Creates the JSON serialized form of the accessory for use over the HomeKit Accessory Protocol.- Overrides:
makeBuilderin classBaseCharacteristic<java.lang.Integer>- Parameters:
iid- the static id of the accessory.- Returns:
- a future that will complete with the JSON builder for the object.
-
convert
protected java.lang.Integer convert(javax.json.JsonValue jsonValue)
Converts from the JSON value to a Java object of the type T- Specified by:
convertin classBaseCharacteristic<java.lang.Integer>- Parameters:
jsonValue- the JSON value to convert from.- Returns:
- the converted Java object.
-
getEnumValue
public java.util.concurrent.CompletableFuture<T> getEnumValue()
- Returns:
- the current value of this characteristic, or null if it has no value or can't be fetched
-
getValue
public java.util.concurrent.CompletableFuture<java.lang.Integer> getValue()
Description copied from class:BaseCharacteristicRetrieves the current value of the characteristic.- Specified by:
getValuein classBaseCharacteristic<java.lang.Integer>- Returns:
- a future that will complete with the current value.
-
setValue
public void setValue(T value) throws java.lang.Exception
- Throws:
java.lang.Exception
-
setValue
public void setValue(java.lang.Integer value) throws java.lang.ExceptionDescription copied from class:BaseCharacteristicUpdate the characteristic value using a new value supplied by the connected client.- Specified by:
setValuein classBaseCharacteristic<java.lang.Integer>- Parameters:
value- the new value to set.- Throws:
java.lang.Exception- if the value cannot be set.
-
getDefault
public java.lang.Integer getDefault()
Supplies a default value for the characteristic to send to connected clients when the real value. cannot be retrieved.- Specified by:
getDefaultin classBaseCharacteristic<java.lang.Integer>- Returns:
- a sensible default value.
-
getValidValues
public T[] getValidValues()
-
-