public abstract class Capability extends java.lang.Object implements java.lang.Iterable<Attribute>
CapabilityOnOff,
CapabilityLevel.
Each capability might have one or more commands. Which can be executed using
sendResourceCommand(Command, CommandStatusListener)
Capability class acts as blueprint for the Capability present in the resource. It encapsulates all commands and attributes it supports.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Capability.AttributeId
Super interface for all AttributeIds used by capability of a resource.
|
static class |
Capability.CapabilityId
Enum mapping all coco-standard capabilityIds and their corresponding capability IDProviders.
|
static interface |
Capability.CommandId
Super interface for all CommandIds in all child Capabilities.
|
static interface |
Capability.CommandStatusListener<T extends Capability.CommandId>
Listener to assist with status of the
sendResourceCommand(Command, CommandStatusListener). |
| Modifier | Constructor and Description |
|---|---|
protected |
Capability(int id,
Resource parent)
Constructor of the current class.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
clearAndSetStandardCommandSet(int[] commands)
A function to clear current commands and set new one's.
|
boolean |
containsAttribute(Capability.AttributeId attributeId)
A function to check if this capability contains
Attribute given the ID. |
protected boolean |
containsAttribute(int attributeId)
A function to check if this capability contains
Attribute given the ID. |
protected Command<? extends Capability.CommandId> |
createCommand(int commandId,
com.google.gson.JsonElement commandParams)
A function to create the command from the Json params.
|
protected <T extends CommandIdInterface> |
createCommandResponseArgs(T commandId,
com.google.gson.JsonElement jsonResponse)
create response args for the command.
|
protected abstract Command<? extends Capability.CommandId> |
extendedCreateCommand(int commandId,
com.google.gson.JsonElement commandParams)
A function to create the command from the Json params.
|
<T extends Attribute> |
getAttribute(Capability.AttributeId attributeId)
This function is used to get the Attribute with the given ID.
|
<T extends Attribute> |
getAttribute(int attributeId)
This function is used to get the Attribute with the given ID.
|
java.util.Map<java.lang.Integer,Attribute> |
getAttributeMap()
This function is used to return the HashMap that the sdk uses to map
the integer id of the attribute to the Attribute Objects.
|
CapabilityWrapper |
getCapabilityWrapper()
A function to get
CapabilityWrapper. |
Capability.CapabilityId |
getId()
This function is used to get the unique id of the capability.
|
java.lang.String |
getName()
This function is used to get the Name of the capability.
|
Resource |
getParent()
This function is used to get the parent resource of the current capability.
|
java.util.List<Capability.CommandId> |
getSupportedCommands()
This function fetches the list of commands supported.
|
int |
hashCode() |
protected <T extends Capability.CommandId> |
interceptCommand(Command<T> command)
A function that will get called before command being sent to device.
|
protected void |
internalAddAttribute(Attribute attribute)
A function that will would get triggered when a
Attribute is added. |
protected void |
internalMarkAsReady()
A function that would be triggered to make
Capability this as ready. |
protected void |
internalRemoveAttribute(int attributeId)
A function that would be triggered when a
Attribute is removed. |
protected void |
internalSetName(java.lang.String name)
A function that would be triggered when
name is updated. |
protected void |
internalSetParent(Resource parent)
A function that would be triggered when parent of the capability updated.
|
boolean |
isReady()
A function to state if the current capability is updated from
NativeCallbacks.resourceCapabilityCallback(boolean, java.lang.String, long, java.lang.String, int, java.lang.String, int[], java.lang.Object) or by any other way. |
java.util.Iterator<Attribute> |
iterator() |
<T extends Capability.CommandId> |
sendResourceCommand(Command<T> command,
Capability.CommandStatusListener<T> listener)
sendCommands to the current capability.
|
void |
setCapabilityWrapper(CapabilityWrapper capabilityWrapper)
This function sets provided
CapabilityWrapper object. |
boolean |
supports(Capability.CommandId commandId)
This function checks if a command is supported or not, pass
null to check if capability supports any commands at all.
|
java.lang.String |
toString() |
protected Capability(int id,
Resource parent)
id - The unique id Of the capabilityparent - The parent Resource of the capability.protected <T extends Capability.CommandId> void interceptCommand(Command<T> command)
T - capture for casting.command - Command which is being sent.public final <T extends Capability.CommandId> void sendResourceCommand(Command<T> command, Capability.CommandStatusListener<T> listener)
bulb
.getCapability(Capability.CapabilityId.ON_OFF_CONTROL)
.sendResourceCommand(new CapabilityOnOff.On(),
(commandResponse, throwable) -> {
if (null != throwable) {
// success case.
})
});
T - capture for casting.command - The command which is to be executed.listener - Callback of this interface will be triggered.implements a different approachpublic boolean supports(Capability.CommandId commandId)
commandId - The ID denoting the command to be sent.public final Capability.CapabilityId getId()
public final java.lang.String getName()
public final Resource getParent()
public java.util.Map<java.lang.Integer,Attribute> getAttributeMap()
public <T extends Attribute> T getAttribute(int attributeId)
T - Capture for casting.attributeId - Attribute ID of the of required Attribute.public <T extends Attribute> T getAttribute(Capability.AttributeId attributeId)
T - Capture for castingattributeId - AttributeId of required Attributeprotected boolean containsAttribute(int attributeId)
Attribute given the ID.public boolean containsAttribute(Capability.AttributeId attributeId)
Attribute given the ID.protected void internalAddAttribute(Attribute attribute)
Attribute is added.attribute - Attribute which is added to the capability.protected void internalRemoveAttribute(int attributeId)
Attribute is removed.attributeId - ID of attribute which is removed from the capability.protected void internalSetParent(Resource parent)
parent - Resource which is parent of the capability.public void setCapabilityWrapper(CapabilityWrapper capabilityWrapper)
CapabilityWrapper object.capabilityWrapper - instance of wrapper object.public CapabilityWrapper getCapabilityWrapper()
CapabilityWrapper.CapabilityWrapperpublic final int hashCode()
hashCode in class java.lang.Objectpublic java.util.List<Capability.CommandId> getSupportedCommands()
protected abstract Command<? extends Capability.CommandId> extendedCreateCommand(int commandId, com.google.gson.JsonElement commandParams)
commandId - The int form of the commandIdcommandParams - The Json params that can form a commandprotected <T extends CommandIdInterface> CommandResponse.Args<T> createCommandResponseArgs(T commandId, com.google.gson.JsonElement jsonResponse)
T - Capture for casting.commandId - The command ID which has to be respondedjsonResponse - The response bodyCommandResponse.Argsprotected Command<? extends Capability.CommandId> createCommand(int commandId, com.google.gson.JsonElement commandParams)
commandId - The int form of the commandIdcommandParams - The Json params that can form a commandpublic boolean isReady()
NativeCallbacks.resourceCapabilityCallback(boolean, java.lang.String, long, java.lang.String, int, java.lang.String, int[], java.lang.Object) or by any other way.protected void internalSetName(java.lang.String name)
name is updated.name - Updated name of the capability.protected void clearAndSetStandardCommandSet(int[] commands)
commands - commands which needs to set as the standard commands
for the capability.protected void internalMarkAsReady()
Capability this as ready.public java.lang.String toString()
toString in class java.lang.Object