Search in sources :

Example 26 with AssetAttribute

use of org.openremote.model.asset.AssetAttribute in project openremote by openremote.

the class AbstractManagerSetup method linkDemoApartmentWithSceneAgent.

protected void linkDemoApartmentWithSceneAgent(ServerAsset apartment, ServerAsset agent, Scene[] scenes) {
    for (Scene scene : scenes) {
        apartment.addAttributes(new AssetAttribute(scene.attributeName, AttributeType.STRING, Values.create(AttributeExecuteStatus.READY.name())).setMeta(new MetaItem(LABEL, Values.create(scene.attributeLabel)), new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)), new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)), new MetaItem(EXECUTABLE, Values.create(true)), new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), scene.attributeName).toArrayValue())), new AssetAttribute(scene.attributeName + "AlarmEnabled", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create(scene.attributeLabel + " alarm enabled")), new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)), new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)), new MetaItem(META_MACRO_ACTION_INDEX, Values.create(0)), new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), scene.attributeName).toArrayValue())), new AssetAttribute(scene.attributeName + "TargetTemperature", AttributeType.NUMBER).setMeta(new MetaItem(LABEL, Values.create(scene.attributeLabel + " target temperature")), new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)), new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)), new MetaItem(META_MACRO_ACTION_INDEX, Values.create(1)), new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), scene.attributeName).toArrayValue())));
        for (DayOfWeek dayOfWeek : DayOfWeek.values()) {
            // "MONDAY" => "Monday"
            String dayOfWeekLabel = dayOfWeek.name().substring(0, 1) + dayOfWeek.name().substring(1).toLowerCase(Locale.ROOT);
            apartment.addAttributes(new AssetAttribute(scene.attributeName + "Time" + dayOfWeek.name(), AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create(scene.attributeLabel + " time " + dayOfWeekLabel)), new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)), new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)), new MetaItem(RULE_STATE, Values.create(true)), new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())), new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), scene.attributeName + dayOfWeek.name()).toArrayValue())), new AssetAttribute(scene.attributeName + "Enabled" + dayOfWeek.name(), AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create(scene.attributeLabel + " enabled " + dayOfWeekLabel)), new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)), new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)), new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())), new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), scene.attributeName + dayOfWeek.name()).toArrayValue())));
        }
    }
    apartment.addAttributes(// The scene timer is enabled when the timer protocol starts
    new AssetAttribute("sceneTimerEnabled", AttributeType.BOOLEAN, Values.create(true)).setMeta(new MetaItem(LABEL, Values.create("Scene timer enabled")), new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)), new MetaItem(SHOW_ON_DASHBOARD, Values.create(true)), new MetaItem(READ_ONLY, Values.create(true))), new AssetAttribute("enableSceneTimer", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Enable scene timer")), new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)), new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)), new MetaItem(EXECUTABLE, Values.create(true)), new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), "enableSceneTimer").toArrayValue())), new AssetAttribute("disableSceneTimer", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Disable scene timer")), new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)), new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)), new MetaItem(EXECUTABLE, Values.create(true)), new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), "disableSceneTimer").toArrayValue())));
}
Also used : DayOfWeek(java.time.DayOfWeek) AssetAttribute(org.openremote.model.asset.AssetAttribute)

Aggregations

AssetAttribute (org.openremote.model.asset.AssetAttribute)26 Logger (java.util.logging.Logger)7 Level (java.util.logging.Level)6 Asset (org.openremote.model.asset.Asset)6 AssetMeta (org.openremote.model.asset.AssetMeta)6 Values (org.openremote.model.value.Values)6 List (java.util.List)5 Optional (java.util.Optional)5 Consumer (java.util.function.Consumer)5 Container (org.openremote.container.Container)5 ProtocolConfiguration (org.openremote.model.asset.agent.ProtocolConfiguration)5 Pair (org.openremote.model.util.Pair)5 java.util (java.util)4 Protocol (org.openremote.agent.protocol.Protocol)4 GlobalLock.withLock (org.openremote.container.concurrent.GlobalLock.withLock)4 TextUtil (org.openremote.model.util.TextUtil)4 TimeUnit (java.util.concurrent.TimeUnit)3 HttpMethod (javax.ws.rs.HttpMethod)3 AbstractProtocol (org.openremote.agent.protocol.AbstractProtocol)3 ServerAsset (org.openremote.manager.asset.ServerAsset)3