diff --git a/io.openems.edge.battery.pylontech/src/io/openems/edge/battery/pylontech/powercubem2/PylontechPowercubeM2BatteryImpl.java b/io.openems.edge.battery.pylontech/src/io/openems/edge/battery/pylontech/powercubem2/PylontechPowercubeM2BatteryImpl.java index 45216c93b21..a0bd0bac08e 100644 --- a/io.openems.edge.battery.pylontech/src/io/openems/edge/battery/pylontech/powercubem2/PylontechPowercubeM2BatteryImpl.java +++ b/io.openems.edge.battery.pylontech/src/io/openems/edge/battery/pylontech/powercubem2/PylontechPowercubeM2BatteryImpl.java @@ -74,7 +74,8 @@ public PylontechPowercubeM2BatteryImpl() { ModbusComponent.ChannelId.values(), // StartStoppable.ChannelId.values(), // Battery.ChannelId.values(), // - BatteryProtection.ChannelId.values(), PylontechPowercubeM2Battery.ChannelId.values() // + BatteryProtection.ChannelId.values(), + PylontechPowercubeM2Battery.ChannelId.values() // ); } @@ -741,75 +742,10 @@ private ChannelIdImpl generatePileChannel(int pile, String channelIdSuffix, Leve */ private int getOffsetForPile(int pileNumber) { - switch (pileNumber) { - case 1: - return 0x1400; - case 2: - return 0x1B00; - case 3: - return 0x2200; - case 4: - return 0x2900; - case 5: - return 0x3000; - case 6: - return 0x3700; - case 7: - return 0x3E00; - case 8: - return 0x4500; - case 9: - return 0x4C00; - case 10: - return 0x5300; - case 11: - return 0x5A00; - case 12: - return 0x6100; - case 13: - return 0x6800; - case 14: - return 0x6F00; - case 15: - return 0x7600; - case 16: - return 0x7D00; - case 17: - return 0x8400; - case 18: - return 0x8B00; - case 19: - return 0x9200; - case 20: - return 0x9900; - case 21: - return 0xA000; - case 22: - return 0xA700; - case 23: - return 0xAE00; - case 24: - return 0xB500; - case 25: - return 0xBC00; - case 26: - return 0xC300; - case 27: - return 0xCA00; - case 28: - return 0xD100; - case 29: - return 0xD800; - case 30: - return 0xDF00; - case 31: - return 0xE600; - case 32: - return 0xED00; + if (pileNumber < 1 || pileNumber > 32) { + return -1; } - ; - - return -1; + return 0x0D00 + pileNumber * 0x0700; } diff --git a/io.openems.edge.battery.pylontech/src/io/openems/edge/battery/pylontech/powercubem2/statemachine/StateMachine.java b/io.openems.edge.battery.pylontech/src/io/openems/edge/battery/pylontech/powercubem2/statemachine/StateMachine.java index 7a22c43f27a..8d4982604d0 100644 --- a/io.openems.edge.battery.pylontech/src/io/openems/edge/battery/pylontech/powercubem2/statemachine/StateMachine.java +++ b/io.openems.edge.battery.pylontech/src/io/openems/edge/battery/pylontech/powercubem2/statemachine/StateMachine.java @@ -50,21 +50,14 @@ public StateMachine(State initialState) { @Override public StateHandler getStateHandler(State state) { - switch (state) { - case UNDEFINED: - return new UndefinedHandler(); - case GO_RUNNING: - return new GoRunningHandler(); - case RUNNING: - return new RunningHandler(); - case GO_STOPPED: - return new GoStoppedHandler(); - case STOPPED: - return new StoppedHandler(); - case ERROR: - return new ErrorHandler(); - } - throw new IllegalArgumentException("Unknown State [" + state + "]"); - + + return switch (state) { + case UNDEFINED -> new UndefinedHandler(); + case GO_RUNNING -> new GoRunningHandler(); + case RUNNING -> new RunningHandler(); + case GO_STOPPED -> new GoStoppedHandler(); + case STOPPED -> new StoppedHandler(); + case ERROR -> new ErrorHandler(); + }; } } \ No newline at end of file