]> git.basschouten.com Git - openhab-addons.git/blob
7a39a93ed3e5ffdc32742de46a8f3c3a0536ca07
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.gardena.internal.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.apache.commons.lang.builder.EqualsBuilder;
19 import org.apache.commons.lang.builder.HashCodeBuilder;
20 import org.openhab.binding.gardena.internal.exception.GardenaException;
21
22 import com.google.gson.annotations.SerializedName;
23
24 /**
25  * Represents a Gardena device.
26  *
27  * @author Gerhard Riegler - Initial contribution
28  */
29 public class Device {
30
31     private String id;
32     private String name;
33     private String description;
34     private String category;
35     @SerializedName("configuration_synchronized")
36     private boolean configurationSynchronized;
37     private List<Ability> abilities = new ArrayList<>();
38     @SerializedName("scheduled_events")
39     private List<ScheduledEvent> scheduledEvents = new ArrayList<>();
40     private transient Location location;
41     private List<Setting> settings = new ArrayList<>();
42
43     /**
44      * Returns the id of the device.
45      */
46     public String getId() {
47         return id;
48     }
49
50     /**
51      * Returns the name of the device.
52      */
53     public String getName() {
54         return name;
55     }
56
57     /**
58      * Returns the description of the device.
59      */
60     public String getDescription() {
61         return description;
62     }
63
64     /**
65      * Returns the category of the device.
66      */
67     public String getCategory() {
68         return category;
69     }
70
71     /**
72      * Returns true, if all configurations are synchronized.
73      */
74     public boolean isConfigurationSynchronized() {
75         return configurationSynchronized;
76     }
77
78     /**
79      * Returns a list of abilities of the device.
80      */
81     public List<Ability> getAbilities() {
82         return abilities;
83     }
84
85     /**
86      * Returns a list of scheduled events of the device.
87      */
88     public List<ScheduledEvent> getScheduledEvents() {
89         return scheduledEvents;
90     }
91
92     /**
93      * Returns the location of the device.
94      */
95     public Location getLocation() {
96         return location;
97     }
98
99     /**
100      * Sets the location of the device.
101      */
102     public void setLocation(Location location) {
103         this.location = location;
104     }
105
106     /**
107      * Returns the ability with the specified name.
108      */
109     public Ability getAbility(String name) throws GardenaException {
110         for (Ability ability : abilities) {
111             if (ability.getName().equals(name)) {
112                 return ability;
113             }
114         }
115         throw new GardenaException("Ability '" + name + "' not found in device '" + this.name + "'");
116     }
117
118     public List<Setting> getSettings() {
119         return settings;
120     }
121
122     /**
123      * Returns the setting with the specified name.
124      */
125     public Setting getSetting(String name) throws GardenaException {
126         for (Setting setting : settings) {
127             if (setting.getName().equals(name)) {
128                 return setting;
129             }
130         }
131         throw new GardenaException("Setting '" + name + "' not found in device '" + this.name + "'");
132     }
133
134     @Override
135     public int hashCode() {
136         return new HashCodeBuilder().append(id).toHashCode();
137     }
138
139     @Override
140     public boolean equals(Object obj) {
141         if (obj == null || !(obj instanceof Device)) {
142             return false;
143         }
144         Device comp = (Device) obj;
145         return new EqualsBuilder().append(comp.getId(), id).isEquals();
146     }
147 }