]> git.basschouten.com Git - openhab-addons.git/blob
f15eb995f24d5b6c2a8043fda80ad4ef01775e6e
[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.hue.internal.dto;
14
15 import java.util.List;
16 import java.util.stream.Collectors;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  *
23  * @author Q42 - Initial contribution
24  * @author Denis Dudnik - moved Jue library source code inside the smarthome Hue binding
25  */
26 @SuppressWarnings("unused")
27 @NonNullByDefault
28 public class SetAttributesRequest {
29     private final @Nullable String name;
30     private final @Nullable List<String> lights;
31
32     public SetAttributesRequest(String name) {
33         this(name, null);
34     }
35
36     public SetAttributesRequest(List<HueObject> lights) {
37         this(null, lights);
38     }
39
40     public SetAttributesRequest(@Nullable String name, @Nullable List<HueObject> lights) {
41         if (name != null && Util.stringSize(name) > 32) {
42             throw new IllegalArgumentException("Name can be at most 32 characters long");
43         } else if (lights != null && (lights.isEmpty() || lights.size() > 16)) {
44             throw new IllegalArgumentException("Group cannot be empty and cannot have more than 16 lights");
45         }
46
47         this.name = name;
48         this.lights = lights == null ? null : lights.stream().map(l -> l.getId()).collect(Collectors.toList());
49     }
50 }