Class BaseCharacteristic<T>

    • Constructor Summary

      Constructors 
      Constructor Description
      BaseCharacteristic​(java.lang.String type, java.lang.String format, java.lang.String description, boolean isReadable, boolean isWritable, java.util.Optional<java.util.function.Consumer<HomekitCharacteristicChangeCallback>> subscriber, java.util.Optional<java.lang.Runnable> unsubscriber)
      Default constructor
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract T convert​(javax.json.JsonValue jsonValue)
      Converts from the JSON value to a Java object of the type T
      abstract T getDefault()
      Supplies a default value for the characteristic to send to connected clients when the real value.
      java.lang.String getType()  
      abstract java.util.concurrent.CompletableFuture<T> getValue()
      Retrieves the current value of the characteristic.
      protected java.util.concurrent.CompletableFuture<javax.json.JsonObjectBuilder> makeBuilder​(int instanceId)
      Creates the JSON serialized form of the accessory for use over the HomeKit Accessory Protocol.
      protected void setJsonValue​(javax.json.JsonObjectBuilder builder, T value)
      Writes the value key to the serialized characteristic
      void setValue​(javax.json.JsonValue jsonValue)
      Invoked by the remote client, this updates the current value of the characteristic.
      abstract void setValue​(T value)
      Update the characteristic value using a new value supplied by the connected client.
      void subscribe​(HomekitCharacteristicChangeCallback callback)
      Begin listening to changes to this characteristic.
      void supplyValue​(javax.json.JsonObjectBuilder builder)
      Adds an attribute to the passed JsonObjectBuilder named "value" with the current value of the characteristic.
      java.util.concurrent.CompletableFuture<javax.json.JsonObject> toJson​(int iid)
      Creates the JSON representation of the characteristic, in accordance with the HomeKit Accessory Protocol.
      void unsubscribe()
      Stop listening to changes to this characteristic.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BaseCharacteristic

        public BaseCharacteristic​(java.lang.String type,
                                  java.lang.String format,
                                  java.lang.String description,
                                  boolean isReadable,
                                  boolean isWritable,
                                  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.
        format - a string indicating the value type, which must be a recognized type by the consuming device.
        isWritable - indicates whether the value can be changed.
        isReadable - indicates whether the value can be retrieved.
        description - a description of the characteristic to be passed to the consuming device.
        subscriber - subscribes to changes
        unsubscriber - unsubscribes to changes
    • Method Detail

      • getType

        public java.lang.String getType()
        Specified by:
        getType in interface Characteristic
        Returns:
        The UUID type for this characteristic.
      • toJson

        public final java.util.concurrent.CompletableFuture<javax.json.JsonObject> toJson​(int iid)
        Description copied from interface: Characteristic
        Creates the JSON representation of the characteristic, in accordance with the HomeKit Accessory Protocol.
        Specified by:
        toJson in interface Characteristic
        Parameters:
        iid - The instance ID of the characteristic to be included in the serialization.
        Returns:
        the future completing with the resulting JSON.
      • makeBuilder

        protected java.util.concurrent.CompletableFuture<javax.json.JsonObjectBuilder> makeBuilder​(int instanceId)
        Creates the JSON serialized form of the accessory for use over the HomeKit Accessory Protocol.
        Parameters:
        instanceId - the static id of the accessory.
        Returns:
        a future that will complete with the JSON builder for the object.
      • setValue

        public final void setValue​(javax.json.JsonValue jsonValue)
        Invoked by the remote client, this updates the current value of the characteristic.
        Specified by:
        setValue in interface Characteristic
        Parameters:
        jsonValue - the JSON serialized value to set.
      • supplyValue

        public void supplyValue​(javax.json.JsonObjectBuilder builder)
        Adds an attribute to the passed JsonObjectBuilder named "value" with the current value of the characteristic.
        Specified by:
        supplyValue in interface Characteristic
        Parameters:
        builder - the JsonObjectBuilder to add the value attribute to.
      • subscribe

        public void subscribe​(HomekitCharacteristicChangeCallback callback)
        Begin listening to changes to this characteristic. When a change is made, call the provided function.
        Specified by:
        subscribe in interface EventableCharacteristic
        Parameters:
        callback - a function to call when a change is made to the characteristic value.
      • convert

        protected abstract T convert​(javax.json.JsonValue jsonValue)
        Converts from the JSON value to a Java object of the type T
        Parameters:
        jsonValue - the JSON value to convert from.
        Returns:
        the converted Java object.
      • setValue

        public abstract void setValue​(T value)
                               throws java.lang.Exception
        Update the characteristic value using a new value supplied by the connected client.
        Parameters:
        value - the new value to set.
        Throws:
        java.lang.Exception - if the value cannot be set.
      • getValue

        public abstract java.util.concurrent.CompletableFuture<T> getValue()
        Retrieves the current value of the characteristic.
        Returns:
        a future that will complete with the current value.
      • getDefault

        public abstract T getDefault()
        Supplies a default value for the characteristic to send to connected clients when the real value. cannot be retrieved.
        Returns:
        a sensible default value.
      • setJsonValue

        protected void setJsonValue​(javax.json.JsonObjectBuilder builder,
                                    T value)
        Writes the value key to the serialized characteristic
        Parameters:
        builder - The JSON builder to add the value to
        value - The value to add