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