Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OEM-Bundle: implement a OpenEMS OEM bundle #2428

Merged
merged 6 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions io.openems.backend.application/BackendApp.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
io.openems.backend.timedata.timescaledb;version=snapshot,\
io.openems.backend.uiwebsocket;version=snapshot,\
io.openems.common;version=snapshot,\
io.openems.oem.openems;version=snapshot,\
io.openems.shared.influxdb;version=snapshot,\
io.openems.wrapper.aXMLRPC;version=snapshot,\
io.openems.wrapper.fastexcel;version=snapshot,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.gson.JsonObject;

import io.openems.common.OpenemsOEM;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.jsonrpc.base.JsonrpcRequest;
import io.openems.common.utils.JsonUtils;
Expand All @@ -20,14 +19,14 @@ public class RegisterUserRequest extends JsonrpcRequest {
public static RegisterUserRequest from(JsonrpcRequest request) throws OpenemsNamedException {
var params = request.getParams();
var user = JsonUtils.getAsJsonObject(params, "user");
var oem = JsonUtils.getAsEnum(OpenemsOEM.Manufacturer.class, params, "oem");
var oem = JsonUtils.getAsString(params, "oem");
return new RegisterUserRequest(request, user, oem);
}

private final JsonObject user;
private final OpenemsOEM.Manufacturer oem;
private final String oem;

private RegisterUserRequest(JsonrpcRequest request, JsonObject jsonObject, OpenemsOEM.Manufacturer oem) {
private RegisterUserRequest(JsonrpcRequest request, JsonObject jsonObject, String oem) {
super(request, RegisterUserRequest.METHOD);
this.user = jsonObject;
this.oem = oem;
Expand All @@ -50,7 +49,7 @@ public JsonObject getUser() {
return this.user;
}

public OpenemsOEM.Manufacturer getOem() {
public String getOem() {
return this.oem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.google.gson.JsonObject;

import io.openems.backend.common.event.BackendEventConstants;
import io.openems.common.OpenemsOEM;
import io.openems.common.channel.Level;
import io.openems.common.exceptions.OpenemsError;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
Expand Down Expand Up @@ -279,7 +278,7 @@ public static String activeStateChannelsToString(
* @param oem OEM name
* @throws OpenemsNamedException on error
*/
public void registerUser(JsonObject user, OpenemsOEM.Manufacturer oem) throws OpenemsNamedException;
public void registerUser(JsonObject user, String oem) throws OpenemsNamedException;

/**
* Update language from given user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import io.openems.backend.common.metadata.EdgeHandler;
import io.openems.backend.common.metadata.Metadata;
import io.openems.backend.common.metadata.User;
import io.openems.common.OpenemsOEM;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.request.GetEdgesRequest.PaginationOptions;
Expand Down Expand Up @@ -131,7 +130,7 @@ public int submitSetupProtocol(User user, JsonObject jsonObject) throws OpenemsN
}

@Override
public void registerUser(JsonObject user, OpenemsOEM.Manufacturer oem) throws OpenemsNamedException {
public void registerUser(JsonObject user, String oem) throws OpenemsNamedException {
throw new UnsupportedOperationException("Unsupported by Dummy Class");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import io.openems.backend.common.metadata.Metadata;
import io.openems.backend.common.metadata.SimpleEdgeHandler;
import io.openems.backend.common.metadata.User;
import io.openems.common.OpenemsOEM;
import io.openems.common.channel.Level;
import io.openems.common.event.EventReader;
import io.openems.common.exceptions.OpenemsError;
Expand Down Expand Up @@ -237,7 +236,7 @@ public int submitSetupProtocol(User user, JsonObject jsonObject) {
}

@Override
public void registerUser(JsonObject jsonObject, OpenemsOEM.Manufacturer oem) throws OpenemsNamedException {
public void registerUser(JsonObject jsonObject, String oem) throws OpenemsNamedException {
throw new UnsupportedOperationException("DummyMetadata.registerUser() is not implemented");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import io.openems.backend.common.metadata.Metadata;
import io.openems.backend.common.metadata.SimpleEdgeHandler;
import io.openems.backend.common.metadata.User;
import io.openems.common.OpenemsOEM;
import io.openems.common.channel.Level;
import io.openems.common.event.EventReader;
import io.openems.common.exceptions.OpenemsError;
Expand Down Expand Up @@ -269,7 +268,7 @@ public int submitSetupProtocol(User user, JsonObject jsonObject) {
}

@Override
public void registerUser(JsonObject jsonObject, OpenemsOEM.Manufacturer oem) throws OpenemsNamedException {
public void registerUser(JsonObject jsonObject, String oem) throws OpenemsNamedException {
throw new UnsupportedOperationException("FileMetadata.registerUser() is not implemented");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import io.openems.backend.metadata.odoo.odoo.OdooUserRole;
import io.openems.backend.metadata.odoo.odoo.OdooUtils.DateTime;
import io.openems.backend.metadata.odoo.postgres.PostgresHandler;
import io.openems.common.OpenemsOEM;
import io.openems.common.channel.Level;
import io.openems.common.event.EventReader;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
Expand Down Expand Up @@ -268,7 +267,7 @@ public int submitSetupProtocol(User user, JsonObject jsonObject) throws OpenemsN
}

@Override
public void registerUser(JsonObject jsonObject, OpenemsOEM.Manufacturer oem) throws OpenemsNamedException {
public void registerUser(JsonObject jsonObject, String oem) throws OpenemsNamedException {
final OdooUserRole role;

var roleOpt = JsonUtils.getAsOptionalString(jsonObject, "role");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import io.openems.backend.metadata.odoo.MyUser;
import io.openems.backend.metadata.odoo.odoo.Domain.Operator;
import io.openems.backend.metadata.odoo.odoo.OdooUtils.SuccessResponseAndHeaders;
import io.openems.common.OpenemsOEM;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.request.GetEdgesRequest.PaginationOptions;
Expand Down Expand Up @@ -400,7 +399,7 @@ public int submitSetupProtocol(MyUser user, JsonObject setupProtocolJson) throws
var userJson = JsonUtils.getAsJsonObject(setupProtocolJson, "customer");
var edgeJson = JsonUtils.getAsJsonObject(setupProtocolJson, "edge");
var installerJson = JsonUtils.getAsJsonObject(setupProtocolJson, "installer");
var oem = OpenemsOEM.Manufacturer.valueOf(JsonUtils.getAsString(setupProtocolJson, "oem").toUpperCase());
var oem = JsonUtils.getAsString(setupProtocolJson, "oem").toUpperCase();

var edgeId = JsonUtils.getAsString(edgeJson, "id");
var foundEdge = OdooUtils.search(this.credentials, Field.EdgeDevice.ODOO_MODEL,
Expand Down Expand Up @@ -516,8 +515,7 @@ private void sendSetupProtocolMail(MyUser user, int protocolId, String edgeId) t
* @return the Odoo user id
* @throws OpenemsNamedException on error
*/
private int createOdooUser(JsonObject userJson, String password, OpenemsOEM.Manufacturer oem)
throws OpenemsNamedException {
private int createOdooUser(JsonObject userJson, String password, String oem) throws OpenemsNamedException {
var customerFields = new HashMap<>(this.updateAddress(userJson));
customerFields.putAll(this.updateCompany(userJson));

Expand Down Expand Up @@ -760,8 +758,7 @@ private int getOdooPartnerId(int odooUserId) throws OpenemsException {
* @param oem OEM name
* @throws OpenemsNamedException on error
*/
public void registerUser(JsonObject jsonObject, OdooUserRole role, OpenemsOEM.Manufacturer oem)
throws OpenemsNamedException {
public void registerUser(JsonObject jsonObject, OdooUserRole role, String oem) throws OpenemsNamedException {
var emailOpt = JsonUtils.getAsOptionalString(jsonObject, "email");
if (!emailOpt.isPresent()) {
throw new OpenemsException("No email specified");
Expand Down Expand Up @@ -802,7 +799,7 @@ public void registerUser(JsonObject jsonObject, OdooUserRole role, OpenemsOEM.Ma
* @param oem OEM name
* @throws OpenemsNamedException error
*/
private void sendRegistrationMail(int odooUserId, OpenemsOEM.Manufacturer oem) throws OpenemsNamedException {
private void sendRegistrationMail(int odooUserId, String oem) throws OpenemsNamedException {
this.sendRegistrationMail(odooUserId, null, oem);
}

Expand All @@ -813,7 +810,7 @@ private void sendRegistrationMail(int odooUserId, OpenemsOEM.Manufacturer oem) t
* @param password password for the user
* @param oem OEM name
*/
private void sendRegistrationMail(int odooUserId, String password, OpenemsOEM.Manufacturer oem) {
private void sendRegistrationMail(int odooUserId, String password, String oem) {
try {
OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_backend/sendRegistrationEmail",
JsonUtils.buildJsonObject() //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
import io.openems.backend.common.timedata.InternalTimedataException;
import io.openems.backend.common.timedata.Timedata;
import io.openems.backend.timedata.aggregatedinflux.AllowedChannels.ChannelType;
import io.openems.common.OpenemsOEM;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.notification.AbstractDataNotification;
import io.openems.common.jsonrpc.notification.AggregatedDataNotification;
import io.openems.common.jsonrpc.notification.ResendDataNotification;
import io.openems.common.jsonrpc.notification.TimestampedDataNotification;
import io.openems.common.oem.OpenemsBackendOem;
import io.openems.common.timedata.DurationUnit;
import io.openems.common.timedata.Resolution;
import io.openems.common.types.ChannelAddress;
Expand All @@ -76,6 +76,9 @@ public class AggregatedInflux extends AbstractOpenemsBackendComponent implements
// map from edgeId to channelName and availableSince time stamp
private final Map<Integer, Map<String, Long>> availableSinceForEdge = new ConcurrentHashMap<>();

@Reference
private OpenemsBackendOem oem;

@Reference(//
cardinality = ReferenceCardinality.OPTIONAL, //
policyOption = ReferencePolicyOption.GREEDY //
Expand Down Expand Up @@ -107,8 +110,8 @@ private void activate(Config config) throws OpenemsNamedException, IllegalArgume
config.org(), WritePrecision.S, WriteConsistency.ALL);

this.influxConnector = new InfluxConnector(config.id(), config.queryLanguage(), URI.create(config.url()),
config.org(), config.apiKey(), config.bucket(), config.isReadOnly(), config.poolSize(),
config.maxQueueSize(), //
config.org(), config.apiKey(), config.bucket(), this.oem.getInfluxdbTag(), config.isReadOnly(),
config.poolSize(), config.maxQueueSize(), //
(throwable) -> {
this.logError(this.log, "Unable to write to InfluxDB. " + throwable.getClass().getSimpleName()
+ ": " + throwable.getMessage());
Expand Down Expand Up @@ -271,7 +274,7 @@ record AddValuesToPoint(String channel, JsonElement value) {

final var point = Point //
.measurement(this.config.measurementAvg()) //
.addTag(OpenemsOEM.INFLUXDB_TAG, String.valueOf(influxEdgeId)) //
.addTag(this.oem.getInfluxdbTag(), String.valueOf(influxEdgeId)) //
.time(timestampSeconds, WritePrecision.S);

channelPerType.getOrDefault(ChannelType.AVG, emptyList()).stream() //
Expand All @@ -287,7 +290,7 @@ record AddValuesToPoint(String channel, JsonElement value) {

final var maxPoint = Point //
.measurement(measurementEntry.getValue()) //
.addTag(OpenemsOEM.INFLUXDB_TAG, String.valueOf(influxEdgeId)) //
.addTag(this.oem.getInfluxdbTag(), String.valueOf(influxEdgeId)) //
.time(truncatedTimestamp, WritePrecision.S);

channelPerType.getOrDefault(ChannelType.MAX, emptyList()).stream() //
Expand Down Expand Up @@ -316,8 +319,8 @@ private Map<ZoneId, String> getDayChangeMeasurements(long timestamp) {
}

private void setAvailableSince(int influxEdgeId, String channelName, long availableSince) {
this.influxConnector
.write(InfluxConnector.buildUpdateAvailableSincePoint(influxEdgeId, channelName, availableSince));
this.influxConnector.write(InfluxConnector.buildUpdateAvailableSincePoint(this.oem.getInfluxdbTag(),
influxEdgeId, channelName, availableSince));
this.availableSinceForEdge.computeIfAbsent(influxEdgeId, key -> new ConcurrentHashMap<>()) //
.put(channelName, availableSince);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
import io.openems.backend.common.metadata.Edge;
import io.openems.backend.common.metadata.Metadata;
import io.openems.backend.common.timedata.Timedata;
import io.openems.common.OpenemsOEM;
import io.openems.common.event.EventReader;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.notification.AbstractDataNotification;
import io.openems.common.jsonrpc.notification.AggregatedDataNotification;
import io.openems.common.jsonrpc.notification.ResendDataNotification;
import io.openems.common.jsonrpc.notification.TimestampedDataNotification;
import io.openems.common.oem.OpenemsBackendOem;
import io.openems.common.timedata.Resolution;
import io.openems.common.types.ChannelAddress;
import io.openems.common.utils.StringUtils;
Expand All @@ -59,6 +59,9 @@ public class TimedataInfluxDb extends AbstractOpenemsBackendComponent implements
private final Logger log = LoggerFactory.getLogger(TimedataInfluxDb.class);
private final FieldTypeConflictHandler fieldTypeConflictHandler;

@Reference
private OpenemsBackendOem oem;

@Reference
protected volatile Metadata metadata;

Expand Down Expand Up @@ -88,8 +91,8 @@ private void activate(Config config) throws OpenemsException, IllegalArgumentExc
+ "]");

this.influxConnector = new InfluxConnector(config.id(), config.queryLanguage(), URI.create(config.url()),
config.org(), config.apiKey(), config.bucket(), config.isReadOnly(), config.poolSize(),
config.maxQueueSize(), //
config.org(), config.apiKey(), config.bucket(), this.oem.getInfluxdbTag(), config.isReadOnly(),
config.poolSize(), config.maxQueueSize(), //
(e) -> {
this.fieldTypeConflictHandler.handleException(e);
});
Expand Down Expand Up @@ -212,7 +215,7 @@ private void writeData(//
// this builds an InfluxDB record ("point") for a given timestamp
var point = Point //
.measurement(this.config.measurement()) //
.addTag(OpenemsOEM.INFLUXDB_TAG, String.valueOf(influxEdgeId)) //
.addTag(this.oem.getInfluxdbTag(), String.valueOf(influxEdgeId)) //
.time(timestamp, WritePrecision.MS);
for (var channelEntry : channelEntries) {
if (!shouldWriteValue.apply(influxEdgeId, channelEntry.getKey())) {
Expand Down
74 changes: 0 additions & 74 deletions io.openems.common/src/io/openems/common/OpenemsConstants.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package io.openems.common;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Optional;
import java.util.Scanner;

import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.openems.common.types.SemanticVersion;
import io.openems.common.utils.StringUtils;

public class OpenemsConstants {

Expand Down Expand Up @@ -72,73 +65,6 @@ public class OpenemsConstants {
*/
public static final String VERSION_DEV_BUILD_TIME = "";

/**
* The manufacturer of the device that is running OpenEMS.
*
* <p>
* Note: this should be max. 32 ASCII characters long
*/
public static final String MANUFACTURER = OpenemsOEM.MANUFACTURER;

/**
* The model identifier of the device.
*
* <p>
* Note: this should be max. 32 ASCII characters long
*/
public static final String MANUFACTURER_MODEL = "OpenEMS";

/**
* The options of the device.
*
* <p>
* Note: this should be max. 32 ASCII characters long
*/
public static final String MANUFACTURER_OPTIONS = "";

/**
* The version of the device.
*
* <p>
* Note: this should be max. 32 ASCII characters long
*/
public static final String MANUFACTURER_VERSION = "";

/**
* The serial number of the device.
*
* <p>
* Note: this should be max. 32 ASCII characters long
*/
public static final String MANUFACTURER_SERIAL_NUMBER = "";

/**
* The Energy-Management-System serial number of the device.
*
* <p>
* Note: this should be max. 32 ASCII characters long
*/
public static final String MANUFACTURER_EMS_SERIAL_NUMBER;

static {
Logger log = LoggerFactory.getLogger(OpenemsConstants.class);

String mesn = "";
try (Scanner s = new Scanner(Runtime.getRuntime().exec("hostname").getInputStream())) {
mesn = s.hasNext() ? s.next() : "";
} catch (IOException ioe) {
log.warn("Unable get hostname via OS-Command: " + ioe.getMessage());

try {
mesn = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException uhe) {
log.error("Unable get hostname via DNS-Lookup: " + uhe.getMessage());
}
}

MANUFACTURER_EMS_SERIAL_NUMBER = StringUtils.toShortString(mesn, 32);
}

/*
* Constants for Component properties
*/
Expand Down
Loading
Loading