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
Updated EnergyOptimisationService.java to react to attribute events on optimisation assets
Rich Turner80276dc06af4
diff --git a/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorAgent.java b/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorAgent.javaindex ab5e73fab..c2f954ab4 100644--- a/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorAgent.java+++ b/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorAgent.java@@ -55,8 +55,6 @@ public class SimulatorAgent extends Agent<SimulatorAgent, SimulatorProtocol, Sim}}- public static final AttributeDescriptor<String> SERIAL_SERIAL_PORT = SERIAL_PORT.withOptional(false);-public static final AgentDescriptor<SimulatorAgent, SimulatorProtocol, SimulatorAgentLink> DESCRIPTOR = new AgentDescriptor<>(SimulatorAgent.class, SimulatorProtocol.class, SimulatorAgentLink.class);diff --git a/manager/src/main/java/org/openremote/manager/energy/EnergyOptimisationService.java b/manager/src/main/java/org/openremote/manager/energy/EnergyOptimisationService.javaindex 99793522c..163ddc0e4 100644--- a/manager/src/main/java/org/openremote/manager/energy/EnergyOptimisationService.java+++ b/manager/src/main/java/org/openremote/manager/energy/EnergyOptimisationService.java@@ -32,6 +32,8 @@ import org.openremote.model.Container;import org.openremote.model.ContainerService;import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetDescriptor;+import org.openremote.model.asset.AssetEvent;+import org.openremote.model.asset.AssetFilter;import org.openremote.model.asset.impl.*;import org.openremote.model.attribute.Attribute;import org.openremote.model.attribute.AttributeEvent;@@ -139,6 +141,11 @@ public class EnergyOptimisationService extends RouteBuilder implements ContainerLOG.fine("Found enabled optimisation asset count = " + energyOptimisationAssets.size());energyOptimisationAssets.forEach(this::startOptimisation);++ clientEventService.addInternalSubscription(+ AttributeEvent.class,+ new AssetFilter<>(energyOptimisationAssets.stream().map(Asset::getId).toArray(String[]::new)),+ this::processAttributeChange);}@SuppressWarnings("unchecked")@@ -168,6 +175,31 @@ public class EnergyOptimisationService extends RouteBuilder implements Container}}+ protected void processAttributeChange(AttributeEvent attributeEvent) {++ OptimisationInstance optimisationInstance = assetOptimisationInstanceMap.get(attributeEvent.getAssetId());++ if (optimisationInstance == null) {+ return;+ }++ if (EnergyOptimisationAsset.FINANCIAL_SAVING.getName().equals(attributeEvent.getAttributeName())+ || EnergyOptimisationAsset.CARBON_SAVING.getName().equals(attributeEvent.getAttributeName())) {+ // These are updated by this service+ return;+ }++ LOG.info("Processing optimisation asset attribute event: " + attributeEvent);+ stopOptimisation(attributeEvent.getAssetId());++ // Get latest asset from storage+ EnergyOptimisationAsset asset = (EnergyOptimisationAsset)assetStorageService.find(attributeEvent.getAssetId());++ if (asset != null && !asset.isOptimisationDisabled().orElse(false)) {+ startOptimisation(asset);+ }+ }+protected void startOptimisation(EnergyOptimisationAsset optimisationAsset) {LOG.fine("Initialising optimiser for optimisation asset: " + optimisationAsset);double intervalSize = optimisationAsset.getIntervalSize().orElse(0.25d);diff --git a/model/src/main/java/org/openremote/model/asset/impl/EnergyOptimisationAsset.java b/model/src/main/java/org/openremote/model/asset/impl/EnergyOptimisationAsset.javaindex 242fdc3db..21b8bb235 100644--- a/model/src/main/java/org/openremote/model/asset/impl/EnergyOptimisationAsset.java+++ b/model/src/main/java/org/openremote/model/asset/impl/EnergyOptimisationAsset.java@@ -39,8 +39,8 @@ public class EnergyOptimisationAsset extends Asset<EnergyOptimisationAsset> {.withUnits(UNITS_PERCENTAGE).withConstraints(new ValueConstraint.Min(0), new ValueConstraint.Max(100));public static final AttributeDescriptor<Double> INTERVAL_SIZE = new AttributeDescriptor<>("intervalSize", POSITIVE_NUMBER);public static final AttributeDescriptor<Boolean> OPTIMISATION_DISABLED = new AttributeDescriptor<>("optimisationDisabled", BOOLEAN, new MetaItem<>(READ_ONLY));- public static final AttributeDescriptor<Double> FINANCIAL_SAVING = new AttributeDescriptor<>("financialSaving", NUMBER).withUnits("EUR");- public static final AttributeDescriptor<Double> CARBON_SAVING = new AttributeDescriptor<>("carbonSaving", NUMBER).withUnits(UNITS_KILO, UNITS_GRAM);+ public static final AttributeDescriptor<Double> FINANCIAL_SAVING = new AttributeDescriptor<>("financialSaving", NUMBER, new MetaItem<>(READ_ONLY)).withUnits("EUR");+ public static final AttributeDescriptor<Double> CARBON_SAVING = new AttributeDescriptor<>("carbonSaving", NUMBER, new MetaItem<>(READ_ONLY)).withUnits(UNITS_KILO, UNITS_GRAM);public static final AssetDescriptor<EnergyOptimisationAsset> DESCRIPTOR = new AssetDescriptor<>("flash", "C4DB0D", EnergyOptimisationAsset.class);diff --git a/model/src/main/java/org/openremote/model/value/ValueDescriptor.java b/model/src/main/java/org/openremote/model/value/ValueDescriptor.javaindex fd394088b..0499bf14d 100644--- a/model/src/main/java/org/openremote/model/value/ValueDescriptor.java+++ b/model/src/main/java/org/openremote/model/value/ValueDescriptor.java@@ -135,6 +135,7 @@ public class ValueDescriptor<T> implements NameHolder, Serializable {// }public static final ValueDescriptor<Object> UNKNOWN = new ValueDescriptor<>("Unknown", Object.class);+protected String name;@JsonSerialize(converter = ValueDescriptor.ValueTypeStringConverter.class)protected Class<T> type;diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.tsindex 60dee2656..7a7b49242 100644--- a/ui/component/or-chart/src/index.ts+++ b/ui/component/or-chart/src/index.ts@@ -585,7 +585,7 @@ export class OrChart extends translate(i18next)(LitElement) {<span>${this.assets[assetIndex].name}</span><span style="font-size:14px; color:grey;">${label}</span></div>- <button class="button-clear" @click="${() => this._deleteAttribute(assetIndex)}"><or-icon icon="close-circle"></or-icon></button>+ <button class="button-clear" @click="${() => this._deleteAttribute(index)}"><or-icon icon="close-circle"></or-icon></button></div>`})}