]> git.basschouten.com Git - openhab-addons.git/blob
14325962e08d3fd986bda5b94114f0d9339ae910
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.loxone.internal.types;
14
15 import org.openhab.binding.loxone.internal.controls.LxControl;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * A state of a Loxone control ({@link LxControl})
21  * <p>
22  * Each control object may have a number of states defined, that describe the overall condition of the control.
23  * List of states is read from LoxApp3.json configuration file.
24  * <p>
25  * Each state is identified by its own UUID and a name of the state. Names are proprietary to a particular type of the
26  * control and as such are defined in {@link LxControl} child classes implementation.
27  * Objects of this class are used to bind state updates received from the Miniserver to a control object.
28  *
29  * @author Pawel Pieczul - initial contribution
30  *
31  */
32 public class LxState {
33     private final LxUuid uuid;
34     private final String name;
35     private final LxControl control;
36     private final Logger logger = LoggerFactory.getLogger(LxState.class);
37     private Object stateValue;
38
39     /**
40      * Create a control state object.
41      *
42      * @param uuid UUID of the state
43      * @param name name of the state
44      * @param control control to which this state belongs
45      */
46     public LxState(LxUuid uuid, String name, LxControl control) {
47         this.uuid = uuid;
48         this.name = name;
49         this.control = control;
50     }
51
52     /**
53      * Gets UUID of the state
54      *
55      * @return state's UUID
56      */
57     public LxUuid getUuid() {
58         return uuid;
59     }
60
61     /**
62      * Sets current value of the control's state
63      *
64      * @param value current state's value to set
65      */
66     public void setStateValue(Object value) {
67         logger.debug("State set ({},{}) control ({},{}) value={}", uuid, name, control.getUuid(), control.getName(),
68                 value);
69         if (value != null && !value.equals(this.stateValue)) {
70             this.stateValue = value;
71             control.onStateChange(this);
72         }
73     }
74
75     /**
76      * Gets current value of the control's state
77      *
78      * @return current state's value
79      */
80     public Object getStateValue() {
81         return stateValue;
82     }
83
84     /**
85      * Gets state's name.
86      * <p>
87      * State's name is proprietary per control type.
88      *
89      * @return state's name
90      */
91     public String getName() {
92         return name;
93     }
94 }