Search in sources :

Example 21 with AssetAttribute

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

the class AbstractProtocol method updateLinkedProtocolConfiguration.

/**
 * Update a linked protocol configuration; allows protocols to reconfigure their own protocol configurations to
 * persist changing data e.g. authorization tokens. First this clones the existing protocolConfiguration and calls
 * the consumer to perform the modification.
 */
protected final void updateLinkedProtocolConfiguration(AssetAttribute protocolConfiguration, Consumer<AssetAttribute> protocolUpdater) {
    withLock(getProtocolName() + "::updateLinkedProtocolConfiguration", () -> {
        // Clone the protocol configuration rather than modify this one
        AssetAttribute modifiedProtocolConfiguration = protocolConfiguration.deepCopy();
        protocolUpdater.accept(modifiedProtocolConfiguration);
        assetService.updateProtocolConfiguration(modifiedProtocolConfiguration);
    });
}
Also used : AssetAttribute(org.openremote.model.asset.AssetAttribute)

Example 22 with AssetAttribute

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

the class AbstractVelbusProtocol method processLinkedAttributeWrite.

@Override
protected void processLinkedAttributeWrite(AttributeEvent event, AssetAttribute protocolConfiguration) {
    Pair<VelbusNetwork, Consumer<ConnectionStatus>> velbusNetworkConsumerPair = networkConfigurationMap.get(protocolConfiguration.getReferenceOrThrow());
    if (velbusNetworkConsumerPair == null) {
        return;
    }
    VelbusNetwork velbusNetwork = velbusNetworkConsumerPair.key;
    AssetAttribute attribute = getLinkedAttribute(event.getAttributeRef());
    if (attribute == null) {
        return;
    }
    // Get the device that this attribute is linked to
    int deviceAddress = getVelbusDeviceAddress(attribute);
    // Get the property that this attribute is linked to
    String property = getVelbusDevicePropertyLink(attribute);
    velbusNetwork.writeProperty(deviceAddress, property, event.getValue().orElse(null));
}
Also used : Consumer(java.util.function.Consumer) AssetAttribute(org.openremote.model.asset.AssetAttribute)

Example 23 with AssetAttribute

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

the class AbstractVelbusProtocol method doLinkAttribute.

@Override
protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {
    Pair<VelbusNetwork, Consumer<ConnectionStatus>> velbusNetworkConsumerPair = networkConfigurationMap.get(protocolConfiguration.getReferenceOrThrow());
    if (velbusNetworkConsumerPair == null) {
        LOG.info("Protocol Configuration doesn't have a valid VelbusNetwork so cannot link");
        return;
    }
    VelbusNetwork velbusNetwork = velbusNetworkConsumerPair.key;
    // Get the device that this attribute is linked to
    int deviceAddress = getVelbusDeviceAddress(attribute);
    // Get the property that this attribute is linked to
    String property = getVelbusDevicePropertyLink(attribute);
    AttributeRef attributeRef = attribute.getReferenceOrThrow();
    ValueType valueType = attribute.getType().orElse(AttributeType.STRING).getValueType();
    LOG.fine("Linking attribute to device '" + deviceAddress + "' and property '" + property + "': " + attributeRef);
    Consumer<DevicePropertyValue> propertyValueConsumer = propertyValue -> updateLinkedAttribute(new AttributeState(attributeRef, propertyValue != null ? propertyValue.toValue(valueType) : null));
    attributePropertyValueConsumers.put(attributeRef, propertyValueConsumer);
    velbusNetwork.addPropertyValueConsumer(deviceAddress, property, propertyValueConsumer);
}
Also used : java.util(java.util) CodecUtil(org.openremote.container.util.CodecUtil) ConnectionStatus(org.openremote.model.asset.agent.ConnectionStatus) VelbusConfiguration(org.openremote.agent.protocol.velbus.VelbusConfiguration) org.openremote.agent.protocol(org.openremote.agent.protocol) FeatureProcessor(org.openremote.agent.protocol.velbus.device.FeatureProcessor) VelbusDeviceType(org.openremote.agent.protocol.velbus.device.VelbusDeviceType) Level(java.util.logging.Level) AgentLink(org.openremote.model.asset.agent.AgentLink) Document(org.w3c.dom.Document) PROTOCOL_NAMESPACE(org.openremote.model.Constants.PROTOCOL_NAMESPACE) REGEXP_PATTERN_INTEGER_POSITIVE_NON_ZERO(org.openremote.model.util.TextUtil.REGEXP_PATTERN_INTEGER_POSITIVE_NON_ZERO) InputSource(org.xml.sax.InputSource) NodeList(org.w3c.dom.NodeList) ValueType(org.openremote.model.value.ValueType) Asset(org.openremote.model.asset.Asset) AssetType(org.openremote.model.asset.AssetType) Pair(org.openremote.model.util.Pair) FileInfo(org.openremote.model.file.FileInfo) EnumUtil(org.openremote.model.util.EnumUtil) Logger(java.util.logging.Logger) AssetMeta(org.openremote.model.asset.AssetMeta) Consumer(java.util.function.Consumer) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) org.openremote.model.attribute(org.openremote.model.attribute) Values(org.openremote.model.value.Values) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TextUtil.isNullOrEmpty(org.openremote.model.util.TextUtil.isNullOrEmpty) AssetAttribute(org.openremote.model.asset.AssetAttribute) DevicePropertyValue(org.openremote.agent.protocol.velbus.device.DevicePropertyValue) Consumer(java.util.function.Consumer) ValueType(org.openremote.model.value.ValueType) DevicePropertyValue(org.openremote.agent.protocol.velbus.device.DevicePropertyValue)

Example 24 with AssetAttribute

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

the class AssetViewActivity method onAgentStatusEvent.

protected void onAgentStatusEvent(AgentStatusEvent event) {
    for (AttributeView attributeView : attributeViews) {
        AssetAttribute assetAttribute = attributeView.getAttribute();
        Optional<AttributeRef> assetAttributeRef = assetAttribute.getReference();
        if (asset.getWellKnownType() == AssetType.AGENT) {
            if (assetAttributeRef.map(ref -> ref.equals(event.getProtocolConfiguration())).orElse(false)) {
                attributeView.setStatus(event.getConnectionStatus());
            }
        } else {
            AgentLink.getAgentLink(assetAttribute).filter(agentLink -> agentLink.equals(event.getProtocolConfiguration())).ifPresent(agentLink -> {
                attributeView.setStatus(event.getConnectionStatus());
            });
        }
    }
}
Also used : SimulatorState(org.openremote.model.simulator.SimulatorState) DatapointInterval(org.openremote.model.datapoint.DatapointInterval) AssetMapper(org.openremote.app.client.assets.AssetMapper) Environment(org.openremote.app.client.Environment) ProtocolConfiguration(org.openremote.model.asset.agent.ProtocolConfiguration) AttributeRef(org.openremote.model.attribute.AttributeRef) AssetDatapointResource(org.openremote.model.datapoint.AssetDatapointResource) AttributeViewImpl(org.openremote.app.client.assets.attributes.AttributeViewImpl) ObjectValueMapper(org.openremote.app.client.interop.value.ObjectValueMapper) FormButton(org.openremote.app.client.widget.FormButton) NumberDatapoint(org.openremote.model.datapoint.NumberDatapoint) ArrayList(java.util.ArrayList) AgentLink(org.openremote.model.asset.agent.AgentLink) Inject(javax.inject.Inject) ReadAssetAttributesEvent(org.openremote.model.asset.ReadAssetAttributesEvent) TenantFilter(org.openremote.model.event.shared.TenantFilter) AttributeEvent(org.openremote.model.attribute.AttributeEvent) URL(com.google.gwt.http.client.URL) AbstractAttributeViewExtension(org.openremote.app.client.assets.attributes.AbstractAttributeViewExtension) AttributeView(org.openremote.app.client.assets.attributes.AttributeView) AgentStatusEventMapper(org.openremote.app.client.assets.AgentStatusEventMapper) Consumer(org.openremote.model.interop.Consumer) AgentResource(org.openremote.model.asset.agent.AgentResource) MapResource(org.openremote.model.map.MapResource) AgentStatusEvent(org.openremote.model.asset.agent.AgentStatusEvent) AssetType(org.openremote.model.asset.AssetType) DatapointBrowser(org.openremote.app.client.datapoint.DatapointBrowser) JsonEditor(org.openremote.app.client.app.dialog.JsonEditor) Constants(org.openremote.model.Constants) AssetResource(org.openremote.model.asset.AssetResource) Provider(com.google.inject.Provider) List(java.util.List) AssetBrowser(org.openremote.app.client.assets.browser.AssetBrowser) NumberDatapointArrayMapper(org.openremote.app.client.datapoint.NumberDatapointArrayMapper) Optional(java.util.Optional) Values(org.openremote.model.value.Values) TextUtil.isNullOrEmpty(org.openremote.model.util.TextUtil.isNullOrEmpty) AssetAttribute(org.openremote.model.asset.AssetAttribute) Datapoint(org.openremote.model.datapoint.Datapoint) Collections(java.util.Collections) Simulator(org.openremote.app.client.simulator.Simulator) AttributeExecuteStatus(org.openremote.model.attribute.AttributeExecuteStatus) AttributeView(org.openremote.app.client.assets.attributes.AttributeView) AttributeRef(org.openremote.model.attribute.AttributeRef) AssetAttribute(org.openremote.model.asset.AssetAttribute)

Example 25 with AssetAttribute

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

the class AbstractManagerSetup method addDemoApartmentSceneEnableDisableTimer.

protected void addDemoApartmentSceneEnableDisableTimer(ServerAsset apartment, ServerAsset agent, Scene[] scenes) {
    AssetAttribute enableAllMacro = initProtocolConfiguration(new AssetAttribute("enableSceneTimer"), MacroProtocol.PROTOCOL_NAME).addMeta(new MetaItem(LABEL, Values.create("Enable scene timer")));
    for (Scene scene : scenes) {
        for (DayOfWeek dayOfWeek : DayOfWeek.values()) {
            String sceneAttributeName = scene.attributeName + "Enabled" + dayOfWeek;
            enableAllMacro.getMeta().add(new MacroAction(new AttributeState(new AttributeRef(apartment.getId(), sceneAttributeName), Values.create(true))).toMetaItem());
        }
    }
    enableAllMacro.getMeta().add(new MacroAction(new AttributeState(new AttributeRef(apartment.getId(), "sceneTimerEnabled"), Values.create(true))).toMetaItem());
    agent.addAttributes(enableAllMacro);
    AssetAttribute disableAllMacro = initProtocolConfiguration(new AssetAttribute("disableSceneTimer"), MacroProtocol.PROTOCOL_NAME).addMeta(new MetaItem(LABEL, Values.create("Disable scene timer")));
    for (Scene scene : scenes) {
        for (DayOfWeek dayOfWeek : DayOfWeek.values()) {
            String sceneAttributeName = scene.attributeName + "Enabled" + dayOfWeek;
            disableAllMacro.getMeta().add(new MacroAction(new AttributeState(new AttributeRef(apartment.getId(), sceneAttributeName), Values.create(false))).toMetaItem());
        }
    }
    disableAllMacro.getMeta().add(new MacroAction(new AttributeState(new AttributeRef(apartment.getId(), "sceneTimerEnabled"), Values.create(false))).toMetaItem());
    agent.addAttributes(disableAllMacro);
}
Also used : MacroAction(org.openremote.agent.protocol.macro.MacroAction) 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