100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Fixed setup
Christian Bauer8b15bb7fa4a0
diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.javaindex 6d80c08ad..060bdd6dc 100644--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java@@ -20,14 +20,11 @@package org.openremote.manager.server.setup.builtin;import com.vividsolutions.jts.geom.Coordinate;-import org.openremote.agent.protocol.macro.MacroAction;-import org.openremote.agent.protocol.macro.MacroProtocol;import org.openremote.agent.protocol.simulator.SimulatorProtocol;import org.openremote.agent.protocol.simulator.element.ColorSimulatorElement;import org.openremote.agent.protocol.simulator.element.DecimalSimulatorElement;import org.openremote.agent.protocol.simulator.element.IntegerSimulatorElement;import org.openremote.agent.protocol.simulator.element.SwitchSimulatorElement;-import org.openremote.agent.protocol.timer.TimerValue;import org.openremote.container.Container;import org.openremote.manager.server.asset.ServerAsset;import org.openremote.manager.server.setup.AbstractManagerSetup;@@ -37,18 +34,12 @@ import org.openremote.model.asset.AssetState;import org.openremote.model.attribute.*;import org.openremote.model.value.Values;-import java.time.DayOfWeek;import java.time.LocalDateTime;import java.time.ZoneId;import java.time.ZonedDateTime;-import java.util.ArrayList;import java.util.Arrays;import java.util.List;-import java.util.Locale;-import static org.openremote.agent.protocol.macro.MacroProtocol.META_MACRO_ACTION_INDEX;-import static org.openremote.agent.protocol.timer.TimerConfiguration.initTimerConfiguration;-import static org.openremote.agent.protocol.timer.TimerProtocol.META_TIMER_VALUE_LINK;import static org.openremote.model.asset.AssetMeta.*;import static org.openremote.model.asset.AssetType.*;import static org.openremote.model.asset.agent.ProtocolConfiguration.initProtocolConfiguration;@@ -475,297 +466,4 @@ public class ManagerDemoSetup extends AbstractManagerSetup {assetStorageService.storeUserAsset(keycloakDemoSetup.testuser3Id, apartment1LivingroomId);assetStorageService.storeUserAsset(keycloakDemoSetup.testuser3Id, apartment2Id);}-- // ################################ Demo apartment with complex scenes ###################################-- protected ServerAsset createDemoApartment(ServerAsset parent, String name, Coordinate location) {- ServerAsset apartment = new ServerAsset(name, RESIDENCE, parent);- apartment.setLocation(geometryFactory.createPoint(location));- apartment.setAttributes(- new AssetAttribute("alarmEnabled", AttributeType.BOOLEAN, Values.create(false))- .setMeta(new Meta(- new MetaItem(LABEL, Values.create("Alarm enabled")),- new MetaItem(READ_ONLY, Values.create(true)),- new MetaItem(DESCRIPTION, Values.create("Send notifications when presence is detected")),- new MetaItem(RULE_STATE, Values.create(true))- )),- new AssetAttribute("vacationDays", AttributeType.INTEGER)- .setMeta(new Meta(- new MetaItem(LABEL, Values.create("Vacation days")),- new MetaItem(DESCRIPTION, Values.create("Enable vacation mode for given days")),- new MetaItem(RULE_STATE, Values.create(true))- )),- new AssetAttribute("autoSceneSchedule", AttributeType.BOOLEAN, Values.create(false))- .setMeta(- new MetaItem(LABEL, Values.create("Automatic scene schedule")),- new MetaItem(DESCRIPTION, Values.create("Predict presence and automatically adjust scene schedule")),- new MetaItem(RULE_STATE, Values.create(true))- ),- new AssetAttribute("lastExecutedScene", AttributeType.STRING, Values.create("HOME"))- .setMeta(- new MetaItem(LABEL, Values.create("Last executed scene")),- new MetaItem(READ_ONLY, Values.create(true)),- new MetaItem(RULE_STATE, Values.create(true))- )- );- return apartment;- }-- protected ServerAsset createDemoApartmentRoom(ServerAsset apartment, String name) {- ServerAsset room = new ServerAsset(name, ROOM, apartment);- room.setLocation(apartment.getLocation());- room.setAttributes(- new AssetAttribute("motionCount", AttributeType.INTEGER)- .setMeta(- new MetaItem(LABEL, Values.create("Motion Count")),- new MetaItem(DESCRIPTION, Values.create("Sensor that increments a counter when motion is detected")),- new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(RULE_EVENT, Values.create(true))- ),- new AssetAttribute("presenceDetected", AttributeType.BOOLEAN)- .setMeta(- new MetaItem(LABEL, Values.create("Presence Detected")),- new MetaItem(DESCRIPTION, Values.create("Someone is currently present in the room")),- new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTECTED, Values.create(true)),- new MetaItem(READ_ONLY, Values.create(true))- ),-// new AssetAttribute("firstPresenceDetected", AttributeType.DECIMAL)-// .setMeta(-// new MetaItem(LABEL, Values.create("First Presence Timestamp")),-// new MetaItem(DESCRIPTION, Values.create("Timestamp of the first detected presence")),-// new MetaItem(RULE_STATE, Values.create(true)),-// new MetaItem(PROTECTED, Values.create(true)),-// new MetaItem(READ_ONLY, Values.create(true))-// ),- new AssetAttribute("lastPresenceDetected", AttributeType.DECIMAL)- .setMeta(- new MetaItem(LABEL, Values.create("Last Presence Timestamp")),- new MetaItem(DESCRIPTION, Values.create("Timestamp of last detected presence")),- new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTECTED, Values.create(true)),- new MetaItem(READ_ONLY, Values.create(true))- ),- new AssetAttribute("co2Level", AttributeType.DECIMAL)- .setMeta(- new MetaItem(LABEL, Values.create("CO2 Level")),- new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTECTED, Values.create(true)),- new MetaItem(READ_ONLY, Values.create(true))- ),- new AssetAttribute("humidity", AttributeType.DECIMAL)- .setMeta(- new MetaItem(LABEL, Values.create("Humidity")),- new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTECTED, Values.create(true)),- new MetaItem(READ_ONLY, Values.create(true))- ),- new AssetAttribute("currentTemperature", DECIMAL)- .setMeta(- new MetaItem(LABEL, Values.create("Current temperature")),- new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTECTED, Values.create(true)),- new MetaItem(READ_ONLY, Values.create(true))- ),- new AssetAttribute("targetTemperature", DECIMAL)- .setMeta(- new MetaItem(LABEL, Values.create("Target Temperature")),- new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTECTED, Values.create(true))- )- );- return room;- }-- protected ServerAsset createDemoApartmentServiceAgent(ServerAsset apartment) {- ServerAsset agent = new ServerAsset("Service Agent (Simulator)", AGENT, apartment);- agent.setLocation(apartment.getLocation());- agent.setAttributes(- initProtocolConfiguration(new AssetAttribute("apartmentSimulator"), SimulatorProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(- SimulatorProtocol.CONFIG_MODE,- Values.create(SimulatorProtocol.Mode.WRITE_THROUGH_DELAYED.toString())- ),- new MetaItem(- SimulatorProtocol.CONFIG_WRITE_DELAY_MILLISECONDS,- Values.create(500)- )),- initProtocolConfiguration(new AssetAttribute("roomSimulator"), SimulatorProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(- SimulatorProtocol.CONFIG_MODE,- Values.create(SimulatorProtocol.Mode.WRITE_THROUGH_DELAYED.toString())- ),- new MetaItem(- SimulatorProtocol.CONFIG_WRITE_DELAY_MILLISECONDS,- Values.create(500)- ))- );- return agent;- }-- protected void linkDemoApartmentWithServiceAgent(ServerAsset apartment, ServerAsset agent) {- for (AssetAttribute attribute : apartment.getAttributesList()) {- String name = attribute.getName().orElseThrow(- () -> new IllegalStateException("Missing apartment attribute name: " + attribute)- );- switch (name) {- // TODO Any attributes of apartment to link with simulator?- }- }- }-- protected void linkDemoApartmentRoomWithServiceAgent(ServerAsset room, ServerAsset agent) {- for (AssetAttribute attribute : room.getAttributesList()) {- String name = attribute.getName().orElseThrow(- () -> new IllegalStateException("Missing apartment room attribute name: " + attribute)- );- switch (name) {- case "motionCount":- attribute.getMeta().add(- new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), "roomSimulator").toArrayValue()),- new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(IntegerSimulatorElement.ELEMENT_NAME_INTEGER))- );- break;- case "co2Level":- attribute.getMeta().add(- new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), "roomSimulator").toArrayValue()),- new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(DecimalSimulatorElement.ELEMENT_NAME))- );- break;- case "humidity":- attribute.getMeta().add(- new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), "roomSimulator").toArrayValue()),- new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(DecimalSimulatorElement.ELEMENT_NAME))- );- break;- case "currentTemperature":- attribute.getMeta().add(- new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), "roomSimulator").toArrayValue()),- new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(DecimalSimulatorElement.ELEMENT_NAME))- );- break;- case "targetTemperature":- attribute.getMeta().add(- new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), "roomSimulator").toArrayValue()),- new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(DecimalSimulatorElement.ELEMENT_NAME))- );- break;- }- }- }-- public static class Scene {-- final String attributeName;- final String attributeLabel;- final String internalName;- final String startTime;- final boolean alarmEnabled;- final double targetTemperature;-- public Scene(String attributeName,- String attributeLabel,- String internalName,- String startTime,- boolean alarmEnabled,- double targetTemperature) {- this.attributeName = attributeName;- this.attributeLabel = attributeLabel;- this.internalName = internalName;- this.startTime = startTime;- this.alarmEnabled = alarmEnabled;- this.targetTemperature = targetTemperature;- }-- AssetAttribute createMacroAttribute(ServerAsset apartment, ServerAsset... rooms) {- AssetAttribute attribute = initProtocolConfiguration(new AssetAttribute(attributeName), MacroProtocol.PROTOCOL_NAME)- .addMeta(new MetaItem(LABEL, Values.create(attributeLabel)));- attribute.getMeta().add(- new MacroAction(new AttributeState(new AttributeRef(apartment.getId(), "alarmEnabled"), Values.create(alarmEnabled))).toMetaItem()- );- for (ServerAsset room : rooms) {- attribute.getMeta().add(- new MacroAction(new AttributeState(new AttributeRef(room.getId(), "targetTemperature"), Values.create(targetTemperature))).toMetaItem()- );- }- attribute.getMeta().add(- new MacroAction(new AttributeState(new AttributeRef(apartment.getId(), "lastExecutedScene"), Values.create(internalName))).toMetaItem()- );- return attribute;- }-- AssetAttribute[] createTimerAttributes(ServerAsset apartment) {- List<AssetAttribute> attributes = new ArrayList<>();- for (DayOfWeek dayOfWeek : DayOfWeek.values()) {- // "MONDAY" => "Monday"- String dayName = dayOfWeek.name().substring(0, 1) + dayOfWeek.name().substring(1).toLowerCase(Locale.ROOT);- // "0 0 7 ? *" => "0 0 7 ? * MON *"- String timePattern = startTime + " " + dayOfWeek.name().substring(0, 3).toUpperCase(Locale.ROOT) + " *";- attributes.add(- initTimerConfiguration(new AssetAttribute(attributeName + dayName), timePattern,- new AttributeState(apartment.getId(), attributeName, Values.create("REQUEST_START")))- .addMeta(new MetaItem(LABEL, Values.create(attributeLabel + " trigger " + dayName)))- );- }- return attributes.toArray(new AssetAttribute[attributes.size()]);- }- }-- protected ServerAsset createDemoApartmentSceneAgent(ServerAsset apartment, Scene[] scenes, ServerAsset... rooms) {- ServerAsset agent = new ServerAsset("Scene Agent", AGENT, apartment);- agent.setLocation(apartment.getLocation());- for (Scene scene : scenes) {- agent.addAttributes(scene.createMacroAttribute(apartment, rooms));- }- for (Scene scene : scenes) {- agent.addAttributes(scene.createTimerAttributes(apartment));- }- return agent;- }-- 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(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(META_MACRO_ACTION_INDEX, Values.create(0)),- new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), scene.attributeName).toArrayValue())- ),- new AssetAttribute(scene.attributeName + "TargetTemperature", AttributeType.DECIMAL)- .setMeta(- new MetaItem(LABEL, Values.create(scene.attributeLabel + " target temperature")),- 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 dayName = 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 " + dayName)),- 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 + dayName).toArrayValue())- ),- new AssetAttribute(scene.attributeName + "Enabled" + dayOfWeek.name(), AttributeType.BOOLEAN)- .setMeta(- new MetaItem(LABEL, Values.create(scene.attributeLabel + " enabled " + dayName)),- new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),- new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), scene.attributeName + dayName).toArrayValue())- )- );- }- }- }}\ No newline at end of file