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);
});
}
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));
}
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);
}
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());
});
}
}
}
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);
}
Aggregations