]> git.basschouten.com Git - openhab-addons.git/commitdiff
[daikin] Fix NPE when setting zones on startup (#12165)
authorjimtng <2554958+jimtng@users.noreply.github.com>
Wed, 2 Feb 2022 16:35:15 +0000 (02:35 +1000)
committerGitHub <noreply@github.com>
Wed, 2 Feb 2022 16:35:15 +0000 (17:35 +0100)
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinAcUnitHandler.java
bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinAirbaseUnitHandler.java

index ef6a702678a34af1e4778e4018f210ec33c17f0f..c9a3774e77632ba7c3fa4ba0010822d49af4e470 100644 (file)
@@ -72,7 +72,6 @@ public class DaikinAcUnitHandler extends DaikinBaseHandler {
             return;
         }
         ControlInfo controlInfo = webTargets.getControlInfo();
-        updateStatus(ThingStatus.ONLINE);
         updateState(DaikinBindingConstants.CHANNEL_AC_POWER, controlInfo.power ? OnOffType.ON : OnOffType.OFF);
         updateTemperatureChannel(DaikinBindingConstants.CHANNEL_AC_TEMP, controlInfo.temp);
 
@@ -153,6 +152,7 @@ public class DaikinAcUnitHandler extends DaikinBaseHandler {
             // Suppress any error if energy info is not supported.
             logger.debug("getEnergyInfoDayAndWeek() error: {}", e.getMessage());
         }
+        updateStatus(ThingStatus.ONLINE);
     }
 
     @Override
index a7f7428b8ebd1e331a92e246f554bf0aac3f2fca..72ed5e5326272ca8367bfeff890590a701ec491a 100644 (file)
@@ -77,7 +77,6 @@ public class DaikinAirbaseUnitHandler extends DaikinBaseHandler {
     @Override
     protected void pollStatus() throws IOException {
         AirbaseControlInfo controlInfo = webTargets.getAirbaseControlInfo();
-        updateStatus(ThingStatus.ONLINE);
 
         if (airbaseModelInfo == null || !"OK".equals(airbaseModelInfo.ret)) {
             airbaseModelInfo = webTargets.getAirbaseModelInfo();
@@ -115,6 +114,7 @@ public class DaikinAirbaseUnitHandler extends DaikinBaseHandler {
                     .forEach(idx -> updateState(DaikinBindingConstants.CHANNEL_AIRBASE_AC_ZONE + idx,
                             OnOffType.from(zoneInfo.zone[idx])));
         }
+        updateStatus(ThingStatus.ONLINE);
     }
 
     @Override
@@ -178,18 +178,25 @@ public class DaikinAirbaseUnitHandler extends DaikinBaseHandler {
     }
 
     protected void changeZone(int zone, boolean command) throws DaikinCommunicationException {
-        if (zone <= 0 || zone > airbaseModelInfo.zonespresent) {
+        AirbaseZoneInfo zoneInfo = webTargets.getAirbaseZoneInfo();
+        long commonZones = 0;
+        long maxZones = zoneInfo.zone.length;
+
+        if (airbaseModelInfo != null) {
+            maxZones = Math.min(maxZones - 1, airbaseModelInfo.zonespresent);
+            commonZones = airbaseModelInfo.commonzone;
+        }
+        if (zone <= 0 || zone > maxZones) {
             logger.warn("The given zone number ({}) is outside the number of zones supported by the controller ({})",
-                    zone, airbaseModelInfo.zonespresent);
+                    zone, maxZones);
             return;
         }
 
-        AirbaseZoneInfo zoneInfo = webTargets.getAirbaseZoneInfo();
-        long count = IntStream.range(0, zoneInfo.zone.length).filter(idx -> zoneInfo.zone[idx]).count()
-                + airbaseModelInfo.commonzone;
-        logger.debug("Number of open zones: \"{}\"", count);
+        long openZones = IntStream.range(0, zoneInfo.zone.length).filter(idx -> zoneInfo.zone[idx]).count()
+                + commonZones;
+        logger.debug("Number of open zones: \"{}\"", openZones);
 
-        if (count >= 1) {
+        if (openZones >= 1) {
             zoneInfo.zone[zone] = command;
             webTargets.setAirbaseZoneInfo(zoneInfo);
         }