-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement new Shelly Plus Plug S (#2529)
- Loading branch information
Showing
15 changed files
with
754 additions
and
36 deletions.
There are no files selected for viewing
37 changes: 31 additions & 6 deletions
37
io.openems.edge.bridge.http/src/io/openems/edge/bridge/http/dummy/DummyBridgeHttp.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 |
---|---|---|
@@ -1,27 +1,52 @@ | ||
package io.openems.edge.bridge.http.dummy; | ||
|
||
import static java.util.concurrent.CompletableFuture.completedFuture; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import io.openems.edge.bridge.http.api.BridgeHttp; | ||
|
||
public class DummyBridgeHttp implements BridgeHttp { | ||
|
||
public final List<CycleEndpoint> cycleEndpoints = new ArrayList<>(); | ||
public final List<TimeEndpoint> timeEndpoints = new ArrayList<>(); | ||
|
||
private String nextRequestResult = null; | ||
|
||
@Override | ||
public void subscribeCycle(CycleEndpoint endpoint) { | ||
// TODO Auto-generated method stub | ||
|
||
this.cycleEndpoints.add(endpoint); | ||
} | ||
|
||
@Override | ||
public void subscribeTime(TimeEndpoint endpoint) { | ||
// TODO Auto-generated method stub | ||
|
||
this.timeEndpoints.add(endpoint); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<String> request(Endpoint endpoint) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
return completedFuture(this.nextRequestResult); | ||
} | ||
|
||
/** | ||
* Mocks a result for all {@link CycleEndpoint}s. | ||
* | ||
* @param result the mocked read result | ||
*/ | ||
public void mockCycleResult(String result) { | ||
this.cycleEndpoints.forEach(// | ||
e -> e.result().accept(result)); | ||
} | ||
|
||
/** | ||
* Mocks a result for simple request {@link Endpoint}. | ||
* | ||
* @param nextRequestResult the mocked read result | ||
*/ | ||
public void mockRequestResult(String nextRequestResult) { | ||
this.nextRequestResult = nextRequestResult; | ||
} | ||
|
||
} |
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
29 changes: 29 additions & 0 deletions
29
io.openems.edge.io.shelly/src/io/openems/edge/io/shelly/common/Utils.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,29 @@ | ||
package io.openems.edge.io.shelly.common; | ||
|
||
import io.openems.edge.common.channel.Channel; | ||
import io.openems.edge.common.component.OpenemsComponent; | ||
|
||
public class Utils { | ||
|
||
private Utils() { | ||
} | ||
|
||
/** | ||
* Generates a standard Debug-Log string for Shellys with one relay and power | ||
* meter. | ||
* | ||
* @param relayChannel the Relay-Channel | ||
* @param activePowerChannel the ActivePower-Channel | ||
* @return suitable for {@link OpenemsComponent#debugLog()} | ||
*/ | ||
public static String generateDebugLog(Channel<Boolean> relayChannel, Channel<Integer> activePowerChannel) { | ||
var b = new StringBuilder(); | ||
relayChannel.value().asOptional().ifPresentOrElse(// | ||
v -> b.append(v ? "On" : "Off"), // | ||
() -> b.append("Unknown")); | ||
b.append("|"); | ||
b.append(activePowerChannel.value().asString()); | ||
return b.toString(); | ||
} | ||
|
||
} |
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
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
33 changes: 33 additions & 0 deletions
33
io.openems.edge.io.shelly/src/io/openems/edge/io/shelly/shellyplusplugs/Config.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,33 @@ | ||
package io.openems.edge.io.shelly.shellyplusplugs; | ||
|
||
import org.osgi.service.metatype.annotations.AttributeDefinition; | ||
import org.osgi.service.metatype.annotations.ObjectClassDefinition; | ||
|
||
import io.openems.edge.meter.api.MeterType; | ||
import io.openems.edge.meter.api.SinglePhase; | ||
|
||
@ObjectClassDefinition(// | ||
name = "IO Shelly Plus Plug S", // | ||
description = "Implements the Shelly Plus Plug S") | ||
@interface Config { | ||
|
||
@AttributeDefinition(name = "Component-ID", description = "Unique ID of this Component") | ||
String id() default "io0"; | ||
|
||
@AttributeDefinition(name = "Alias", description = "Human-readable name of this Component; defaults to Component-ID") | ||
String alias() default ""; | ||
|
||
@AttributeDefinition(name = "Is enabled?", description = "Is this Component enabled?") | ||
boolean enabled() default true; | ||
|
||
@AttributeDefinition(name = "Phase", description = "Which Phase is this Shelly Plug connected to?") | ||
SinglePhase phase() default SinglePhase.L1; | ||
|
||
@AttributeDefinition(name = "IP-Address", description = "The IP address of the Shelly device.") | ||
String ip(); | ||
|
||
@AttributeDefinition(name = "Meter-Type", description = "What is measured by this Meter?") | ||
MeterType type() default MeterType.CONSUMPTION_METERED; | ||
|
||
String webconsole_configurationFactory_nameHint() default "IO Shelly Plus Plug S [{id}]"; | ||
} |
Oops, something went wrong.