[sensibo] Fix channel provider throwing exception (#17030)

* Fix channel provider throwing exception
* Add case insensitive mac address comparison

Signed-off-by: Arne Seime <arne.seime@gmail.com>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Arne Seime 2024-07-16 18:40:17 +02:00 committed by Ciprian Pascu
parent 5e51d93c30
commit c1dc512dfe
6 changed files with 470 additions and 5 deletions

View 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

View 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) {

View 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();
}
/**

View File

@ -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());
}
}

View 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);

View File

@ -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
}
}