Skip to content

Commit

Permalink
[Keba] Removed check of firmware version (openhab#4987)
Browse files Browse the repository at this point in the history
* Removed check of firmware version
* Make sure that send commands to not block forever if they do not receive a response

Signed-off-by: Kai Kreuzer <[email protected]>
Signed-off-by: Pshatsillo <[email protected]>
  • Loading branch information
kaikreuzer authored and Pshatsillo committed Jun 19, 2019
1 parent 261874c commit cb6f4f6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 50 deletions.
2 changes: 1 addition & 1 deletion addons/binding/org.openhab.binding.keba/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ All devices support the following channels (non exhaustive):
| Channel Type ID | Item Type | Description | | |
|------------------|-----------|---------------------------------------------------------------------------------------------------|---|---|
| state | Number | This channel indicates the current operational state of the wallbox | | |
| maxpresetcurrent | Number | This channel supports adjusting the maximim current the charging station should deliver to the EV | | |
| maxpresetcurrent | Number | This channel supports adjusting the maximum current the charging station should deliver to the EV | | |
| power | Number | This channel indicates the active power delivered by the charging station | | |
| I1/2/3 | Number | This channel indicates the current for the given phase | | |
| U1/2/3 | Number | This channel indicates the voltage for the given phase | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,38 +100,4 @@ public static KebaSeries getSeries(char text) throws IllegalArgumentException {
throw new IllegalArgumentException("Not a valid series");
}
};

public enum KebaFirmware {
V201M21("2.01m21"),
V22A1("2.2a1"),
V23A2("2.3a2"),
V23A3("2.3a3"),
V25A3("2.5a3"),
V3042A1("3.04.2a1"),
V3062A5("3.06.2a5"),
V3071A1("3.07.1a1"),
V3084("3.08.4");

private final String id;

private KebaFirmware(final String id) {
this.id = id;
}

@Override
public String toString() {
return id;
}

public static KebaFirmware getFirmware(String text) throws IllegalArgumentException {
for (KebaFirmware c : KebaFirmware.values()) {
if (text.contains(c.id)) {
return c;
}
}

throw new IllegalArgumentException("Not a valid firmware");
}

};
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.RefreshType;
import org.eclipse.smarthome.core.types.State;
import org.openhab.binding.keba.internal.KebaBindingConstants.KebaFirmware;
import org.openhab.binding.keba.internal.KebaBindingConstants.KebaSeries;
import org.openhab.binding.keba.internal.KebaBindingConstants.KebaType;
import org.slf4j.Logger;
Expand Down Expand Up @@ -83,10 +82,8 @@ public class KeContactHandler extends BaseThingHandler {
private int maxPresetCurrent = 0;
private int maxSystemCurrent = 63000;
private KebaType type;
private KebaFirmware firmware;
private KebaSeries series;

@SuppressWarnings("null")
public KeContactHandler(Thing thing) {
super(thing);
}
Expand All @@ -96,6 +93,13 @@ public void initialize() {
if (getConfig().get(IP_ADDRESS) != null && !getConfig().get(IP_ADDRESS).equals("")) {
transceiver.registerHandler(this);

cache = new ExpiringCacheMap<>(
Math.max((((BigDecimal) getConfig().get(POLLING_REFRESH_INTERVAL)).intValue()) - 5, 0) * 1000);

cache.put(CACHE_REPORT_1, () -> transceiver.send("report 1", getHandler()));
cache.put(CACHE_REPORT_2, () -> transceiver.send("report 2", getHandler()));
cache.put(CACHE_REPORT_3, () -> transceiver.send("report 3", getHandler()));

if (pollingJob == null || pollingJob.isCancelled()) {
try {
pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 0,
Expand All @@ -105,13 +109,6 @@ public void initialize() {
"An exception occurred while scheduling the polling job");
}
}

cache = new ExpiringCacheMap<>(
Math.max((((BigDecimal) getConfig().get(POLLING_REFRESH_INTERVAL)).intValue()) - 5, 0) * 1000);

cache.put(CACHE_REPORT_1, () -> transceiver.send("report 1", getHandler()));
cache.put(CACHE_REPORT_2, () -> transceiver.send("report 2", getHandler()));
cache.put(CACHE_REPORT_3, () -> transceiver.send("report 3", getHandler()));
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"IP address or port number not set");
Expand Down Expand Up @@ -174,12 +171,14 @@ protected Configuration getConfig() {
}
}
}
} catch (InterruptedException | NumberFormatException | IOException e) {
} catch (NumberFormatException | IOException e) {
logger.debug("An exception occurred while polling the KEBA KeContact '{}': {}", getThing().getUID(),
e.getMessage(), e);
Thread.currentThread().interrupt();
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"An exception occurred while while polling the charging station");
} catch (InterruptedException e) {
logger.debug("Polling job has been interrupted for handler of thing '{}'.", getThing().getUID());
}
};

Expand Down Expand Up @@ -220,7 +219,6 @@ protected void onData(ByteBuffer byteBuffer) {
Map<String, String> properties = editProperties();
properties.put(CHANNEL_FIRMWARE, entry.getValue().getAsString());
updateProperties(properties);
firmware = KebaFirmware.getFirmware(entry.getValue().getAsString());
break;
}
case "Plug": {
Expand Down Expand Up @@ -425,7 +423,8 @@ protected void onData(ByteBuffer byteBuffer) {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if ((command instanceof RefreshType)) {
scheduler.schedule(pollingRunnable, 0, TimeUnit.SECONDS);
// let's assume we do frequent enough polling and ignore the REFRESH request here
// in order to prevent too many channel state updates
} else {
switch (channelUID.getId()) {
case CHANNEL_MAX_PRESET_CURRENT: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void start() {
selector = Selector.open();

if (transceiverThread == null) {
transceiverThread = new Thread(transceiverRunnable, "ESH-Keba-Transceiver");
transceiverThread = new Thread(transceiverRunnable, "openHAB-Keba-Transceiver");
transceiverThread.start();
}

Expand Down Expand Up @@ -196,7 +196,7 @@ protected ByteBuffer send(String message, KeContactHandler handler) {
logger.trace("{} waiting on handerLock {}", Thread.currentThread().getName(),
handlerLock.toString());
}
handlerLock.wait();
handlerLock.wait(KeContactHandler.REPORT_INTERVAL);
}

return buffers.remove(handler);
Expand Down

0 comments on commit cb6f4f6

Please sign in to comment.