forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[influxdb] Add option for using metadata value as measurement name (o…
…penhab#9943) * Add option for using metadata value as measurement name Also-by: Joan Pujol <joanpujol@gmail.com> Signed-off-by: Johannes Ott <info@johannes-ott.net>
- Loading branch information
Showing
11 changed files
with
315 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...fluxdb/src/main/java/org/openhab/persistence/influxdb/internal/InfluxDBMetadataUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.persistence.influxdb.internal; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.core.items.Metadata; | ||
import org.openhab.core.items.MetadataKey; | ||
import org.openhab.core.items.MetadataRegistry; | ||
import org.openhab.persistence.influxdb.InfluxDBPersistenceService; | ||
|
||
/** | ||
* Logic to use items metadata from an openHAB {@link Item} | ||
* | ||
* @author Johannes Ott - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class InfluxDBMetadataUtils { | ||
|
||
private InfluxDBMetadataUtils() { | ||
} | ||
|
||
public static String calculateMeasurementNameFromMetadataIfPresent( | ||
final @Nullable MetadataRegistry currentMetadataRegistry, String name, @Nullable String itemName) { | ||
|
||
if (itemName == null || currentMetadataRegistry == null) { | ||
return name; | ||
} | ||
|
||
MetadataKey key = new MetadataKey(InfluxDBPersistenceService.SERVICE_NAME, itemName); | ||
Metadata metadata = currentMetadataRegistry.get(key); | ||
if (metadata != null) { | ||
String metaName = metadata.getValue(); | ||
if (!metaName.isBlank()) { | ||
name = metaName; | ||
} | ||
} | ||
|
||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.