Class StringCharacteristic
- java.lang.Object
-
- io.github.hapjava.characteristics.impl.base.BaseCharacteristic<String>
-
- io.github.hapjava.characteristics.impl.base.StringCharacteristic
-
- All Implemented Interfaces:
Characteristic,EventableCharacteristic
- Direct Known Subclasses:
ConfiguredNameCharacteristic
public class StringCharacteristic extends BaseCharacteristic<String>
A characteristic that provides an string value.- Author:
- Eugen Freiter
-
-
Constructor Summary
Constructors Constructor Description StringCharacteristic(String type, String description, Optional<Supplier<CompletableFuture<String>>> getter, Optional<ExceptionalConsumer<String>> setter, Optional<Consumer<HomekitCharacteristicChangeCallback>> subscriber, Optional<Runnable> unsubscriber)Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringconvert(javax.json.JsonValue jsonValue)Converts from the JSON value to a Java object of the type TStringgetDefault()Supplies a default value for the characteristic to send to connected clients when the real value.protected CompletableFuture<String>getValue()Retrieves the current value of the characteristic.protected CompletableFuture<javax.json.JsonObjectBuilder>makeBuilder(int iid)Creates the JSON serialized form of the accessory for use over the HomeKit Accessory Protocol.voidsetValue(String value)Update the characteristic value using a new value supplied by the connected client.-
Methods inherited from class io.github.hapjava.characteristics.impl.base.BaseCharacteristic
setJsonValue, setValue, subscribe, supplyValue, toJson, unsubscribe
-
-
-
-
Constructor Detail
-
StringCharacteristic
public StringCharacteristic(String type, String description, Optional<Supplier<CompletableFuture<String>>> getter, Optional<ExceptionalConsumer<String>> setter, Optional<Consumer<HomekitCharacteristicChangeCallback>> subscriber, Optional<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.getter- getter to retrieve the valuesetter- setter for valuesubscriber- subscriber to subscribe to changesunsubscriber- unsubscriber to unsubscribe from chnages
-
-
Method Detail
-
makeBuilder
protected 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<String>- Parameters:
iid- the static id of the accessory.- Returns:
- a future that will complete with the JSON builder for the object.
-
convert
public String convert(javax.json.JsonValue jsonValue)
Converts from the JSON value to a Java object of the type T- Specified by:
convertin classBaseCharacteristic<String>- Parameters:
jsonValue- the JSON value to convert from.- Returns:
- the converted Java object.
-
setValue
public void setValue(String value) throws Exception
Update the characteristic value using a new value supplied by the connected client.- Specified by:
setValuein classBaseCharacteristic<String>- Parameters:
value- the new value to set.- Throws:
Exception- if the value cannot be set.
-
getValue
protected CompletableFuture<String> getValue()
Retrieves the current value of the characteristic.- Specified by:
getValuein classBaseCharacteristic<String>- Returns:
- a future that will complete with the current value.
-
getDefault
public String getDefault()
Supplies a default value for the characteristic to send to connected clients when the real value. cannot be retrieved.- Specified by:
getDefaultin classBaseCharacteristic<String>- Returns:
- a sensible default value.
-
-