]> git.basschouten.com Git - openhab-addons.git/blob
2112bed716db11e5b35bf49aea20f21e570f694e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.nuki.internal.dataexchange;
14
15 import java.util.Collections;
16 import java.util.List;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.nuki.internal.dto.BridgeApiListDeviceDto;
21
22 /**
23  * The {@link BridgeListResponse} class wraps {@link BridgeApiListDeviceDto} class.
24  *
25  * @author Jan Vybíral - Initial contribution
26  */
27 @NonNullByDefault
28 public class BridgeListResponse extends NukiBaseResponse {
29
30     private final List<BridgeApiListDeviceDto> devices;
31
32     public BridgeListResponse(int status, @Nullable String message, @Nullable List<BridgeApiListDeviceDto> devices) {
33         super(status, message);
34         setSuccess(devices != null);
35         this.devices = devices == null ? Collections.emptyList() : Collections.unmodifiableList(devices);
36     }
37
38     public BridgeListResponse(NukiBaseResponse nukiBaseResponse) {
39         this(nukiBaseResponse.getStatus(), nukiBaseResponse.getMessage(), null);
40     }
41
42     public List<BridgeApiListDeviceDto> getDevices() {
43         return devices;
44     }
45
46     public @Nullable BridgeApiListDeviceDto getDevice(String nukiId) {
47         for (BridgeApiListDeviceDto device : this.devices) {
48             if (device.getNukiId().equals(nukiId)) {
49                 return device;
50             }
51         }
52         return null;
53     }
54 }