]> git.basschouten.com Git - openhab-addons.git/blob
d3f942ef7c3d371ab19e1da7091582f5af24355d
[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.openhab.binding.gardena.internal.exception.GardenaException;
19
20 /**
21  * Represents a Gardena ability.
22  *
23  * @author Gerhard Riegler - Initial contribution
24  */
25 public class Ability {
26
27     private String name;
28     private String type;
29     private transient Device device;
30
31     private List<Property> properties = new ArrayList<>();
32
33     /**
34      * Returns the name of the ability.
35      */
36     public String getName() {
37         return name;
38     }
39
40     /**
41      * Returns the type of the ability.
42      */
43     public String getType() {
44         return type;
45     }
46
47     /**
48      * Returns a list of properties of the ability.
49      */
50     public List<Property> getProperties() {
51         return properties;
52     }
53
54     /**
55      * Adds a property to this ability.
56      */
57     public void addProperty(Property property) {
58         property.setAbility(this);
59         properties.add(property);
60     }
61
62     /**
63      * Returns the property with the specified name.
64      */
65     public Property getProperty(String name) throws GardenaException {
66         for (Property property : properties) {
67             if (property.getName().equals(name)) {
68                 return property;
69             }
70         }
71         throw new GardenaException("Property '" + name + "' not found in ability '" + this.name + "'");
72     }
73
74     /**
75      * Returns the device of the ability.
76      */
77     public Device getDevice() {
78         return device;
79     }
80
81     /**
82      * Sets the name of the ability.
83      */
84     public void setDevice(Device device) {
85         this.device = device;
86     }
87 }