]> git.basschouten.com Git - openhab-addons.git/blob
5cb25a8aab0b4ae63cbc7dbc0d71a4dec9532dc7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.hdpowerview.internal.api.responses;
14
15 import java.nio.charset.StandardCharsets;
16 import java.util.Base64;
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21
22 /**
23  * State of all Scenes in an HD PowerView hub
24  *
25  * @author Andy Lintner - Initial contribution
26  */
27 @NonNullByDefault
28 public class Scenes {
29
30     public @Nullable List<Scene> sceneData;
31     public @Nullable List<Integer> sceneIds;
32
33     /*
34      * the following SuppressWarnings annotation is because the Eclipse compiler
35      * does NOT expect a NonNullByDefault annotation on the inner class, since it is
36      * implicitly inherited from the outer class, whereas the Maven compiler always
37      * requires an explicit NonNullByDefault annotation on all classes
38      */
39     @SuppressWarnings("null")
40     @NonNullByDefault
41     public static class Scene implements Comparable<Scene> {
42         public int id;
43         public @Nullable String name;
44         public int roomId;
45         public int order;
46         public int colorId;
47         public int iconId;
48
49         @Override
50         public boolean equals(@Nullable Object o) {
51             if (o == this) {
52                 return true;
53             }
54             if (!(o instanceof Scene)) {
55                 return false;
56             }
57             Scene other = (Scene) o;
58
59             return this.id == other.id && this.name.equals(other.name) && this.roomId == other.roomId
60                     && this.order == other.order && this.colorId == other.colorId && this.iconId == other.iconId;
61         }
62
63         @Override
64         public final int hashCode() {
65             final int prime = 31;
66             int result = 1;
67             result = prime * result + id;
68             result = prime * result + (name == null ? 0 : name.hashCode());
69             result = prime * result + roomId;
70             result = prime * result + order;
71             result = prime * result + colorId;
72             result = prime * result + iconId;
73
74             return result;
75         }
76
77         @Override
78         public int compareTo(Scene other) {
79             return Integer.compare(order, other.order);
80         }
81
82         public String getName() {
83             return new String(Base64.getDecoder().decode(name), StandardCharsets.UTF_8);
84         }
85     }
86 }