[easee] simplified determination of start/stop status due to recent API changes (#15538)
* simplified determination of start/stop as the opMode now has new values (7+8) to show missing authentication (before this was included in value "2") * refactored ChargerOpState to enum --------- Signed-off-by: Alexander Friese <af944580@googlemail.com> Signed-off-by: Alexander Friese <alexf2015@users.noreply.github.com> Co-authored-by: lsiepel <leosiepel@gmail.com>pull/15568/head
parent
c0d66da660
commit
f4fed3a800
|
@ -156,9 +156,6 @@ public class EaseeBindingConstants {
|
||||||
|
|
||||||
public static final String GENERIC_YES = "Yes";
|
public static final String GENERIC_YES = "Yes";
|
||||||
public static final String GENERIC_NO = "No";
|
public static final String GENERIC_NO = "No";
|
||||||
public static final int CHARGER_OP_STATE_WAITING = 2;
|
|
||||||
public static final int CHARGER_OP_STATE_CHARGING = 3;
|
|
||||||
public static final int CHARGER_OP_STATE_NOT_AUTHENTICATED = 7;
|
|
||||||
public static final double CHARGER_DYNAMIC_CURRENT_PAUSE = 0;
|
public static final double CHARGER_DYNAMIC_CURRENT_PAUSE = 0;
|
||||||
public static final int CHARGER_REASON_FOR_NO_CURRENT_CIRCUIT_LIMIT = 2;
|
public static final int CHARGER_REASON_FOR_NO_CURRENT_CIRCUIT_LIMIT = 2;
|
||||||
public static final int CHARGER_REASON_FOR_NO_CURRENT_CHARGER_LIMIT = 52;
|
public static final int CHARGER_REASON_FOR_NO_CURRENT_CHARGER_LIMIT = 52;
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2010-2023 Contributors to the openHAB project
|
||||||
|
*
|
||||||
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
|
* information.
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the Eclipse Public License 2.0 which is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-2.0
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
|
*/
|
||||||
|
package org.openhab.binding.easee.internal.model;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this enum represents the charger operation states as documented by https://developer.easee.cloud/docs/enumerations
|
||||||
|
*
|
||||||
|
* @author Alexander Friese - initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public enum ChargerOpState {
|
||||||
|
OFFLINE(0),
|
||||||
|
DISCONNECTED(1),
|
||||||
|
WAITING(2),
|
||||||
|
CHARGING(3),
|
||||||
|
COMPLETED(4),
|
||||||
|
ERROR(5),
|
||||||
|
READY_TO_CHARGE(6),
|
||||||
|
NOT_AUTHENTICATED(7),
|
||||||
|
DEAUTHENTICATING(8),
|
||||||
|
UNKNOWN_STATE(-1);
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ChargerOpState.class);
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
private ChargerOpState(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAuthenticatedState() {
|
||||||
|
switch (this) {
|
||||||
|
case WAITING:
|
||||||
|
case CHARGING:
|
||||||
|
case COMPLETED:
|
||||||
|
case READY_TO_CHARGE:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChargerOpState fromCode(String code) {
|
||||||
|
try {
|
||||||
|
return ChargerOpState.fromCode(Integer.parseInt(code));
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
LOGGER.warn("caught exception while parsing ChargerOpState code: '{}' - exception: {}", code,
|
||||||
|
ex.getMessage());
|
||||||
|
return UNKNOWN_STATE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChargerOpState fromCode(int code) {
|
||||||
|
for (ChargerOpState state : ChargerOpState.values()) {
|
||||||
|
if (state.code == code) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOGGER.info("unknown ChargerOpState code: '{}'", code);
|
||||||
|
return UNKNOWN_STATE;
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,7 +53,7 @@ class CustomResponseTransformer {
|
||||||
|
|
||||||
switch (triggerChannel.getUID().getId()) {
|
switch (triggerChannel.getUID().getId()) {
|
||||||
case CHANNEL_GROUP_CHARGER_STATE + "#" + CHANNEL_CHARGER_OP_MODE:
|
case CHANNEL_GROUP_CHARGER_STATE + "#" + CHANNEL_CHARGER_OP_MODE:
|
||||||
updateChargerStartStop(result, value, rawData);
|
updateChargerStartStop(result, value);
|
||||||
break;
|
break;
|
||||||
case CHANNEL_GROUP_CHARGER_STATE + "#" + CHANNEL_CHARGER_DYNAMIC_CURRENT:
|
case CHANNEL_GROUP_CHARGER_STATE + "#" + CHANNEL_CHARGER_DYNAMIC_CURRENT:
|
||||||
updateChargerPauseResume(result, value);
|
updateChargerPauseResume(result, value);
|
||||||
|
@ -78,28 +78,11 @@ class CustomResponseTransformer {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateChargerStartStop(Map<Channel, State> result, String value, JsonObject rawData) {
|
private void updateChargerStartStop(Map<Channel, State> result, String value) {
|
||||||
Channel channel = channelProvider.getChannel(CHANNEL_GROUP_CHARGER_COMMANDS, CHANNEL_CHARGER_START_STOP);
|
Channel channel = channelProvider.getChannel(CHANNEL_GROUP_CHARGER_COMMANDS, CHANNEL_CHARGER_START_STOP);
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
int val = Integer.parseInt(value);
|
ChargerOpState state = ChargerOpState.fromCode(value);
|
||||||
// state >= 3 && state < 7 will mean charging, ready to charge or charging finished
|
result.put(channel, OnOffType.from(state.isAuthenticatedState()));
|
||||||
boolean charging = val >= CHARGER_OP_STATE_CHARGING && val < CHARGER_OP_STATE_NOT_AUTHENTICATED;
|
|
||||||
|
|
||||||
String rfnc = Utils.getAsString(rawData, CHANNEL_CHARGER_REASON_FOR_NO_CURRENT);
|
|
||||||
int reasonForNoCurrent = Integer.valueOf(rfnc == null ? "-1" : rfnc);
|
|
||||||
boolean paused = false;
|
|
||||||
if (val == CHARGER_OP_STATE_WAITING) {
|
|
||||||
switch (reasonForNoCurrent) {
|
|
||||||
case CHARGER_REASON_FOR_NO_CURRENT_CHARGER_LIMIT:
|
|
||||||
case CHARGER_REASON_FOR_NO_CURRENT_CIRCUIT_LIMIT:
|
|
||||||
paused = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
paused = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.put(channel, OnOffType.from(charging || paused));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue