[doorbird] fix controller id (#11190)

Signed-off-by: True Random <rantruedom@gmail.com>
This commit is contained in:
TheTrueRandom 2021-09-07 22:48:33 +02:00 committed by GitHub
parent 12fba3a5ee
commit 0a1f23f98d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 19 deletions

View File

@ -38,6 +38,7 @@ The following configuration parameters are available on the Doorbird A1081 Contr
| Hostname | doorbirdHost | Required | The hostname or IP address of the Doorbird device. |
| User ID | userId | Required | User Id of a Doorbird user that has permissions to access the API. The User ID and Password must be created using the Doorbird smart phone application. |
| Password | userPassword | Required | Password of a Doorbird user. |
| Controller Id | controllerId | Optional | Doorbird Id of the controller to reliable target the relays of this device. E.g. "gggaaa" |
## Discovery

View File

@ -13,6 +13,7 @@
package org.openhab.binding.doorbird.internal.api;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -35,7 +36,6 @@ public class DoorbirdInfo {
private @Nullable String primaryMacAddress;
private @Nullable String wifiMacAddress;
private @Nullable String deviceType;
private @Nullable String controllerId;
private ArrayList<String> relays = new ArrayList<>();
@SuppressWarnings("null")
@ -51,13 +51,7 @@ public class DoorbirdInfo {
primaryMacAddress = doorbirdInfo.primaryMacAddress;
wifiMacAddress = doorbirdInfo.wifiMacAddress;
deviceType = doorbirdInfo.deviceType;
for (String relay : doorbirdInfo.relays) {
relays.add(relay);
String[] parts = relay.split("@");
if (parts.length == 2) {
controllerId = parts[0];
}
}
relays.addAll(Arrays.asList(doorbirdInfo.relays));
}
}
}
@ -86,15 +80,12 @@ public class DoorbirdInfo {
return deviceType;
}
public @Nullable String getControllerId() {
return controllerId;
public @Nullable String getControllerId(@Nullable String configId) {
return relays.stream().map(relay -> relay.split("@")).filter(parts -> parts.length == 2).map(parts -> parts[0])
.filter(id -> configId == null || id.equals(configId)).reduce((first, second) -> second).orElse(null);
}
public ArrayList<String> getRelays() {
return relays;
}
public void addRelay(String relay) {
relays.add(relay);
}
}

View File

@ -37,4 +37,9 @@ public class ControllerConfiguration {
* Password of the Doorbird doorbell to which the controller is assigned
*/
public @Nullable String userPassword;
/**
* Id of the Doorbird device
*/
public @Nullable String controllerId;
}

View File

@ -68,7 +68,7 @@ public class ControllerHandler extends BaseThingHandler {
api.setAuthorization(host, user, password);
// Get the Id of the controller for use in the open door API
controllerId = getControllerId();
controllerId = getControllerId(config.controllerId);
if (controllerId != null) {
updateStatus(ThingStatus.ONLINE);
} else {
@ -105,8 +105,8 @@ public class ControllerHandler extends BaseThingHandler {
}
}
private @Nullable String getControllerId() {
private @Nullable String getControllerId(@Nullable String configId) {
DoorbirdInfo info = api.getDoorbirdInfo();
return info == null ? null : info.getControllerId();
return info == null ? null : info.getControllerId(configId);
}
}

View File

@ -81,7 +81,7 @@ public class DoorbirdInfoTest {
public void testGetControllerId() {
DoorbirdInfo info = new DoorbirdInfo(infoWithControllerId);
assertEquals("gggaaa", info.getControllerId());
assertEquals("gggaaa", info.getControllerId(null));
assertTrue(info.getRelays().contains("gggaaa@1"));
assertTrue(info.getRelays().contains("gggaaa@2"));
@ -92,6 +92,6 @@ public class DoorbirdInfoTest {
public void testControllerIdIsNull() {
DoorbirdInfo info = new DoorbirdInfo(infoWithoutControllerId);
assertNull(info.getControllerId());
assertNull(info.getControllerId(null));
}
}