]> git.basschouten.com Git - openhab-addons.git/commitdiff
[sensibo] Fix channel provider throwing exception (#17030)
authorArne Seime <seime@users.noreply.github.com>
Tue, 16 Jul 2024 16:40:17 +0000 (18:40 +0200)
committerGitHub <noreply@github.com>
Tue, 16 Jul 2024 16:40:17 +0000 (18:40 +0200)
* Fix channel provider throwing exception
* Add case insensitive mac address comparison

Signed-off-by: Arne Seime <arne.seime@gmail.com>
bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/CallbackChannelsTypeProvider.java
bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java
bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/model/SensiboModel.java
bundles/org.openhab.binding.sensibo/src/test/java/org/openhab/binding/sensibo/internal/SensiboModelTest.java [new file with mode: 0644]
bundles/org.openhab.binding.sensibo/src/test/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandlerTest.java
bundles/org.openhab.binding.sensibo/src/test/resources/get_pod_details_response_valter.json [new file with mode: 0644]

index e9bd52b20676b83e98c9043af792f5b805fdaa3c..61819bb06add9f622ec65e7e4411956b805340ae 100644 (file)
@@ -14,6 +14,7 @@ package org.openhab.binding.sensibo.internal;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.List;
 import java.util.Locale;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -44,12 +45,12 @@ public class CallbackChannelsTypeProvider
 
     @Override
     public Collection<ChannelType> getChannelTypes(@Nullable final Locale locale) {
-        return handler.getChannelTypes(locale);
+        return handler != null ? handler.getChannelTypes(locale) : List.of();
     }
 
     @Override
     public @Nullable ChannelType getChannelType(final ChannelTypeUID channelTypeUID, @Nullable final Locale locale) {
-        return handler.getChannelType(channelTypeUID, locale);
+        return handler != null ? handler.getChannelType(channelTypeUID, locale) : null;
     }
 
     @Override
index 6668a8019df634654bc61eca8d5c819c60ec44da..9de972e5010f77483d260a213ba9f55d633d7112 100644 (file)
@@ -297,8 +297,10 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
     public void initialize() {
         config = Optional.ofNullable(getConfigAs(SensiboSkyConfiguration.class));
         logger.debug("Initializing SensiboSky using config {}", config);
-        getSensiboModel().findSensiboSkyByMacAddress(getMacAddress()).ifPresent(pod -> {
+        Optional<SensiboSky> optionalDevice = getSensiboModel().findSensiboSkyByMacAddress(getMacAddress());
 
+        if (optionalDevice.isPresent()) {
+            SensiboSky pod = optionalDevice.get();
             if (pod.isAlive()) {
                 addDynamicChannelsAndProperties(pod);
                 updateStatus(ThingStatus.ONLINE);
@@ -306,7 +308,10 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
                 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
                         "Unreachable by Sensibo servers");
             }
-        });
+        } else {
+            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+                    String.format("Device with mac address %s not found", getMacAddress()));
+        }
     }
 
     private boolean isDynamicChannel(final ChannelTypeUID uid) {
index 2f211b17c2dbaf84324122237eb7df671b1c7e0e..45375bcee037f6135191262017d589dd01391a98 100644 (file)
@@ -46,7 +46,7 @@ public class SensiboModel {
 
     public Optional<SensiboSky> findSensiboSkyByMacAddress(final String macAddress) {
         final String macAddressWithoutColons = macAddress.replace(":", "");
-        return pods.stream().filter(pod -> macAddressWithoutColons.equals(pod.getMacAddress())).findFirst();
+        return pods.stream().filter(pod -> macAddressWithoutColons.equalsIgnoreCase(pod.getMacAddress())).findFirst();
     }
 
     /**
diff --git a/bundles/org.openhab.binding.sensibo/src/test/java/org/openhab/binding/sensibo/internal/SensiboModelTest.java b/bundles/org.openhab.binding.sensibo/src/test/java/org/openhab/binding/sensibo/internal/SensiboModelTest.java
new file mode 100644 (file)
index 0000000..6c538b8
--- /dev/null
@@ -0,0 +1,46 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.sensibo.internal;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+
+import org.junit.jupiter.api.Test;
+import org.openhab.binding.sensibo.internal.dto.poddetails.PodDetailsDTO;
+import org.openhab.binding.sensibo.internal.model.SensiboModel;
+import org.openhab.binding.sensibo.internal.model.SensiboSky;
+
+/**
+ * @author Arne Seime - Initial contribution
+ * 
+ */
+public class SensiboModelTest {
+
+    private final WireHelper wireHelper = new WireHelper();
+
+    @Test
+    public void testCaseInsensitiveMacAddress() throws IOException {
+
+        final PodDetailsDTO rsp = wireHelper.deSerializeResponse("/get_pod_details_response.json", PodDetailsDTO.class);
+        SensiboSky sky = new SensiboSky(rsp);
+
+        SensiboModel model = new SensiboModel(0);
+        model.addPod(sky);
+
+        assertFalse(model.findSensiboSkyByMacAddress("MA:C:AD:DR:ES:XX").isPresent());
+        assertTrue(model.findSensiboSkyByMacAddress("MA:C:AD:DR:ES:S0").isPresent());
+        assertTrue(model.findSensiboSkyByMacAddress("MA:C:AD:DR:ES:S0".toLowerCase()).isPresent());
+    }
+}
index 9cd95149aa35d913b12a50d8658bb2da14b062ac..0117107cfadc06d2c20b9bcd052c18d26650c8ec 100644 (file)
@@ -126,6 +126,11 @@ public class SensiboSkyHandlerTest {
         testAddDynamicChannels("/get_pod_details_response.json");
     }
 
+    @Test
+    public void testAddDynamicChannelsValter() throws IOException, SensiboCommunicationException {
+        testAddDynamicChannels("/get_pod_details_response_valter.json");
+    }
+
     private void testAddDynamicChannels(String podDetailsResponse) throws IOException, SensiboCommunicationException {
         final PodDetailsDTO rsp = wireHelper.deSerializeResponse(podDetailsResponse, PodDetailsDTO.class);
         SensiboSky sky = new SensiboSky(rsp);
diff --git a/bundles/org.openhab.binding.sensibo/src/test/resources/get_pod_details_response_valter.json b/bundles/org.openhab.binding.sensibo/src/test/resources/get_pod_details_response_valter.json
new file mode 100644 (file)
index 0000000..1a4c2a6
--- /dev/null
@@ -0,0 +1,408 @@
+
+{
+  "status": "success",
+  "result": {
+    "id": "IDIDIDIDI",
+    "qrId": "SFWZNCVZQE",
+    "temperatureUnit": "C",
+    "room": {
+      "uid": "JCs8iZDs",
+      "name": "Uppe",
+      "icon": "Livingroom"
+    },
+    "acState": {
+      "timestamp": {
+        "time": "2024-07-10T13:37:08.892645Z",
+        "secondsAgo": 0
+      },
+      "on": true,
+      "mode": "cool",
+      "targetTemperature": 21,
+      "temperatureUnit": "C",
+      "fanLevel": "high",
+      "swing": "stopped",
+      "horizontalSwing": "stopped"
+    },
+    "lastStateChange": {
+      "time": "2024-07-10T09:34:59Z",
+      "secondsAgo": 14529
+    },
+    "lastStateChangeToOn": {
+      "time": "2024-06-29T20:05:50Z",
+      "secondsAgo": 927078
+    },
+    "lastStateChangeToOff": {
+      "time": "2024-06-29T20:05:49Z",
+      "secondsAgo": 927079
+    },
+    "location": {
+      "id": "Vy5YqF7Zhd",
+      "name": "Home",
+      "latLon": [
+        58.340266022912814,
+        13.833971541444877
+      ],
+      "address": [
+        "Address 13",
+        " Zip place",
+        " Country"
+      ],
+      "countryAlpha2": "SE",
+      "createTime": {
+        "time": "2023-12-11T13:49:04Z",
+        "secondsAgo": 18316084
+      },
+      "updateTime": {
+        "time": "2023-12-11T13:49:14Z",
+        "secondsAgo": 18316074
+      },
+      "features": [],
+      "geofenceTriggerRadius": 200,
+      "shareAnalytics": false,
+      "currency": ""
+    },
+    "connectionStatus": {
+      "isAlive": true,
+      "lastSeen": {
+        "time": "2024-07-10T13:36:50.018202Z",
+        "secondsAgo": 17
+      }
+    },
+    "firmwareVersion": "SKY30047",
+    "firmwareType": "esp8266ex",
+    "productModel": "skyv2",
+    "configGroup": "flash_ok",
+    "currentlyAvailableFirmwareVersion": "SKY30047",
+    "cleanFiltersNotificationEnabled": false,
+    "shouldShowFilterCleaningNotification": false,
+    "isGeofenceOnExitEnabled": false,
+    "isClimateReactGeofenceOnExitEnabled": false,
+    "isMotionGeofenceOnExitEnabled": false,
+    "isCalibrating": false,
+    "serial": "522101087",
+    "sensorsCalibration": {
+      "temperature": 0.0,
+      "humidity": 0.0
+    },
+    "motionSensors": [],
+    "tags": [],
+    "schedules": [],
+    "filtersCleaning": {
+      "acOnSecondsSinceLastFiltersClean": 17981666,
+      "filtersCleanSecondsThreshold": 1080000,
+      "shouldCleanFilters": true
+    },
+    "serviceSubscriptions": [],
+    "warrantyEligible": "no",
+    "warrantyEligibleUntil": {
+      "time": "2022-10-04T16:05:11Z",
+      "secondsAgo": 55719117
+    },
+    "features": [
+      "optimusTrial",
+      "showPlus"
+    ],
+    "homekitSupported": false,
+    "remoteCapabilities": {
+      "modes": {
+        "cool": {
+          "temperatures": {
+            "F": {
+              "isNative": false,
+              "values": [
+                61,
+                63,
+                64,
+                66,
+                68,
+                70,
+                72,
+                73,
+                75,
+                77,
+                79,
+                81,
+                82,
+                84,
+                86
+              ]
+            },
+            "C": {
+              "isNative": true,
+              "values": [
+                16,
+                17,
+                18,
+                19,
+                20,
+                21,
+                22,
+                23,
+                24,
+                25,
+                26,
+                27,
+                28,
+                29,
+                30
+              ]
+            }
+          },
+          "fanLevels": [
+            "quiet",
+            "low",
+            "medium_low",
+            "medium",
+            "high",
+            "auto",
+            "strong"
+          ],
+          "swing": [
+            "stopped",
+            "rangeFull"
+          ],
+          "horizontalSwing": [
+            "stopped",
+            "rangeFull"
+          ]
+        },
+        "heat": {
+          "temperatures": {
+            "F": {
+              "isNative": false,
+              "values": [
+                46,
+                48,
+                50,
+                52,
+                54,
+                55,
+                57,
+                59,
+                61,
+                63,
+                64,
+                66,
+                68,
+                70,
+                72,
+                73,
+                75,
+                77,
+                79,
+                81,
+                82,
+                84,
+                86
+              ]
+            },
+            "C": {
+              "isNative": true,
+              "values": [
+                8,
+                9,
+                10,
+                11,
+                12,
+                13,
+                14,
+                15,
+                16,
+                17,
+                18,
+                19,
+                20,
+                21,
+                22,
+                23,
+                24,
+                25,
+                26,
+                27,
+                28,
+                29,
+                30
+              ]
+            }
+          },
+          "fanLevels": [
+            "quiet",
+            "low",
+            "medium_low",
+            "medium",
+            "high",
+            "auto",
+            "strong"
+          ],
+          "swing": [
+            "stopped",
+            "rangeFull"
+          ],
+          "horizontalSwing": [
+            "stopped",
+            "rangeFull"
+          ]
+        },
+        "fan": {
+          "temperatures": {},
+          "fanLevels": [
+            "quiet",
+            "low",
+            "medium_low",
+            "medium",
+            "high",
+            "auto",
+            "strong"
+          ],
+          "swing": [
+            "stopped",
+            "rangeFull"
+          ],
+          "horizontalSwing": [
+            "stopped",
+            "rangeFull"
+          ]
+        },
+        "dry": {
+          "temperatures": {
+            "F": {
+              "isNative": false,
+              "values": [
+                61,
+                63,
+                64,
+                66,
+                68,
+                70,
+                72,
+                73,
+                75,
+                77,
+                79,
+                81,
+                82,
+                84,
+                86
+              ]
+            },
+            "C": {
+              "isNative": true,
+              "values": [
+                16,
+                17,
+                18,
+                19,
+                20,
+                21,
+                22,
+                23,
+                24,
+                25,
+                26,
+                27,
+                28,
+                29,
+                30
+              ]
+            }
+          },
+          "swing": [
+            "stopped",
+            "rangeFull"
+          ],
+          "horizontalSwing": [
+            "stopped",
+            "rangeFull"
+          ]
+        },
+        "auto": {
+          "temperatures": {
+            "F": {
+              "isNative": false,
+              "values": [
+                61,
+                63,
+                64,
+                66,
+                68,
+                70,
+                72,
+                73,
+                75,
+                77,
+                79,
+                81,
+                82,
+                84,
+                86
+              ]
+            },
+            "C": {
+              "isNative": true,
+              "values": [
+                16,
+                17,
+                18,
+                19,
+                20,
+                21,
+                22,
+                23,
+                24,
+                25,
+                26,
+                27,
+                28,
+                29,
+                30
+              ]
+            }
+          },
+          "swing": [
+            "stopped",
+            "rangeFull"
+          ],
+          "horizontalSwing": [
+            "stopped",
+            "rangeFull"
+          ]
+        }
+      }
+    },
+    "remote": {
+      "toggle": false,
+      "window": false
+    },
+    "remoteFlavor": "Cheerful Orca",
+    "remoteAlternatives": [
+      "_samsung2b_different_quiet",
+      "samsung2b"
+    ],
+    "measurements": {
+      "time": {
+        "time": "2024-07-10T13:36:50.018202Z",
+        "secondsAgo": 18
+      },
+      "temperature": 21.1,
+      "humidity": 67,
+      "feelsLike": 21.1,
+      "rssi": -56
+    },
+    "accessPoint": {
+      "ssid": "SENSIBO-I-IDIDIDIDI"
+    },
+    "macAddress": "BC:FF:AA:AA:AA:AA",
+    "autoOffEnabled": false,
+    "optimusEnabled": true,
+    "optimusInsights": {
+      "Progress": {
+        "name": "Progress",
+        "start_time": "2024-07-10T09:29:38",
+        "data": {
+          "Percentage": 0.0
+        }
+      }
+    },
+    "hasPolicy": false
+  }
+}