| 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
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;
private @Nullable String primaryMacAddress;
private @Nullable String wifiMacAddress;
private @Nullable String deviceType;
- private @Nullable String controllerId;
private ArrayList<String> relays = new ArrayList<>();
@SuppressWarnings("null")
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));
}
}
}
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);
- }
}
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 {
}
}
- 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);
}
}
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"));
public void testControllerIdIsNull() {
DoorbirdInfo info = new DoorbirdInfo(infoWithoutControllerId);
- assertNull(info.getControllerId());
+ assertNull(info.getControllerId(null));
}
}