Skip to content

Commit

Permalink
FEMS Backport (#2359)
Browse files Browse the repository at this point in the history
* CI: fix tools/common.sh for updating UI version

* CI: fix Debian build script

Replace all unwanted characters in branch name with "." to be compliant with Debian version requirements

* WebsocketClient: decreased connection lost timeout

Decreased connection lost timeout to make sure the detection happens within 5 minutes

every 100sec ping
waiting for response time 1.5 * 100sec = 150sec
total time 250sec

* Debian: fix debian/semver compatible version string

* UI: remove unused channels History Production modal

Before this bugfix UI would query a channel that was not existing for pure AC systems, and Backend would fall-back to 'old' InfluxDB instead of Aggregated.

* KMtronic: set persistence priority for relay channels to high

- Increased persistence priority to enable resending and saving data locally
- Also set debug channel to medium

* Backend/UI: Add filters to edges overview

* UI
  * Add OpenEMSSumStateLevel (as sumState) to getEdgesRequest
  * Show sumState in edges Overview
  * Add filter for producttype and sumState to edges overview
  * Add firstSetupProtocolDate to profile

* Backend
  * Add Sumstate to edgeMetadata
  * Add searchParams to getEdgesRequest
    * isOnline -> if edge is online
    * sumState -> the sumState of the edge
    * productType -> the producttype of the edge

* Fix OptionsEnums with non-unique values

Original: change value of Undefined state in GoodWeHardwareType. Caused problems in fems14974 as the Battery values are set to 0 in Undefined state

* Cleanup

---------

Co-authored-by: Michael Grill <[email protected]>
Co-authored-by: Lukas Rieger <[email protected]>
Co-authored-by: Sagar Venu <[email protected]>
Co-authored-by: Jan Seidemann <[email protected]>
Co-authored-by: Anas Shetla <[email protected]>
Co-authored-by: Sebastian Asen <[email protected]>
Co-authored-by: Stefan Feilmeier <[email protected]>
  • Loading branch information
8 people authored Sep 16, 2023
1 parent 7a92b64 commit dc9c67e
Show file tree
Hide file tree
Showing 55 changed files with 920 additions and 978 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public TestOfflineEdgeHandler() {
));
}

private Edge getTestEdge(Metadata metadata, String id, ZonedDateTime LastMessage, boolean isOnline) {
final var edge = new Edge(metadata, id, "comment", "version", "producttype", LastMessage);
private Edge getTestEdge(Metadata metadata, String id, ZonedDateTime lastMessage, boolean isOnline) {
final var edge = new Edge(metadata, id, "comment", "version", "producttype", lastMessage);
edge.setOnline(isOnline);
return edge;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Edge {
private String comment;
private SemanticVersion version;
private String producttype;
private ZonedDateTime lastmessage = null;
private ZonedDateTime lastmessage;
private boolean isOnline = false;

private final List<EdgeUser> user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.request.GetEdgesRequest.PaginationOptions;
import io.openems.common.jsonrpc.response.GetEdgesResponse.EdgeMetadata;
import io.openems.common.session.Language;
import io.openems.common.session.Role;
import io.openems.common.types.ChannelAddress;
import io.openems.common.types.EdgeConfig;
import io.openems.common.types.EdgeConfig.Component.Channel;
Expand Down Expand Up @@ -352,7 +352,8 @@ public static final class Events {
* @return the role to the Edge-IDs
* @throws OpenemsNamedException on error
*/
public Map<String, Role> getPageDevice(User user, PaginationOptions paginationOptions) throws OpenemsNamedException;
public List<EdgeMetadata> getPageDevice(User user, PaginationOptions paginationOptions)
throws OpenemsNamedException;

/**
* Gets the Role for a edge of the current user.
Expand All @@ -362,6 +363,6 @@ public static final class Events {
* @return the role to the edge
* @throws OpenemsNamedException on error
*/
public Role getRoleForEdge(User user, String edgeId) throws OpenemsNamedException;
public EdgeMetadata getEdgeMetadataForUser(User user, String edgeId) throws OpenemsNamedException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.NavigableMap;
import java.util.TreeMap;

import io.openems.common.channel.Level;
import io.openems.common.exceptions.OpenemsError;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.jsonrpc.response.GetEdgesResponse.EdgeMetadata;
Expand Down Expand Up @@ -92,7 +93,9 @@ public static List<EdgeMetadata> generateEdgeMetadatas(User user, Metadata metad
edge.getVersion(), // Version
role, // Role
edge.isOnline(), // Online-State
edge.getLastmessage() // Last-Message Timestamp
edge.getLastmessage(), // Last-Message Timestamp
null, //
Level.OK //
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.request.GetEdgesRequest.PaginationOptions;
import io.openems.common.jsonrpc.response.GetEdgesResponse.EdgeMetadata;
import io.openems.common.session.Language;
import io.openems.common.session.Role;

public class DummyMetadata implements Metadata {
@Override
Expand Down Expand Up @@ -138,13 +138,13 @@ public Optional<String> getSerialNumberForEdge(Edge edge) {
}

@Override
public Map<String, Role> getPageDevice(User user, PaginationOptions paginationOptions)
public List<EdgeMetadata> getPageDevice(User user, PaginationOptions paginationOptions)
throws OpenemsNamedException {
throw new UnsupportedOperationException("Unsupported by Dummy Class");
}

@Override
public Role getRoleForEdge(User user, String edgeId) throws OpenemsNamedException {
public EdgeMetadata getEdgeMetadataForUser(User user, String edgeId) throws OpenemsNamedException {
throw new UnsupportedOperationException("Unsupported by Dummy Class");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
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;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.request.GetEdgesRequest.PaginationOptions;
import io.openems.common.jsonrpc.response.GetEdgesResponse.EdgeMetadata;
import io.openems.common.session.Language;
import io.openems.common.session.Role;
import io.openems.common.utils.StringUtils;
Expand Down Expand Up @@ -284,7 +286,7 @@ public void setUserAlertingSettings(User user, String edgeId, List<AlertingSetti
}

@Override
public Map<String, Role> getPageDevice(User user, PaginationOptions paginationOptions)
public List<EdgeMetadata> getPageDevice(User user, PaginationOptions paginationOptions)
throws OpenemsNamedException {
var pagesStream = this.edges.values().stream();
final var query = paginationOptions.getQuery();
Expand All @@ -295,18 +297,55 @@ public Map<String, Role> getPageDevice(User user, PaginationOptions paginationOp
|| StringUtils.containsWithNullCheck(edge.getProducttype(), query) //
);
}
final var searchParams = paginationOptions.getSearchParams();
if (searchParams != null) {
if (searchParams.searchIsOnline()) {
pagesStream = pagesStream.filter(edge -> edge.isOnline() == searchParams.isOnline());
}
if (searchParams.productTypes() != null) {
pagesStream = pagesStream.filter(edge -> searchParams.productTypes().contains(edge.getProducttype()));
}
// TODO sum state filter
}

return pagesStream //
.sorted((s1, s2) -> s1.getId().compareTo(s2.getId())) //
.skip(paginationOptions.getPage() * paginationOptions.getLimit()) //
.limit(paginationOptions.getLimit()) //
.peek(t -> user.setRole(t.getId(), Role.ADMIN)) //
.collect(Collectors.toMap(t -> t.getId(), t -> Role.ADMIN)); //
.map(myEdge -> {
return new EdgeMetadata(//
myEdge.getId(), //
myEdge.getComment(), //
myEdge.getProducttype(), //
myEdge.getVersion(), //
Role.ADMIN, //
myEdge.isOnline(), //
myEdge.getLastmessage(), //
null, //
Level.OK);
}).toList();
}

@Override
public Role getRoleForEdge(User user, String edgeId) throws OpenemsNamedException {
public EdgeMetadata getEdgeMetadataForUser(User user, String edgeId) throws OpenemsNamedException {
final var edge = this.edges.get(edgeId);
if (edge == null) {
return null;
}
user.setRole(edgeId, Role.ADMIN);
return Role.ADMIN;

return new EdgeMetadata(//
edge.getId(), //
edge.getComment(), //
edge.getProducttype(), //
edge.getVersion(), //
Role.ADMIN, //
edge.isOnline(), //
edge.getLastmessage(), //
null, //
Level.OK //
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public String getApikey() {
public String getSetupPassword() {
return this.setupPassword;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
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;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.request.GetEdgesRequest.PaginationOptions;
import io.openems.common.jsonrpc.response.GetEdgesResponse.EdgeMetadata;
import io.openems.common.session.Language;
import io.openems.common.session.Role;
import io.openems.common.utils.JsonUtils;
Expand Down Expand Up @@ -316,7 +318,7 @@ public void setUserAlertingSettings(User user, String edgeId, List<AlertingSetti
}

@Override
public Map<String, Role> getPageDevice(User user, PaginationOptions paginationOptions)
public List<EdgeMetadata> getPageDevice(User user, PaginationOptions paginationOptions)
throws OpenemsNamedException {
var pagesStream = this.edges.values().stream();
final var query = paginationOptions.getQuery();
Expand All @@ -327,18 +329,54 @@ public Map<String, Role> getPageDevice(User user, PaginationOptions paginationOp
|| StringUtils.containsWithNullCheck(edge.getProducttype(), query) //
);
}
final var searchParams = paginationOptions.getSearchParams();
if (searchParams != null) {
if (searchParams.searchIsOnline()) {
pagesStream = pagesStream.filter(edge -> edge.isOnline() == searchParams.isOnline());
}
if (searchParams.productTypes() != null) {
pagesStream = pagesStream.filter(edge -> searchParams.productTypes().contains(edge.getProducttype()));
}
// TODO sum state filter
}
return pagesStream //
.sorted((s1, s2) -> s1.getId().compareTo(s2.getId())) //
.skip(paginationOptions.getPage() * paginationOptions.getLimit()) //
.limit(paginationOptions.getLimit()) //
.peek(t -> user.setRole(t.getId(), Role.ADMIN)) //
.collect(Collectors.toMap(t -> t.getId(), t -> Role.ADMIN)); //
.map(myEdge -> {
return new EdgeMetadata(//
myEdge.getId(), //
myEdge.getComment(), //
myEdge.getProducttype(), //
myEdge.getVersion(), //
Role.ADMIN, //
myEdge.isOnline(), //
myEdge.getLastmessage(), //
null, //
Level.OK);
}).toList();
}

@Override
public Role getRoleForEdge(User user, String edgeId) throws OpenemsNamedException {
public EdgeMetadata getEdgeMetadataForUser(User user, String edgeId) throws OpenemsNamedException {
final var edge = this.edges.get(edgeId);
if (edge == null) {
return null;
}
user.setRole(edgeId, Role.ADMIN);
return Role.ADMIN;

return new EdgeMetadata(//
edge.getId(), //
edge.getComment(), //
edge.getProducttype(), //
edge.getVersion(), //
Role.ADMIN, //
edge.isOnline(), //
edge.getLastmessage(), //
null, //
Level.OK //
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public enum EdgeDevice implements Field {
LASTMESSAGE("lastmessage", true), //
OPENEMS_SUM_STATE("openems_sum_state_level", false), //
OPENEMS_IS_CONNECTED("openems_is_connected", false), //
STOCK_PRODUCTION_LOT_ID("stock_production_lot_id", false);
STOCK_PRODUCTION_LOT_ID("stock_production_lot_id", false),
FIRST_SETUP_PROTOCOL("first_setup_protocol_date", false);

public static final String ODOO_MODEL = "openems.device";
public static final String ODOO_TABLE = ODOO_MODEL.replace(".", "_");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.sql.SQLException;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
Expand Down Expand Up @@ -45,14 +45,15 @@
import io.openems.backend.metadata.odoo.odoo.FieldValue;
import io.openems.backend.metadata.odoo.odoo.OdooHandler;
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;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.request.GetEdgesRequest.PaginationOptions;
import io.openems.common.jsonrpc.response.GetEdgesResponse.EdgeMetadata;
import io.openems.common.session.Language;
import io.openems.common.session.Role;
import io.openems.common.types.EdgeConfig;
Expand Down Expand Up @@ -499,33 +500,62 @@ public void setUserAlertingSettings(User user, String edgeId, List<AlertingSetti
}

@Override
public Map<String, Role> getPageDevice(User user, PaginationOptions paginationOptions)
throws OpenemsNamedException {
public List<EdgeMetadata> getPageDevice(//
final User user, //
final PaginationOptions paginationOptions //
) throws OpenemsNamedException {
var result = this.odooHandler.getEdges((MyUser) user, paginationOptions);

Map<String, Role> devices = new LinkedHashMap<>();

var jDevices = JsonUtils.getAsJsonArray(result, "devices");
for (var jDevice : jDevices) {
var edgeId = JsonUtils.getAsString(jDevice, "name");
var role = Role.getRole(JsonUtils.getAsString(jDevice, "role"));
user.setRole(edgeId, role);

devices.put(edgeId, role);
final var jsonArray = JsonUtils.getAsJsonArray(result, "devices");
final var resultMetadata = new ArrayList<EdgeMetadata>(jsonArray.size());
for (var jElement : jsonArray) {
resultMetadata.add(this.convertToEdgeMetadata(user, jElement));
}

return devices;
return resultMetadata;
}

@Override
public Role getRoleForEdge(User user, String edgeId) throws OpenemsNamedException {
var result = this.odooHandler.getEdgeWithRole((MyUser) user, edgeId);
var roleString = JsonUtils.getAsOptionalString(result, "role") //
.orElseThrow(() -> OpenemsError.COMMON_ROLE_UNDEFINED.exception(edgeId, user.getId()));
public EdgeMetadata getEdgeMetadataForUser(User user, String edgeId) throws OpenemsNamedException {
return this.convertToEdgeMetadata(user, this.odooHandler.getEdgeWithRole(user, edgeId));
}

private EdgeMetadata convertToEdgeMetadata(User user, JsonElement jDevice) throws OpenemsNamedException {
final var edgeId = JsonUtils.getAsString(jDevice, "name");

var role = Role.getRole(roleString);
// TODO remove cached edge
final var cachedEdge = this.getEdge(edgeId).orElse(null);
if (cachedEdge == null) {
throw new OpenemsException("Unable to find edge with id [" + edgeId + "]");
}

final var role = Role.getRole(JsonUtils.getAsString(jDevice, "role"));
user.setRole(edgeId, role);
return role;

final var sumState = JsonUtils.getAsOptionalString(jDevice, "openems_sum_state_level") //
.map(String::toUpperCase) //
.map(Level::valueOf) //
.orElse(Level.OK);
final var commment = JsonUtils.getAsOptionalString(jDevice, "comment").orElse("");
final var producttype = JsonUtils.getAsOptionalString(jDevice, "producttype").orElse("");
final var firstSetupProtocol = JsonUtils.getAsOptionalString(jDevice, "first_setup_protocol_date")
.map(DateTime::stringToDateTime) //
.orElse(null);
final var lastmessage = JsonUtils.getAsOptionalString(jDevice, "lastmessage") //
.map(DateTime::stringToDateTime) //
.orElse(null);

return new EdgeMetadata(//
edgeId, //
commment, //
producttype, //
cachedEdge.getVersion(), //
role, //
// TODO isOnline should also come from odoo and in the ui there should be a
// subscribe to maybe "edgeState" if any of these properties change
cachedEdge.isOnline(), //
lastmessage, //
firstSetupProtocol, //
sumState //
);
}

}
Loading

0 comments on commit dc9c67e

Please sign in to comment.