2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.gardena.internal.model;
15 import java.util.ArrayList;
16 import java.util.List;
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;
22 import com.google.gson.annotations.SerializedName;
25 * Represents a Gardena device.
27 * @author Gerhard Riegler - Initial contribution
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<>();
44 * Returns the id of the device.
46 public String getId() {
51 * Returns the name of the device.
53 public String getName() {
58 * Returns the description of the device.
60 public String getDescription() {
65 * Returns the category of the device.
67 public String getCategory() {
72 * Returns true, if all configurations are synchronized.
74 public boolean isConfigurationSynchronized() {
75 return configurationSynchronized;
79 * Returns a list of abilities of the device.
81 public List<Ability> getAbilities() {
86 * Returns a list of scheduled events of the device.
88 public List<ScheduledEvent> getScheduledEvents() {
89 return scheduledEvents;
93 * Returns the location of the device.
95 public Location getLocation() {
100 * Sets the location of the device.
102 public void setLocation(Location location) {
103 this.location = location;
107 * Returns the ability with the specified name.
109 public Ability getAbility(String name) throws GardenaException {
110 for (Ability ability : abilities) {
111 if (ability.getName().equals(name)) {
115 throw new GardenaException("Ability '" + name + "' not found in device '" + this.name + "'");
118 public List<Setting> getSettings() {
123 * Returns the setting with the specified name.
125 public Setting getSetting(String name) throws GardenaException {
126 for (Setting setting : settings) {
127 if (setting.getName().equals(name)) {
131 throw new GardenaException("Setting '" + name + "' not found in device '" + this.name + "'");
135 public int hashCode() {
136 return new HashCodeBuilder().append(id).toHashCode();
140 public boolean equals(Object obj) {
141 if (obj == null || !(obj instanceof Device)) {
144 Device comp = (Device) obj;
145 return new EqualsBuilder().append(comp.getId(), id).isEquals();