]> git.basschouten.com Git - openhab-addons.git/blob
54a3df891706f6d010485858920bd525054f7af9
[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.innogysmarthome.internal.client.entity.device;
14
15 import java.util.HashMap;
16
17 import org.openhab.binding.innogysmarthome.internal.client.entity.Property;
18
19 /**
20  * Defines the {@link DeviceState}, e.g. if the device is reachable.
21  *
22  * @author Oliver Kuhl - Initial contribution
23  */
24 public class DeviceState {
25
26     protected static final String DEVICE_INCLUSION_STATE_INCLUDED = "Included";
27     protected static final String DEVICE_INCLUSION_STATE_PENDING = "InclusionPending";
28     protected static final String DEVICE_UPDATE_STATE_UPTODATE = "UpToDate";
29
30     protected static final String PROTOCOL_ID_WMBUS = "wMBus";
31     protected static final String PROTOCOL_ID_VIRTUAL = "Virtual";
32     protected static final String PROTOCOL_ID_COSIP = "Cosip";
33
34     private String id;
35
36     private State state;
37
38     private HashMap<String, Property> stateMap;
39
40     /**
41      * @return the id
42      */
43     public String getId() {
44         return id;
45     }
46
47     /**
48      * @param id the id to set
49      */
50     public void setId(String id) {
51         this.id = id;
52     }
53
54     /**
55      * @return the state
56      */
57     public State getState() {
58         return state;
59     }
60
61     /**
62      * @param state the state to set
63      */
64     public void setState(State state) {
65         this.state = state;
66     }
67
68     /**
69      * Returns true if the device is reachable, false otherwise.
70      *
71      * @return true or false for "reachable" {@link Device}s, else null.
72      */
73     public Boolean isReachable() {
74         return getState().getIsReachable().getValue();
75     }
76
77     /**
78      * Returns if the {@link State} "isReachable" is available for the current {@link Device}.
79      *
80      * @return
81      */
82     public Boolean hasIsReachableState() {
83         return getState().getIsReachable() != null;
84     }
85
86     /**
87      * Sets if the {@link Device} is reachable.
88      *
89      * @param isReachable
90      */
91     public void setReachable(boolean isReachable) {
92         getState().getIsReachable().setValue(isReachable);
93     }
94
95     /**
96      * Returns the configuration state of the device.
97      *
98      * @return the configuration state
99      */
100     public String getDeviceConfigurationState() {
101         return getState().getDeviceConfigurationState().getValue();
102     }
103
104     /**
105      * Returns the device inclusion state.
106      *
107      * @return the device inclusion state
108      */
109     public String getDeviceInclusionState() {
110         return getState().getDeviceInclusionState().getValue();
111     }
112
113     /**
114      * Returns true, if the device is included.
115      *
116      * @return true, if the {@link Device} is "Included"
117      */
118     public boolean deviceIsIncluded() {
119         return DEVICE_INCLUSION_STATE_INCLUDED.equals(getState().getDeviceInclusionState().getValue());
120     }
121
122     /**
123      * @return the stateMap
124      */
125     public HashMap<String, Property> getStateMap() {
126         return stateMap;
127     }
128
129     /**
130      * @param stateMap the stateMap to set
131      */
132     public void setStateMap(HashMap<String, Property> stateMap) {
133         this.stateMap = stateMap;
134     }
135
136     /**
137      * Returns true, if the device inclusion state is "InclusionPending".
138      *
139      * @return true, if the inclusion state is "InclusionPending"
140      */
141     public Boolean deviceInclusionIsPending() {
142         return DEVICE_INCLUSION_STATE_PENDING.equals(getDeviceInclusionState());
143     }
144
145     /**
146      * Return the update state of the {@link Device}.
147      *
148      * @return the update state
149      */
150     public String getDeviceUpdateState() {
151         return getState().getUpdateState().getValue();
152     }
153
154     /**
155      * Returns true if the {@link Device} is up to date.
156      *
157      * @return true, if the deviceUpdateState is "UpToDate"
158      */
159     public Boolean deviceIsUpToDate() {
160         return DEVICE_UPDATE_STATE_UPTODATE.equals(getDeviceUpdateState());
161     }
162
163     /**
164      * Returns the firmware version of the {@link Device}.
165      *
166      * @return the firmware version
167      */
168     public String getFirmwareVersion() {
169         return getState().getFirmwareVersion().getValue();
170     }
171 }