mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-26 15:21:41 +01:00
[km200] Added JCE check and removed some warnings (#11841)
* Added a check if JCE is installed * removed warnings Signed-off-by: Markus Eckhardt <github@familie-eckhardt.eu>
This commit is contained in:
parent
e44dfe7dbc
commit
94401fc798
@ -282,7 +282,7 @@ public class KM200Device {
|
|||||||
object = serviceTreeMap.get(servicePath[1]);
|
object = serviceTreeMap.get(servicePath[1]);
|
||||||
}
|
}
|
||||||
for (int i = 2; i < len; i++) {
|
for (int i = 2; i < len; i++) {
|
||||||
if (object.serviceTreeMap.containsKey(servicePath[i])) {
|
if (object != null && object.serviceTreeMap.containsKey(servicePath[i])) {
|
||||||
object = object.serviceTreeMap.get(servicePath[i]);
|
object = object.serviceTreeMap.get(servicePath[i]);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
@ -313,7 +313,7 @@ public class KM200Device {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 2; i < len; i++) {
|
for (int i = 2; i < len; i++) {
|
||||||
if (object.serviceTreeMap.containsKey(servicePath[i])) {
|
if (object != null && object.serviceTreeMap.containsKey(servicePath[i])) {
|
||||||
object = object.serviceTreeMap.get(servicePath[i]);
|
object = object.serviceTreeMap.get(servicePath[i]);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
@ -105,7 +105,9 @@ public class KM200HandlerFactory extends BaseThingHandlerFactory {
|
|||||||
protected synchronized void removeHandler(ThingHandler thingHandler) {
|
protected synchronized void removeHandler(ThingHandler thingHandler) {
|
||||||
if (thingHandler instanceof KM200GatewayHandler) {
|
if (thingHandler instanceof KM200GatewayHandler) {
|
||||||
ServiceRegistration<?> serviceReg = this.discoveryServiceRegs.get(thingHandler.getThing().getUID());
|
ServiceRegistration<?> serviceReg = this.discoveryServiceRegs.get(thingHandler.getThing().getUID());
|
||||||
serviceReg.unregister();
|
if (serviceReg != null) {
|
||||||
|
serviceReg.unregister();
|
||||||
|
}
|
||||||
discoveryServiceRegs.remove(thingHandler.getThing().getUID());
|
discoveryServiceRegs.remove(thingHandler.getThing().getUID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,40 +138,44 @@ public class KM200GatewayDiscoveryService extends AbstractDiscoveryService imple
|
|||||||
|
|
||||||
KM200ServiceObject switchObject = object.serviceTreeMap.get(key).serviceTreeMap
|
KM200ServiceObject switchObject = object.serviceTreeMap.get(key).serviceTreeMap
|
||||||
.get(SWITCH_PROGRAM_PATH_NAME);
|
.get(SWITCH_PROGRAM_PATH_NAME);
|
||||||
if (switchObject.serviceTreeMap.isEmpty()) {
|
if (switchObject != null) {
|
||||||
continue;
|
if (switchObject.serviceTreeMap.isEmpty()) {
|
||||||
}
|
continue;
|
||||||
/*
|
|
||||||
* if the device has only one switching program then the "activeSwitchProgram" service is
|
|
||||||
* not existing. In this case we are using a fix path to this one service.
|
|
||||||
*/
|
|
||||||
if (!currExists) {
|
|
||||||
if (switchObject.serviceTreeMap.keySet().size() == 1) {
|
|
||||||
currParaRepl = switchObject.serviceTreeMap.entrySet().iterator().next().getKey();
|
|
||||||
}
|
}
|
||||||
}
|
/*
|
||||||
KM200SwitchProgramServiceHandler valPara = (KM200SwitchProgramServiceHandler) switchObject.serviceTreeMap
|
* if the device has only one switching program then the "activeSwitchProgram" service
|
||||||
.entrySet().iterator().next().getValue().getValueParameter();
|
* is
|
||||||
if (null != valPara) {
|
* not existing. In this case we are using a fix path to this one service.
|
||||||
String posName = valPara.getPositiveSwitch();
|
*/
|
||||||
String negName = valPara.getNegativeSwitch();
|
if (!currExists) {
|
||||||
if (null == posName || null == negName) {
|
if (switchObject.serviceTreeMap.keySet().size() == 1) {
|
||||||
logger.warn("Service switches not found!");
|
currParaRepl = switchObject.serviceTreeMap.entrySet().iterator().next()
|
||||||
return;
|
.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KM200SwitchProgramServiceHandler valPara = (KM200SwitchProgramServiceHandler) switchObject.serviceTreeMap
|
||||||
|
.entrySet().iterator().next().getValue().getValueParameter();
|
||||||
|
if (null != valPara) {
|
||||||
|
String posName = valPara.getPositiveSwitch();
|
||||||
|
String negName = valPara.getNegativeSwitch();
|
||||||
|
if (null == posName || null == negName) {
|
||||||
|
logger.warn("Service switches not found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ThingUID subThingUID = new ThingUID(tType.getThingTypeUID(), bridgeUID,
|
||||||
|
key + "-switchprogram");
|
||||||
|
Map<String, Object> subProperties = new HashMap<>(4);
|
||||||
|
subProperties.put("root", KM200Utils.translatesPathToName(
|
||||||
|
root + "/" + key + "/" + SWITCH_PROGRAM_PATH_NAME + "/" + currParaRepl));
|
||||||
|
subProperties.put(SWITCH_PROGRAM_CURRENT_PATH_NAME,
|
||||||
|
KM200Utils.translatesPathToName(currentPathName));
|
||||||
|
subProperties.put(SWITCH_PROGRAM_POSITIVE, posName);
|
||||||
|
subProperties.put(SWITCH_PROGRAM_NEGATIVE, negName);
|
||||||
|
DiscoveryResult subDiscoveryResult = DiscoveryResultBuilder.create(subThingUID)
|
||||||
|
.withBridge(bridgeUID).withLabel(key + " switch program")
|
||||||
|
.withProperties(subProperties).build();
|
||||||
|
thingDiscovered(subDiscoveryResult);
|
||||||
}
|
}
|
||||||
ThingUID subThingUID = new ThingUID(tType.getThingTypeUID(), bridgeUID,
|
|
||||||
key + "-switchprogram");
|
|
||||||
Map<String, Object> subProperties = new HashMap<>(4);
|
|
||||||
subProperties.put("root", KM200Utils.translatesPathToName(
|
|
||||||
root + "/" + key + "/" + SWITCH_PROGRAM_PATH_NAME + "/" + currParaRepl));
|
|
||||||
subProperties.put(SWITCH_PROGRAM_CURRENT_PATH_NAME,
|
|
||||||
KM200Utils.translatesPathToName(currentPathName));
|
|
||||||
subProperties.put(SWITCH_PROGRAM_POSITIVE, posName);
|
|
||||||
subProperties.put(SWITCH_PROGRAM_NEGATIVE, negName);
|
|
||||||
DiscoveryResult subDiscoveryResult = DiscoveryResultBuilder.create(subThingUID)
|
|
||||||
.withBridge(bridgeUID).withLabel(key + " switch program")
|
|
||||||
.withProperties(subProperties).build();
|
|
||||||
thingDiscovered(subDiscoveryResult);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import static org.openhab.binding.km200.internal.KM200BindingConstants.*;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -30,6 +31,8 @@ import java.util.concurrent.Executors;
|
|||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.eclipse.jetty.client.HttpClient;
|
import org.eclipse.jetty.client.HttpClient;
|
||||||
@ -109,6 +112,17 @@ public class KM200GatewayHandler extends BaseBridgeHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
try {
|
||||||
|
int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES/ECB/NoPadding");
|
||||||
|
if (maxKeyLen <= 128) {
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
|
"Java Cryptography Extension (JCE) have to be installed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "AES encoding not supported");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!getDevice().getInited()) {
|
if (!getDevice().getInited()) {
|
||||||
logger.info("Update KM50/100/200 gateway configuration, it takes a minute....");
|
logger.info("Update KM50/100/200 gateway configuration, it takes a minute....");
|
||||||
getConfiguration();
|
getConfiguration();
|
||||||
@ -323,17 +337,20 @@ public class KM200GatewayHandler extends BaseBridgeHandler {
|
|||||||
for (String subKey : asProperties) {
|
for (String subKey : asProperties) {
|
||||||
if (serObj.serviceTreeMap.containsKey(subKey)) {
|
if (serObj.serviceTreeMap.containsKey(subKey)) {
|
||||||
KM200ServiceObject subKeyObj = serObj.serviceTreeMap.get(subKey);
|
KM200ServiceObject subKeyObj = serObj.serviceTreeMap.get(subKey);
|
||||||
String subKeyType = subKeyObj.getServiceType();
|
if (subKeyObj != null) {
|
||||||
if (!DATA_TYPE_STRING_VALUE.equals(subKeyType) && !DATA_TYPE_FLOAT_VALUE.equals(subKeyType)) {
|
String subKeyType = subKeyObj.getServiceType();
|
||||||
continue;
|
if (!DATA_TYPE_STRING_VALUE.equals(subKeyType)
|
||||||
}
|
&& !DATA_TYPE_FLOAT_VALUE.equals(subKeyType)) {
|
||||||
if (bridgeProperties.containsKey(subKey)) {
|
continue;
|
||||||
bridgeProperties.remove(subKey);
|
}
|
||||||
}
|
if (bridgeProperties.containsKey(subKey)) {
|
||||||
Object value = subKeyObj.getValue();
|
bridgeProperties.remove(subKey);
|
||||||
logger.trace("Add Property: {} :{}", subKey, value);
|
}
|
||||||
if (null != value) {
|
Object value = subKeyObj.getValue();
|
||||||
bridgeProperties.put(subKey, value.toString());
|
logger.trace("Add Property: {} :{}", subKey, value);
|
||||||
|
if (null != value) {
|
||||||
|
bridgeProperties.put(subKey, value.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.km200.internal.KM200Device;
|
import org.openhab.binding.km200.internal.KM200Device;
|
||||||
import org.openhab.binding.km200.internal.KM200ServiceObject;
|
import org.openhab.binding.km200.internal.KM200ServiceObject;
|
||||||
@ -68,11 +67,10 @@ public class KM200SwitchProgramServiceHandler {
|
|||||||
private static List<String> days = new ArrayList<>(Arrays.asList(TYPE_MONDAY, TYPE_TUESDAY, TYPE_WEDNESDAY,
|
private static List<String> days = new ArrayList<>(Arrays.asList(TYPE_MONDAY, TYPE_TUESDAY, TYPE_WEDNESDAY,
|
||||||
TYPE_THURSDAY, TYPE_FRIDAY, TYPE_SATURDAY, TYPE_SUNDAY));
|
TYPE_THURSDAY, TYPE_FRIDAY, TYPE_SATURDAY, TYPE_SUNDAY));
|
||||||
|
|
||||||
public static List<@NonNull StateOption> daysList = new ArrayList<>(
|
public static List<StateOption> daysList = List.of(new StateOption(TYPE_MONDAY, "Monday"),
|
||||||
Arrays.asList(new StateOption(TYPE_MONDAY, "Monday"), new StateOption(TYPE_TUESDAY, "Tuesday"),
|
new StateOption(TYPE_TUESDAY, "Tuesday"), new StateOption(TYPE_WEDNESDAY, "Wednesday"),
|
||||||
new StateOption(TYPE_WEDNESDAY, "Wednesday"), new StateOption(TYPE_THURSDAY, "Thursday"),
|
new StateOption(TYPE_THURSDAY, "Thursday"), new StateOption(TYPE_FRIDAY, "Friday"),
|
||||||
new StateOption(TYPE_FRIDAY, "Friday"), new StateOption(TYPE_SATURDAY, "Saturday"),
|
new StateOption(TYPE_SATURDAY, "Saturday"), new StateOption(TYPE_SUNDAY, "Sunday"));
|
||||||
new StateOption(TYPE_SUNDAY, "Sunday")));
|
|
||||||
|
|
||||||
/* List with setpoints */
|
/* List with setpoints */
|
||||||
private List<String> setpoints = new ArrayList<>();
|
private List<String> setpoints = new ArrayList<>();
|
||||||
@ -118,9 +116,13 @@ public class KM200SwitchProgramServiceHandler {
|
|||||||
initWeeklist(setpoint);
|
initWeeklist(setpoint);
|
||||||
weekMap = switchMap.get(setpoint);
|
weekMap = switchMap.get(setpoint);
|
||||||
}
|
}
|
||||||
List<Integer> dayList = weekMap.get(day);
|
if (weekMap != null) {
|
||||||
dayList.add(time);
|
List<Integer> dayList = weekMap.get(day);
|
||||||
Collections.sort(dayList);
|
if (dayList != null) {
|
||||||
|
dayList.add(time);
|
||||||
|
Collections.sort(dayList);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -484,12 +486,20 @@ public class KM200SwitchProgramServiceHandler {
|
|||||||
synchronized (switchMap) {
|
synchronized (switchMap) {
|
||||||
Map<String, List<Integer>> weekP = switchMap.get(getPositiveSwitch());
|
Map<String, List<Integer>> weekP = switchMap.get(getPositiveSwitch());
|
||||||
Map<String, List<Integer>> weekN = switchMap.get(getNegativeSwitch());
|
Map<String, List<Integer>> weekN = switchMap.get(getNegativeSwitch());
|
||||||
if (weekP.isEmpty() && weekN.isEmpty()) {
|
if (weekP != null && weekN != null) {
|
||||||
|
if (weekP.isEmpty() && weekN.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
List<Integer> daysListP = weekP.get(getActiveDay());
|
||||||
|
List<Integer> daysListN = weekN.get(getActiveDay());
|
||||||
|
if (daysListP != null && daysListN != null) {
|
||||||
|
return Math.min(daysListP.size(), daysListN.size());
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
List<Integer> daysListP = weekP.get(getActiveDay());
|
|
||||||
List<Integer> daysListN = weekN.get(getActiveDay());
|
|
||||||
return Math.min(daysListP.size(), daysListN.size());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,7 +525,7 @@ public class KM200SwitchProgramServiceHandler {
|
|||||||
Map<String, List<Integer>> week = switchMap.get(getPositiveSwitch());
|
Map<String, List<Integer>> week = switchMap.get(getPositiveSwitch());
|
||||||
if (week != null) {
|
if (week != null) {
|
||||||
List<Integer> daysList = week.get(getActiveDay());
|
List<Integer> daysList = week.get(getActiveDay());
|
||||||
if (!daysList.isEmpty()) {
|
if (daysList != null && !daysList.isEmpty()) {
|
||||||
Integer cycl = getActiveCycle();
|
Integer cycl = getActiveCycle();
|
||||||
if (cycl <= daysList.size()) {
|
if (cycl <= daysList.size()) {
|
||||||
return (daysList.get(getActiveCycle() - 1));
|
return (daysList.get(getActiveCycle() - 1));
|
||||||
@ -534,7 +544,7 @@ public class KM200SwitchProgramServiceHandler {
|
|||||||
Map<String, List<Integer>> week = switchMap.get(getNegativeSwitch());
|
Map<String, List<Integer>> week = switchMap.get(getNegativeSwitch());
|
||||||
if (week != null) {
|
if (week != null) {
|
||||||
List<Integer> daysList = week.get(getActiveDay());
|
List<Integer> daysList = week.get(getActiveDay());
|
||||||
if (!daysList.isEmpty()) {
|
if (daysList != null && !daysList.isEmpty()) {
|
||||||
Integer cycl = getActiveCycle();
|
Integer cycl = getActiveCycle();
|
||||||
if (cycl <= daysList.size()) {
|
if (cycl <= daysList.size()) {
|
||||||
return (daysList.get(getActiveCycle() - 1));
|
return (daysList.get(getActiveCycle() - 1));
|
||||||
|
Loading…
Reference in New Issue
Block a user