diff --git a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/CallbackChannelsTypeProvider.java b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/CallbackChannelsTypeProvider.java index e9bd52b2067..61819bb06ad 100644 --- a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/CallbackChannelsTypeProvider.java +++ b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/CallbackChannelsTypeProvider.java @@ -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 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 diff --git a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java index 6668a8019df..9de972e5010 100644 --- a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java +++ b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java @@ -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 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) { diff --git a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/model/SensiboModel.java b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/model/SensiboModel.java index 2f211b17c2d..45375bcee03 100644 --- a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/model/SensiboModel.java +++ b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/model/SensiboModel.java @@ -46,7 +46,7 @@ public class SensiboModel { public Optional 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 index 00000000000..6c538b80b57 --- /dev/null +++ b/bundles/org.openhab.binding.sensibo/src/test/java/org/openhab/binding/sensibo/internal/SensiboModelTest.java @@ -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()); + } +} diff --git a/bundles/org.openhab.binding.sensibo/src/test/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandlerTest.java b/bundles/org.openhab.binding.sensibo/src/test/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandlerTest.java index 9cd95149aa3..0117107cfad 100644 --- a/bundles/org.openhab.binding.sensibo/src/test/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandlerTest.java +++ b/bundles/org.openhab.binding.sensibo/src/test/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandlerTest.java @@ -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 index 00000000000..1a4c2a6ebc3 --- /dev/null +++ b/bundles/org.openhab.binding.sensibo/src/test/resources/get_pod_details_response_valter.json @@ -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 + } +}