public class Rule
extends java.lang.Object
Like: If (it's too dim) then (turn on lights). If (CapabilityIlluminance.AttributeId.CURRENT_LUMINANCE_LUX< 60) thenCapability.sendResourceCommand(Command, Capability.CommandStatusListener)with args: newCapabilityOnOff.On() The above can be automated using a rule, and is shown below.
Rule class acts as a blueprint for a rule in a network.
A network can have multiple rules. Rules can be
added using Network.createRule(String, Network.NetworkManagementStatusListener),
deleted using Network.deleteRule(Rule, Network.NetworkManagementStatusListener),
modified using Network.SaveRule by user.
There exists two types of constraints :
Time based constraints ScheduleCondition
Event based constraints ResourceCondition
Action can exist in two forms:
Action that directly act on Resources called ResourceAction
Action that execute scenes,which in turn might have one or more
ResourceAction Scene.getResourceActionMap()
Network.SaveRule saveRule = new Network.SaveRule();
saveRule.id = rule.getId();
saveRule.name = rule.getName();
saveRule.resourceActions = Arrays.asList(
new ResourceAction(capabilityOnOff, onCommand)
);
saveRule.sceneActions = Arrays.asList(
goodMorningScene,
sundayScene
);
saveRule.resourceConditions = Arrays.asList(
new ResourceCondition(
illuminanceSensor,
CapabilityIlluminance.AttributeId.CURRENT_LUMINANCE_LUX,
ResourceCondition.OperatorType.GREATER_THAN,
10_000, // condition is true for more than 10 seconds
null, // ok as long as correctConditionsDataTypes is triggered.
500 // 500 lux
)
);
saveRule.scheduleConditions = Arrays.asList(
new ScheduleCondition.Builder()
.setStartTime(Instant.parse("2021-01-02T10:15:00.00Z"))
.setExpiryTime(LocalTime.of(11, 59))
.setScheduleType(ScheduleCondition.ScheduleType.WEEKLY)
.build()
);
saveRule.correctConditionsDataTypes();
network.sendNetworkManagementCommand(saveRule, (status, tr) -> {
// handle status
});
| Modifier and Type | Class and Description |
|---|---|
static interface |
Rule.Condition
An interface to be implemented by
ScheduleCondition and ResourceCondition. |
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_RULE_ID
Default ID of a rule.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Rule(int id,
Network parent)
Constructs a rule with given ID and parent.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getId()
This function is used to get ID of the scene.
|
java.lang.String |
getName()
This function is used to get Name of the Scene.
|
Network |
getParent()
This function is used to get network that this scene belongs to.
|
java.util.List<ResourceAction> |
getResourceActions()
This function fetches the resource actions for this rule.
|
java.util.List<ResourceCondition> |
getResourceConditions()
A function to fetch resource conditions for this rule.
|
java.util.List<Scene> |
getSceneActions()
This function fetches the scene actions for this rule.
|
java.util.List<ScheduleCondition> |
getScheduleConditions()
This function fetches the schedule conditions set for this rule.
|
int |
hashCode() |
protected void |
internalClearAddResourceActions(java.util.Collection<ResourceAction> resourceActions)
A function that would be triggered when
resourceActions of the rule is updated. |
protected void |
internalClearAddResourceConditions(java.util.Collection<ResourceCondition> resourceConditions)
A function that would be triggered when
resourceConditions is updated. |
protected void |
internalClearAddSceneActions(java.util.Collection<Scene> scenesActions)
A function that would be triggered when
sceneActions of the rule is updated. |
protected void |
internalClearAddScheduleConditions(java.util.Collection<ScheduleCondition> scheduleConditions)
A function that would be triggered when
scheduleConditions is updated. |
protected void |
internalMarkAsReady()
A function that will be triggered to mark this rule as ready.
|
protected void |
internalSetName(java.lang.String name)
A function that would be triggered when
name is updated. |
protected void |
internalSetParent(Network parent)
A function that would be triggered when parent network is updated.
|
boolean |
isReady()
A function suggesting if the rule is created from
NativeCallbacks.ruleInfoCallback(boolean, java.lang.String, int, java.lang.String, java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.Object)
or retrieved from cache. |
java.lang.String |
toString() |
public static final int DEFAULT_RULE_ID
protected Rule(int id,
Network parent)
id - ID of rule.parent - parent of the rule.public int getId()
public java.lang.String getName()
public Network getParent()
public java.util.List<ResourceCondition> getResourceConditions()
ResourceConditionpublic java.util.List<ScheduleCondition> getScheduleConditions()
ScheduleConditionpublic java.util.List<ResourceAction> getResourceActions()
ResourceActionpublic java.util.List<Scene> getSceneActions()
Scenepublic boolean isReady()
NativeCallbacks.ruleInfoCallback(boolean, java.lang.String, int, java.lang.String, java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.Object)
or retrieved from cache.protected void internalClearAddResourceConditions(java.util.Collection<ResourceCondition> resourceConditions)
resourceConditions is updated.resourceConditions - resourceConditions which
needs to be added to resourceConditions.protected void internalClearAddScheduleConditions(java.util.Collection<ScheduleCondition> scheduleConditions)
scheduleConditions is updated.scheduleConditions - ScheduleCondition collections which needs
to be added to scheduleConditions.protected void internalClearAddResourceActions(java.util.Collection<ResourceAction> resourceActions)
resourceActions of the rule is updated.resourceActions - ResourceAction collection which needs to be added
to resourceActions.protected void internalClearAddSceneActions(java.util.Collection<Scene> scenesActions)
sceneActions of the rule is updated.scenesActions - SceneActions collections which needs to added
to sceneActions.protected void internalSetName(java.lang.String name)
name is updated.name - Updated name of the rule.protected void internalSetParent(Network parent)
parent - Network which is the parent of the rule.protected void internalMarkAsReady()
public final int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object