Skip to content

Commit

Permalink
[kermi] improved code for MR
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Neuhaus <[email protected]>
  • Loading branch information
KaaNee committed May 7, 2024
1 parent 2f560c5 commit 1a3eb28
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class KermiBindingConstants {
public static final ThingTypeUID THING_TYPE_KERMI_XCENTER = new ThingTypeUID(BINDING_ID, "kermi-xcenter");

// Channels for State
public static final String GLOBAL_STATE_CHANNEL = "global-state";
// public static final String GLOBAL_STATE_CHANNEL = "global-state";
public static final String GLOBAL_STATE_ID_CHANNEL = "global-state-id";

// Alarm State
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.openhab.binding.modbus.kermi.internal.modbus.Data;
import org.openhab.core.io.transport.modbus.ModbusBitUtilities;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.StringType;

/**
* The {@link StateDTO} Data object for Kermi Xcenter
Expand All @@ -24,35 +23,10 @@
*/
public class StateDTO implements Data {

public StringType globalState;
public DecimalType globalStateId;

// State definitions
public static final StringType STATE_STANDBY = StringType.valueOf("Standby");
public static final StringType STATE_ALARM = StringType.valueOf("Alarm");
public static final StringType STATE_TWE = StringType.valueOf("TWE");
public static final StringType STATE_KUEHLEN = StringType.valueOf("Kuehlen");
public static final StringType STATE_HEIZEN = StringType.valueOf("Heizen");
public static final StringType STATE_ABTAUUNG = StringType.valueOf("Abtauung");
public static final StringType STATE_VORBEREITUNG = StringType.valueOf("Vorbereitung");
public static final StringType STATE_BLOCKIERT = StringType.valueOf("Blockiert");
public static final StringType STATE_EVU_SPERRE = StringType.valueOf("EVU Sperre");
public static final StringType STATE_NICHT_VERFUEGBAR = StringType.valueOf("Nicht verfuegbar");
public static final StringType STATE_UNKOWN = StringType.valueOf("Status unknown");
public static final StringType[] STATE_ARRAY = new StringType[] { STATE_STANDBY, STATE_ALARM, STATE_TWE,
STATE_KUEHLEN, STATE_HEIZEN, STATE_ABTAUUNG, STATE_VORBEREITUNG, STATE_BLOCKIERT, STATE_EVU_SPERRE,
STATE_NICHT_VERFUEGBAR };

public StateDTO(byte[] bArray) {

int status = ModbusBitUtilities.extractBit(bArray, 0);

globalStateId = new DecimalType(status);

if (status >= 0 && status < 10) {
globalState = STATE_ARRAY[status];
} else {
globalState = STATE_UNKOWN;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.openhab.binding.modbus.kermi.internal.KermiBindingConstants.EXIT_TEMPERATURE_CHANNEL;
import static org.openhab.binding.modbus.kermi.internal.KermiBindingConstants.FLOW_SPEED_CHANNEL;
import static org.openhab.binding.modbus.kermi.internal.KermiBindingConstants.FLOW_TEMPERATURE_CHANNEL;
import static org.openhab.binding.modbus.kermi.internal.KermiBindingConstants.GLOBAL_STATE_CHANNEL;
import static org.openhab.binding.modbus.kermi.internal.KermiBindingConstants.GLOBAL_STATE_ID_CHANNEL;
import static org.openhab.binding.modbus.kermi.internal.KermiBindingConstants.INCOMING_TEMPERATURE_CHANNEL;
import static org.openhab.binding.modbus.kermi.internal.KermiBindingConstants.POWER_CHANNEL;
Expand Down Expand Up @@ -146,7 +145,7 @@ public enum ReadStatus {
private ChannelUID electricPowerCoolingChannel;

// Global State
private ChannelUID globalStateChannel;
// private ChannelUID globalStateChannel;
private ChannelUID globalStateIdChannel;

// Alarm State
Expand All @@ -163,7 +162,6 @@ public enum ReadStatus {
private ChannelUID pvTargetTemperatureHeatingChannel; // READ-WRITE
private ChannelUID pvTargetTemperatureDrinkingWaterChannel; // READ-WRITE

// private final ArrayList<E3DCWallboxThingHandler> listeners = new ArrayList<>();
private final Logger logger = LoggerFactory.getLogger(KermiXcenterThingHandler.class);

private final Parser alarmParser = new Parser(Data.DataType.ALARM_STATE);
Expand Down Expand Up @@ -204,7 +202,7 @@ public KermiXcenterThingHandler(Bridge thing) {
super(thing);

// STATE
globalStateChannel = channelUID(thing, STATE_GROUP, GLOBAL_STATE_CHANNEL);
// globalStateChannel = channelUID(thing, STATE_GROUP, GLOBAL_STATE_CHANNEL);
globalStateIdChannel = channelUID(thing, STATE_GROUP, GLOBAL_STATE_ID_CHANNEL);

alarmStateChannel = channelUID(thing, ALARM_GROUP, ALARM_STATE_CHANNEL);
Expand Down Expand Up @@ -592,7 +590,7 @@ void handleStateResult(AsyncModbusReadResult result) {
Optional<Data> dtoOpt = stateParser.parse(Data.DataType.STATE);
if (dtoOpt.isPresent()) {
StateDTO dto = (StateDTO) dtoOpt.get();
updateState(globalStateChannel, dto.globalState);
// updateState(globalStateChannel, dto.globalState);
updateState(globalStateIdChannel, dto.globalStateId);
} else {
logger.debug("Unable to get {} from provider {}", Data.DataType.STATE, stateParser.toString());
Expand All @@ -608,7 +606,7 @@ void handleStateFailure(AsyncModbusFailure<ModbusReadRequestBlueprint> result) {
}
}

private void handleWorkHoursResult(AsyncModbusReadResult result) {
void handleWorkHoursResult(AsyncModbusReadResult result) {
workHoursParser.handle(result);
Optional<Data> dtoOpt = workHoursParser.parse(Data.DataType.WORK_HOURS);
if (dtoOpt.isPresent()) {
Expand Down
Loading

0 comments on commit 1a3eb28

Please sign in to comment.