mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[evcc] Extend accepted types for commands & Handle quantity types of commands (#13795)
* [evcc] Extend accepted command types * [evcc] Convert QuantityType commands to required units * [evcc] Allow evcc URL to end with a slash Should fix an issue on the forum, where a user sent a command of DecimalType, but the binding expected a QuantityType. See https://community.openhab.org/t/evcc-binding-electric-vehicle-charging-control/135209/15. The accepted command types are extended for all channels if possible. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This commit is contained in:
parent
d3ecba9e79
commit
446be35ac5
@ -95,16 +95,27 @@ public class EvccHandler extends BaseThingHandler {
|
|||||||
case CHANNEL_LOADPOINT_MODE:
|
case CHANNEL_LOADPOINT_MODE:
|
||||||
if (command instanceof StringType) {
|
if (command instanceof StringType) {
|
||||||
evccAPI.setMode(loadpoint, command.toString());
|
evccAPI.setMode(loadpoint, command.toString());
|
||||||
|
} else {
|
||||||
|
logger.debug("Command has wrong type, StringType required!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHANNEL_LOADPOINT_MIN_SOC:
|
case CHANNEL_LOADPOINT_MIN_SOC:
|
||||||
if (command instanceof QuantityType) {
|
if (command instanceof QuantityType) {
|
||||||
evccAPI.setMinSoC(loadpoint, ((QuantityType<?>) command).intValue());
|
evccAPI.setMinSoC(loadpoint, ((QuantityType<?>) command).toUnit(Units.PERCENT).intValue());
|
||||||
|
} else if (command instanceof DecimalType) {
|
||||||
|
evccAPI.setMinSoC(loadpoint, ((DecimalType) command).intValue());
|
||||||
|
} else {
|
||||||
|
logger.debug("Command has wrong type, QuantityType or DecimalType required!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHANNEL_LOADPOINT_TARGET_SOC:
|
case CHANNEL_LOADPOINT_TARGET_SOC:
|
||||||
if (command instanceof QuantityType) {
|
if (command instanceof QuantityType) {
|
||||||
evccAPI.setTargetSoC(loadpoint, ((QuantityType<?>) command).intValue());
|
evccAPI.setTargetSoC(loadpoint,
|
||||||
|
((QuantityType<?>) command).toUnit(Units.PERCENT).intValue());
|
||||||
|
} else if (command instanceof DecimalType) {
|
||||||
|
evccAPI.setTargetSoC(loadpoint, ((DecimalType) command).intValue());
|
||||||
|
} else {
|
||||||
|
logger.debug("Command has wrong type, QuantityType or DecimalType required!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHANNEL_LOADPOINT_TARGET_TIME:
|
case CHANNEL_LOADPOINT_TARGET_TIME:
|
||||||
@ -120,6 +131,8 @@ public class EvccHandler extends BaseThingHandler {
|
|||||||
logger.debug("Failed to set target charge: ", e);
|
logger.debug("Failed to set target charge: ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logger.debug("Command has wrong type, DateTimeType required!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHANNEL_LOADPOINT_TARGET_TIME_ENABLED:
|
case CHANNEL_LOADPOINT_TARGET_TIME_ENABLED:
|
||||||
@ -129,21 +142,35 @@ public class EvccHandler extends BaseThingHandler {
|
|||||||
} else if (command == OnOffType.OFF) {
|
} else if (command == OnOffType.OFF) {
|
||||||
evccAPI.unsetTargetCharge(loadpoint);
|
evccAPI.unsetTargetCharge(loadpoint);
|
||||||
targetTimeEnabled = false;
|
targetTimeEnabled = false;
|
||||||
|
} else {
|
||||||
|
logger.debug("Command has wrong type, OnOffType required!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHANNEL_LOADPOINT_PHASES:
|
case CHANNEL_LOADPOINT_PHASES:
|
||||||
if (command instanceof DecimalType) {
|
if (command instanceof DecimalType) {
|
||||||
evccAPI.setPhases(loadpoint, ((DecimalType) command).intValue());
|
evccAPI.setPhases(loadpoint, ((DecimalType) command).intValue());
|
||||||
|
} else {
|
||||||
|
logger.debug("Command has wrong type, DecimalType required!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHANNEL_LOADPOINT_MIN_CURRENT:
|
case CHANNEL_LOADPOINT_MIN_CURRENT:
|
||||||
if (command instanceof QuantityType) {
|
if (command instanceof QuantityType) {
|
||||||
evccAPI.setMinCurrent(loadpoint, ((QuantityType<?>) command).intValue());
|
evccAPI.setMinCurrent(loadpoint,
|
||||||
|
((QuantityType<?>) command).toUnit(Units.AMPERE).intValue());
|
||||||
|
} else if (command instanceof DecimalType) {
|
||||||
|
evccAPI.setMinCurrent(loadpoint, ((DecimalType) command).intValue());
|
||||||
|
} else {
|
||||||
|
logger.debug("Command has wrong type, QuantityType or DecimalType required!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHANNEL_LOADPOINT_MAX_CURRENT:
|
case CHANNEL_LOADPOINT_MAX_CURRENT:
|
||||||
if (command instanceof QuantityType) {
|
if (command instanceof QuantityType) {
|
||||||
evccAPI.setMaxCurrent(loadpoint, ((QuantityType<?>) command).intValue());
|
evccAPI.setMaxCurrent(loadpoint,
|
||||||
|
((QuantityType<?>) command).toUnit(Units.AMPERE).intValue());
|
||||||
|
} else if (command instanceof DecimalType) {
|
||||||
|
evccAPI.setMaxCurrent(loadpoint, ((DecimalType) command).intValue());
|
||||||
|
} else {
|
||||||
|
logger.debug("Command has wrong type, QuantityType or DecimalType required!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -41,7 +41,7 @@ public class EvccAPI {
|
|||||||
private String host;
|
private String host;
|
||||||
|
|
||||||
public EvccAPI(String host) {
|
public EvccAPI(String host) {
|
||||||
this.host = host;
|
this.host = (host.endsWith("/") ? host.substring(0, host.length() - 1) : host);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user