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

FEMS Backports 2025-01-16 #2969

Merged
merged 15 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.osgi.service.metatype.annotations.ObjectClassDefinition;

import io.openems.backend.metadata.odoo.odoo.Protocol;
import io.openems.common.types.DebugMode;

@ObjectClassDefinition(//
name = "Metadata.Odoo", //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import io.openems.common.oem.OpenemsBackendOem;
import io.openems.common.session.Language;
import io.openems.common.session.Role;
import io.openems.common.types.DebugMode;
import io.openems.common.types.EdgeConfig;
import io.openems.common.types.EdgeConfigDiff;
import io.openems.common.types.SemanticVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public SystemUpdateParams getSystemUpdateParams() {
.put("App.TimeOfUseTariff.Tibber", "") //
.put("App.Api.ModbusTcp.ReadOnly", "") //
.put("App.Api.ModbusTcp.ReadWrite", "") //
.put("App.Api.ModbusRtu.ReadOnly", "") //
.put("App.Api.ModbusRtu.ReadWrite", "") //
.put("App.Api.RestJson.ReadOnly", "") //
.put("App.Api.RestJson.ReadWrite", "") //
.put("App.Timedata.InfluxDb", "")//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.openems.backend.metadata.odoo;
package io.openems.common.types;

public enum DebugMode {

Expand Down
232 changes: 77 additions & 155 deletions io.openems.common/src/io/openems/common/utils/JsonUtils.java

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions io.openems.common/src/io/openems/common/utils/StreamUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.openems.common.utils;

import java.util.Collections;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Stream;

public class StreamUtils {

/**
* Converts a Dictionary to a Stream of Map entries.
*
* @param dictionary the Dictionary to be converted
* @param <K> the type of keys in the Dictionary
* @param <V> the type of values in the Dictionary
* @return a Stream containing all the key-value pairs from the Dictionary as
* Map entries
*/
public static <K, V> Stream<Entry<K, V>> dictionaryToStream(Dictionary<K, V> dictionary) {
Enumeration<K> keys = dictionary.keys();
return Collections.list(keys).stream().map(key -> Map.entry(key, dictionary.get(key)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ public enum ChannelId implements io.openems.edge.common.channel.ChannelId {
DC_MAX_VOLTAGE(Doc.of(OpenemsType.INTEGER) //
.unit(Unit.VOLT) //
.persistencePriority(PersistencePriority.HIGH) //
), //

/**
* Inverter Cabinet Temperature.
*
* <ul>
* <li>Interface: SymmetricBatteryInverter
* <li>Type: Integer
* <li>Unit: C
* </ul>
*/
TEMPERATURE_CABINET(Doc.of(OpenemsType.INTEGER) //
.unit(Unit.DEGREE_CELSIUS) //
.persistencePriority(PersistencePriority.HIGH) //
);

private final Doc doc;
Expand Down Expand Up @@ -463,4 +477,23 @@ public default void _setDcMaxVoltage(Integer value) {
public default void _setDcMaxVoltage(int value) {
this.getDcMaxVoltageChannel().setNextValue(value);
}

/**
* Gets the Channel for {@link ChannelId#TEMPERATURE_CABINET}.
*
* @return the Channel
*/
public default IntegerReadChannel getTemperatureCabinetChannel() {
return this.channel(ChannelId.TEMPERATURE_CABINET);
}

/**
* Gets the Inverters Cabinet temperature in [C]. See
* {@link ChannelId#TEMPERATURE_CABINET}.
*
* @return the Channel {@link Value}
*/
public default Value<Integer> getTemperatureCabinet() {
return this.getTemperatureCabinetChannel().value();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.openems.common.types.DebugMode;
import io.openems.common.utils.FunctionUtils;
import io.openems.edge.bridge.http.api.BridgeHttp;
import io.openems.edge.bridge.http.api.BridgeHttpExecutor;
Expand Down Expand Up @@ -145,6 +146,8 @@ public void shutdown() {

private final Set<TimeEndpointCountdown> timeEndpoints = ConcurrentHashMap.newKeySet();

private DebugMode debugMode = DebugMode.OFF;

@Activate
public BridgeHttpImpl(//
@Reference final CycleSubscriber cycleSubscriber, //
Expand All @@ -170,6 +173,11 @@ public void deactivate() {
this.timeEndpoints.clear();
}

@Override
public void setDebugMode(DebugMode debugMode) {
this.debugMode = debugMode;
}

@Override
public CycleEndpoint subscribeCycle(CycleEndpoint endpoint) {
Objects.requireNonNull(endpoint, "CycleEndpoint is not allowed to be null!");
Expand Down Expand Up @@ -202,7 +210,7 @@ public CompletableFuture<HttpResponse<String>> request(Endpoint endpoint) {
final var future = new CompletableFuture<HttpResponse<String>>();
this.pool.execute(() -> {
try {
final var result = this.urlFetcher.fetchEndpoint(endpoint);
final var result = this.urlFetcher.fetchEndpoint(endpoint, this.debugMode);
future.complete(result);
} catch (HttpError e) {
future.completeExceptionally(e);
Expand Down Expand Up @@ -252,7 +260,8 @@ private void handleEvent(Event event) {
private Runnable createTask(CycleEndpointCountdown endpointItem) {
return () -> {
try {
final var result = this.urlFetcher.fetchEndpoint(endpointItem.getCycleEndpoint().endpoint().get());
final var result = this.urlFetcher.fetchEndpoint(endpointItem.getCycleEndpoint().endpoint().get(),
this.debugMode);
endpointItem.getCycleEndpoint().onResult().accept(result);
} catch (HttpError e) {
endpointItem.getCycleEndpoint().onError().accept(e);
Expand All @@ -275,7 +284,8 @@ private Runnable createTask(TimeEndpointCountdown endpointCountdown) {
HttpResponse<String> result = null;
HttpError error = null;
try {
result = this.urlFetcher.fetchEndpoint(endpointCountdown.getTimeEndpoint().endpoint().get());
result = this.urlFetcher.fetchEndpoint(endpointCountdown.getTimeEndpoint().endpoint().get(),
this.debugMode);
endpointCountdown.getTimeEndpoint().onResult().accept(result);
} catch (HttpError e) {
endpointCountdown.getTimeEndpoint().onError().accept(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@
import java.net.URI;

import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.openems.common.types.DebugMode;
import io.openems.common.types.HttpStatus;
import io.openems.edge.bridge.http.api.BridgeHttp.Endpoint;
import io.openems.edge.bridge.http.dummy.DummyEndpointFetcher;
import io.openems.edge.bridge.http.api.EndpointFetcher;
import io.openems.edge.bridge.http.api.HttpError;
import io.openems.edge.bridge.http.api.HttpResponse;

@Component
public class NetworkEndpointFetcher implements EndpointFetcher {

private final Logger log = LoggerFactory.getLogger(DummyEndpointFetcher.class);

@Override
public HttpResponse<String> fetchEndpoint(final Endpoint endpoint) throws HttpError {
public HttpResponse<String> fetchEndpoint(final Endpoint endpoint, DebugMode mode) throws HttpError {
try {
var url = URI.create(endpoint.url()).toURL();
var con = (HttpURLConnection) url.openConnection();
Expand Down Expand Up @@ -53,6 +59,12 @@ public HttpResponse<String> fetchEndpoint(final Endpoint endpoint) throws HttpEr
if (status.isError()) {
throw new HttpError.ResponseError(status, body);
}
if (mode.equals(DebugMode.DETAILED)) {
this.log.debug("Fetched Endpoint for request: " + endpoint.url() + "\n" //
+ "method: " + endpoint.method().name() + "\n" //
+ "result: " + body //
);
}
return new HttpResponse<>(status, body);
} catch (IOException e) {
throw new HttpError.UnknownError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.function.ThrowingFunction;
import io.openems.common.types.DebugMode;
import io.openems.common.utils.JsonUtils;

/**
Expand Down Expand Up @@ -73,6 +74,8 @@ public record Endpoint(//

}

public void setDebugMode(DebugMode debugMode);

/**
* Fetches the url once with {@link HttpMethod#GET}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.openems.edge.bridge.http.api;

import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.types.DebugMode;
import io.openems.edge.bridge.http.api.BridgeHttp.Endpoint;

public interface EndpointFetcher {
Expand All @@ -9,10 +10,11 @@ public interface EndpointFetcher {
* Creates a {@link Runnable} to execute a request with the given parameters.
*
* @param endpoint the {@link Endpoint} to fetch
* @param mode the {@link DebugMode}
*
* @return the result of the {@link Endpoint}
* @throws OpenemsNamedException on error
*/
public HttpResponse<String> fetchEndpoint(Endpoint endpoint) throws HttpError;
public HttpResponse<String> fetchEndpoint(Endpoint endpoint, DebugMode mode) throws HttpError;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;

import io.openems.common.types.DebugMode;
import io.openems.edge.bridge.http.api.BridgeHttp;
import io.openems.edge.bridge.http.api.HttpResponse;

Expand Down Expand Up @@ -55,4 +56,9 @@ public Collection<TimeEndpoint> removeTimeEndpointIf(Predicate<TimeEndpoint> con
return emptyList();
}

@Override
public void setDebugMode(DebugMode debugMode) {
// do nothing
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.slf4j.LoggerFactory;

import io.openems.common.function.ThrowingFunction;
import io.openems.common.types.DebugMode;
import io.openems.common.utils.FunctionUtils;
import io.openems.edge.bridge.http.api.BridgeHttp.Endpoint;
import io.openems.edge.bridge.http.api.EndpointFetcher;
Expand All @@ -29,7 +30,8 @@ public record DummyHandler(//

@Override
public HttpResponse<String> fetchEndpoint(//
final Endpoint endpoint //
final Endpoint endpoint, //
DebugMode mode //
) throws HttpError {
try {
for (final var iterator = this.urlHandler.iterator(); iterator.hasNext();) {
Expand Down Expand Up @@ -89,5 +91,4 @@ public void addSingleUseEndpointHandler(ThrowingFunction<Endpoint, HttpResponse<
public void setOnTaskFinished(Runnable onTaskFinished) {
this.onTaskFinished = onTaskFinished == null ? FunctionUtils::doNothing : onTaskFinished;
}

}
2 changes: 1 addition & 1 deletion io.openems.edge.bridge.onewire/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Export-Package: \
com.dalsemi.onewire.application.tag,\
com.dalsemi.onewire.container,\
com.dalsemi.onewire.debug,\
io.openems.edge.bridge.onewire,\
com.dalsemi.onewire.utils,\
io.openems.edge.bridge.onewire,\
gnu.io

Include-Resource: \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.Clock;
import java.util.List;
import java.util.Map;

import org.osgi.framework.BundleContext;

Expand Down Expand Up @@ -173,6 +174,20 @@ public default void _setDefaultConfigurationFailed(boolean value) {
@Override
public Clock getClock();

/**
* Gets the component properties by its component id.
*
* @param componentId the id of the component
* @return the properties or a empty map if none found
* @implNote this method is preferred to use when only the properties of an
* component are of interest. Because of OSGi delivering the component
* updates asynchronously and if a component update happens the config
* update may not reflect immediately to the config of the
* implementation of that component but this method uses the direct
* configuration in the service registration.
*/
public Map<String, Object> getComponentProperties(String componentId);

/**
* Gets all enabled OpenEMS-Components.
*
Expand Down
Loading
Loading