Skip to content

Commit

Permalink
[easee] Migrate charger state API endpoint, add channels (#14614)
Browse files Browse the repository at this point in the history
* reworked the way to retrieve Charger state as API endpoint is now deprecated.
* fixed result processing: removed default handling by bridge handler which caused everything to go offline if a single charger had faulty config.
* additional channels / removed obsolete firmware channel

Signed-off-by: Alexander Friese <af944580@googlemail.com>
  • Loading branch information
alexf2015 authored Aug 18, 2023
1 parent 79ecb2e commit a435ed2
Show file tree
Hide file tree
Showing 30 changed files with 670 additions and 196 deletions.
27 changes: 23 additions & 4 deletions bundles/org.openhab.binding.easee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,42 @@ The settings that start with "dynamic" can be changed frequently, the others are
| state#chargerOpMode | Number | no | 0=Offline, 1=Disconnected, 2=AwaitingStart, 3=Charging, 4=Completed, 5=Error, 6=ReadyToCharge, 7=AwaitingAuthentication, 8=Deauthenticating | |
| state#totalPower | Number:Power | no | current session total power (all phases) | |
| state#sessionEnergy | Number:Energy | no | current session | |
| state#energyPerHour | Number:Energy | no | energy per hour | |
| state#wiFiRSSI | Number:Power | no | | |
| state#cellRSSI | Number:Power | no | | |
| state#dynamicCircuitCurrentP1 | Number:ElectricCurrent | no | | |
| state#dynamicCircuitCurrentP2 | Number:ElectricCurrent | no | | |
| state#dynamicCircuitCurrentP3 | Number:ElectricCurrent | no | | |
| state#latestPulse | DateTime | no | | |
| state#chargerFirmware | Number | no | | |
| state#latestFirmware | Number | no | | |
| state#voltage | Number:ElectricPotential | no | | |
| state#inCurrentT2 | Number:ElectricCurrent | no | | |
| state#inCurrentT3 | Number:ElectricCurrent | no | | |
| state#inCurrentT4 | Number:ElectricCurrent | no | | |
| state#inCurrentT5 | Number:ElectricCurrent | no | | |
| state#outputCurrent | Number:ElectricCurrent | no | | |
| state#inVoltageT1T2 | Number:ElectricPotential | no | | |
| state#inVoltageT1T3 | Number:ElectricPotential | no | | |
| state#inVoltageT1T4 | Number:ElectricPotential | no | | |
| state#inVoltageT1T5 | Number:ElectricPotential | no | | |
| state#inVoltageT2T3 | Number:ElectricPotential | no | | |
| state#inVoltageT2T4 | Number:ElectricPotential | no | | |
| state#inVoltageT2T5 | Number:ElectricPotential | no | | |
| state#inVoltageT3T4 | Number:ElectricPotential | no | | |
| state#inVoltageT3T5 | Number:ElectricPotential | no | | |
| state#inVoltageT4T5 | Number:ElectricPotential | no | | |
| state#ledMode | Number | no | | |
| state#cableRating | Number:ElectricCurrent | no | | |
| state#isOnline | Switch | no | | |
| state#dynamicChargerCurrent | Number:ElectricCurrent | yes | | 0, 6-32 |
| state#reasonForNoCurrent | Number | no | 0=OK, 2=DynamicCircuitCurrentLimitTooLow, 27=DynamicCircuitCurrentCharging, 52=DynamicChargerCurrentLimitTooLow, 55=NotAuthorized, 79=CarLimit, 81=CarLimitedCharging | |
| state#lifetimeEnergy | Number:Energy | no | | |
| state#errorCode | Number | no | | |
| state#fatalErrorCode | Number | no | | |
| config#lockCablePermanently | Switch | yes | | ON/OFF |
| config#authorizationRequired | Switch | yes | | ON/OFF |
| config#limitToSinglePhaseCharging | Switch | yes | | ON/OFF |
| state#connectedToCloud | Switch | no | | |
| config#lockCablePermanently | Switch | yes | | true/false |
| config#authorizationRequired | Switch | yes | | true/false |
| config#limitToSinglePhaseCharging | Switch | yes | | true/false |
| config#phaseMode | Number | yes | 1=1phase, 2=auto, 3=3phase | 1-3 |
| config#maxChargerCurrent | Number:ElectricCurrent | no | write access not yet implemented | |
| commands#genericCommand | String | yes | Generic Endpoint to send commands | reboot, update_firmware, poll_all, smart_charging, start_charging, stop_charging, pause_charging, resume_charging, toggle_charging, override_schedule |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ public class EaseeBindingConstants {
public static final String CHANNEL_TYPE_VOLT = "Number:ElectricPotential";
public static final String CHANNEL_TYPE_AMPERE = "Number:ElectricCurrent";
public static final String CHANNEL_TYPE_KWH = "Number:Energy";
public static final String CHANNEL_TYPE_KW = "Number:Power";
public static final String CHANNEL_TYPE_POWER = "Number:Power";
public static final String CHANNEL_TYPE_DATE = "DateTime";
public static final String CHANNEL_TYPE_STRING = "String";
public static final String CHANNEL_TYPE_NUMBER = "Number";

public static final String CHANNEL_TYPEPREFIX_RW = "rw";

public static final String CHANNEL_TYPENAME_INTEGER = "type-integer";
public static final String CHANNEL_TYPENAME_RSSI = "type-rssi";

// Channels with specific handling
public static final String CHANNEL_CHARGER_OP_MODE = "chargerOpMode";
Expand All @@ -88,6 +89,7 @@ public class EaseeBindingConstants {
public static final String JSON_KEY_GENERIC_NAME = "name";
public static final String JSON_KEY_CIRCUIT_NAME = "panelName";
public static final String JSON_KEY_CIRCUIT_ID = "circuitId";
public static final String JSON_KEY_CHARGER_ID = "chargerID";
public static final String JSON_KEY_CIRCUITS = "circuits";
public static final String JSON_KEY_CHARGERS = "chargers";
public static final String JSON_KEY_BACK_PLATE = "backPlate";
Expand All @@ -99,6 +101,9 @@ public class EaseeBindingConstants {
public static final String JSON_KEY_AUTH_ACCESS_TOKEN = "accessToken";
public static final String JSON_KEY_AUTH_REFRESH_TOKEN = "refreshToken";
public static final String JSON_KEY_AUTH_EXPIRES_IN = "expiresIn";
public static final String JSON_KEY_CIRCUIT_STATES = "circuitStates";
public static final String JSON_KEY_CHARGER_STATES = "chargerStates";
public static final String JSON_KEY_CHARGER_STATE = "chargerState";

// Write Commands
public static final String COMMAND_CHANGE_CONFIGURATION = "ChangeConfiguration";
Expand Down Expand Up @@ -130,7 +135,7 @@ public class EaseeBindingConstants {
public static final String REFRESH_TOKEN_URL = API_BASE_URL + "/accounts/refresh_token";
public static final String GET_SITE_URL = API_BASE_URL + "/sites/{siteId}";
public static final String CHARGER_URL = API_BASE_URL + "/chargers/{id}";
public static final String STATE_URL = API_BASE_URL + "/chargers/{id}/state";
public static final String SITE_STATE_URL = API_BASE_URL + "/sites/{siteId}/state";
public static final String GET_CONFIGURATION_URL = API_BASE_URL + "/chargers/{id}/config";
public static final String CHANGE_CONFIGURATION_URL = API_BASE_URL + "/chargers/{id}/settings";
public static final String COMMANDS_URL = API_BASE_URL + "/chargers/{id}/commands/{command}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

Expand Down Expand Up @@ -87,7 +85,7 @@ public static enum ProcessFailureResponse {
/**
* generic transformer which just transfers all values in a plain map.
*/
private final GenericResponseTransformer transformer;
protected final GenericResponseTransformer transformer;

/**
* retry counter.
Expand All @@ -107,29 +105,20 @@ public static enum ProcessFailureResponse {
/**
* allows further processing of the json result data, if set.
*/
private List<JsonResultProcessor> resultProcessors;
private final JsonResultProcessor resultProcessor;

/**
* the constructor
*/
public AbstractCommand(EaseeThingHandler handler, RetryOnFailure retryOnFailure,
ProcessFailureResponse processFailureResponse) {
ProcessFailureResponse processFailureResponse, JsonResultProcessor resultProcessor) {
this.gson = new GsonBuilder().setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE).create();
this.communicationStatus = new CommunicationStatus();
this.resultProcessors = new ArrayList<>();
this.transformer = new GenericResponseTransformer(handler);
this.handler = handler;
this.processFailureResponse = processFailureResponse;
this.retryOnFailure = retryOnFailure;
}

/**
* the constructor
*/
public AbstractCommand(EaseeThingHandler handler, RetryOnFailure retryOnFailure,
ProcessFailureResponse processFailureResponse, JsonResultProcessor resultProcessor) {
this(handler, retryOnFailure, processFailureResponse);
this.resultProcessors.add(resultProcessor);
this.resultProcessor = resultProcessor;
}

/**
Expand Down Expand Up @@ -237,7 +226,7 @@ protected void onCompleteCodeDefault(@Nullable String json) {
* @param json
* @return
*/
private @Nullable JsonObject transform(@Nullable String json) {
protected @Nullable JsonObject transform(@Nullable String json) {
if (json != null) {
try {
return gson.fromJson(json, JsonObject.class);
Expand Down Expand Up @@ -283,18 +272,16 @@ public CommunicationStatus getCommunicationStatus() {
}

/**
* calls the registered resultPRocessors.
* calls the registered resultProcessor.
*
* @param jsonObject
*/
protected final void processResult(JsonObject jsonObject) {
for (JsonResultProcessor processor : resultProcessors) {
try {
processor.processResult(getCommunicationStatus(), jsonObject);
} catch (Exception ex) {
// this should not happen
logger.warn("Exception caught: {}", ex.getMessage(), ex);
}
try {
resultProcessor.processResult(getCommunicationStatus(), jsonObject);
} catch (Exception ex) {
// this should not happen
logger.warn("Exception caught: {}", ex.getMessage(), ex);
}
}

Expand All @@ -320,9 +307,4 @@ protected final void processResult(JsonObject jsonObject) {
* @return Url
*/
protected abstract String getURL();

@Override
public void registerResultProcessor(JsonResultProcessor resultProcessor) {
this.resultProcessors.add(resultProcessor);
}
}
Loading

0 comments on commit a435ed2

Please sign in to comment.