[doorbird] fix controller id (#11190)
Signed-off-by: True Random <rantruedom@gmail.com>
This commit is contained in:
parent
12fba3a5ee
commit
0a1f23f98d
|
@ -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. |
|
| 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. |
|
| 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. |
|
| 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
|
## Discovery
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
package org.openhab.binding.doorbird.internal.api;
|
package org.openhab.binding.doorbird.internal.api;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
@ -35,7 +36,6 @@ public class DoorbirdInfo {
|
||||||
private @Nullable String primaryMacAddress;
|
private @Nullable String primaryMacAddress;
|
||||||
private @Nullable String wifiMacAddress;
|
private @Nullable String wifiMacAddress;
|
||||||
private @Nullable String deviceType;
|
private @Nullable String deviceType;
|
||||||
private @Nullable String controllerId;
|
|
||||||
private ArrayList<String> relays = new ArrayList<>();
|
private ArrayList<String> relays = new ArrayList<>();
|
||||||
|
|
||||||
@SuppressWarnings("null")
|
@SuppressWarnings("null")
|
||||||
|
@ -51,13 +51,7 @@ public class DoorbirdInfo {
|
||||||
primaryMacAddress = doorbirdInfo.primaryMacAddress;
|
primaryMacAddress = doorbirdInfo.primaryMacAddress;
|
||||||
wifiMacAddress = doorbirdInfo.wifiMacAddress;
|
wifiMacAddress = doorbirdInfo.wifiMacAddress;
|
||||||
deviceType = doorbirdInfo.deviceType;
|
deviceType = doorbirdInfo.deviceType;
|
||||||
for (String relay : doorbirdInfo.relays) {
|
relays.addAll(Arrays.asList(doorbirdInfo.relays));
|
||||||
relays.add(relay);
|
|
||||||
String[] parts = relay.split("@");
|
|
||||||
if (parts.length == 2) {
|
|
||||||
controllerId = parts[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,15 +80,12 @@ public class DoorbirdInfo {
|
||||||
return deviceType;
|
return deviceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable String getControllerId() {
|
public @Nullable String getControllerId(@Nullable String configId) {
|
||||||
return controllerId;
|
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() {
|
public ArrayList<String> getRelays() {
|
||||||
return relays;
|
return relays;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRelay(String relay) {
|
|
||||||
relays.add(relay);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,4 +37,9 @@ public class ControllerConfiguration {
|
||||||
* Password of the Doorbird doorbell to which the controller is assigned
|
* Password of the Doorbird doorbell to which the controller is assigned
|
||||||
*/
|
*/
|
||||||
public @Nullable String userPassword;
|
public @Nullable String userPassword;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Id of the Doorbird device
|
||||||
|
*/
|
||||||
|
public @Nullable String controllerId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class ControllerHandler extends BaseThingHandler {
|
||||||
api.setAuthorization(host, user, password);
|
api.setAuthorization(host, user, password);
|
||||||
|
|
||||||
// Get the Id of the controller for use in the open door API
|
// Get the Id of the controller for use in the open door API
|
||||||
controllerId = getControllerId();
|
controllerId = getControllerId(config.controllerId);
|
||||||
if (controllerId != null) {
|
if (controllerId != null) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
} else {
|
} 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();
|
DoorbirdInfo info = api.getDoorbirdInfo();
|
||||||
return info == null ? null : info.getControllerId();
|
return info == null ? null : info.getControllerId(configId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class DoorbirdInfoTest {
|
||||||
public void testGetControllerId() {
|
public void testGetControllerId() {
|
||||||
DoorbirdInfo info = new DoorbirdInfo(infoWithControllerId);
|
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@1"));
|
||||||
assertTrue(info.getRelays().contains("gggaaa@2"));
|
assertTrue(info.getRelays().contains("gggaaa@2"));
|
||||||
|
@ -92,6 +92,6 @@ public class DoorbirdInfoTest {
|
||||||
public void testControllerIdIsNull() {
|
public void testControllerIdIsNull() {
|
||||||
DoorbirdInfo info = new DoorbirdInfo(infoWithoutControllerId);
|
DoorbirdInfo info = new DoorbirdInfo(infoWithoutControllerId);
|
||||||
|
|
||||||
assertNull(info.getControllerId());
|
assertNull(info.getControllerId(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue