object = serviceTreeMap.get(servicePath[1]);
}
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]);
continue;
} else {
}
}
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]);
continue;
} else {
protected synchronized void removeHandler(ThingHandler thingHandler) {
if (thingHandler instanceof KM200GatewayHandler) {
ServiceRegistration<?> serviceReg = this.discoveryServiceRegs.get(thingHandler.getThing().getUID());
- serviceReg.unregister();
+ if (serviceReg != null) {
+ serviceReg.unregister();
+ }
discoveryServiceRegs.remove(thingHandler.getThing().getUID());
}
}
KM200ServiceObject switchObject = object.serviceTreeMap.get(key).serviceTreeMap
.get(SWITCH_PROGRAM_PATH_NAME);
- 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();
+ if (switchObject != null) {
+ if (switchObject.serviceTreeMap.isEmpty()) {
+ continue;
}
- }
- 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;
+ /*
+ * 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
+ .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);
}
}
}
import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import javax.crypto.Cipher;
+
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
@Override
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()) {
logger.info("Update KM50/100/200 gateway configuration, it takes a minute....");
getConfiguration();
for (String subKey : asProperties) {
if (serObj.serviceTreeMap.containsKey(subKey)) {
KM200ServiceObject subKeyObj = serObj.serviceTreeMap.get(subKey);
- String subKeyType = subKeyObj.getServiceType();
- if (!DATA_TYPE_STRING_VALUE.equals(subKeyType) && !DATA_TYPE_FLOAT_VALUE.equals(subKeyType)) {
- continue;
- }
- if (bridgeProperties.containsKey(subKey)) {
- bridgeProperties.remove(subKey);
- }
- Object value = subKeyObj.getValue();
- logger.trace("Add Property: {} :{}", subKey, value);
- if (null != value) {
- bridgeProperties.put(subKey, value.toString());
+ if (subKeyObj != null) {
+ String subKeyType = subKeyObj.getServiceType();
+ if (!DATA_TYPE_STRING_VALUE.equals(subKeyType)
+ && !DATA_TYPE_FLOAT_VALUE.equals(subKeyType)) {
+ continue;
+ }
+ if (bridgeProperties.containsKey(subKey)) {
+ bridgeProperties.remove(subKey);
+ }
+ Object value = subKeyObj.getValue();
+ logger.trace("Add Property: {} :{}", subKey, value);
+ if (null != value) {
+ bridgeProperties.put(subKey, value.toString());
+ }
}
}
}
import java.util.List;
import java.util.Map;
-import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.km200.internal.KM200Device;
import org.openhab.binding.km200.internal.KM200ServiceObject;
private static List<String> days = new ArrayList<>(Arrays.asList(TYPE_MONDAY, TYPE_TUESDAY, TYPE_WEDNESDAY,
TYPE_THURSDAY, TYPE_FRIDAY, TYPE_SATURDAY, TYPE_SUNDAY));
- public static List<@NonNull StateOption> daysList = new ArrayList<>(
- Arrays.asList(new StateOption(TYPE_MONDAY, "Monday"), new StateOption(TYPE_TUESDAY, "Tuesday"),
- new StateOption(TYPE_WEDNESDAY, "Wednesday"), new StateOption(TYPE_THURSDAY, "Thursday"),
- new StateOption(TYPE_FRIDAY, "Friday"), new StateOption(TYPE_SATURDAY, "Saturday"),
- new StateOption(TYPE_SUNDAY, "Sunday")));
+ public static List<StateOption> daysList = List.of(new StateOption(TYPE_MONDAY, "Monday"),
+ new StateOption(TYPE_TUESDAY, "Tuesday"), new StateOption(TYPE_WEDNESDAY, "Wednesday"),
+ new StateOption(TYPE_THURSDAY, "Thursday"), new StateOption(TYPE_FRIDAY, "Friday"),
+ new StateOption(TYPE_SATURDAY, "Saturday"), new StateOption(TYPE_SUNDAY, "Sunday"));
/* List with setpoints */
private List<String> setpoints = new ArrayList<>();
initWeeklist(setpoint);
weekMap = switchMap.get(setpoint);
}
- List<Integer> dayList = weekMap.get(day);
- dayList.add(time);
- Collections.sort(dayList);
+ if (weekMap != null) {
+ List<Integer> dayList = weekMap.get(day);
+ if (dayList != null) {
+ dayList.add(time);
+ Collections.sort(dayList);
+ }
+ }
}
/**
synchronized (switchMap) {
Map<String, List<Integer>> weekP = switchMap.get(getPositiveSwitch());
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;
}
- List<Integer> daysListP = weekP.get(getActiveDay());
- List<Integer> daysListN = weekN.get(getActiveDay());
- return Math.min(daysListP.size(), daysListN.size());
}
}
Map<String, List<Integer>> week = switchMap.get(getPositiveSwitch());
if (week != null) {
List<Integer> daysList = week.get(getActiveDay());
- if (!daysList.isEmpty()) {
+ if (daysList != null && !daysList.isEmpty()) {
Integer cycl = getActiveCycle();
if (cycl <= daysList.size()) {
return (daysList.get(getActiveCycle() - 1));
Map<String, List<Integer>> week = switchMap.get(getNegativeSwitch());
if (week != null) {
List<Integer> daysList = week.get(getActiveDay());
- if (!daysList.isEmpty()) {
+ if (daysList != null && !daysList.isEmpty()) {
Integer cycl = getActiveCycle();
if (cycl <= daysList.size()) {
return (daysList.get(getActiveCycle() - 1));