]> git.basschouten.com Git - openhab-addons.git/blob
50d9bc5b2c352b706c55b6f4df9ebcfff4b302d9
[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.loxone.internal.controls;
14
15 import java.io.IOException;
16
17 import org.openhab.binding.loxone.internal.types.LxUuid;
18 import org.openhab.core.library.types.OnOffType;
19
20 import com.google.gson.annotations.SerializedName;
21
22 /**
23  * This class represents a mood belonging to a {@link LxControlMood} object.
24  * A mood is effectively a switch. When the switch is set to ON, mood is active and mixed into a set of active
25  * moods.
26  * A mood is deserialized using a default gson, not like {@link LxControl} which has a proprietary deserialization
27  * method.
28  *
29  * @author Pawel Pieczul - initial contribution
30  *
31  */
32 class LxControlMood extends LxControlSwitch {
33
34     /**
35      * An ID that uniquely identifies this mood (e.g. inside activeMoods)
36      */
37     @SerializedName("id")
38     private Integer moodId;
39
40     /**
41      * Bitmask that tells if the mood is used for a specific purpose in the logic.
42      * If it’s not used, it can be removed without affecting the logic on the Miniserver.
43      * 0: not used
44      * 1: this mood is activated by a movement event
45      * 2: a T5 or other inputs activate/deactivate this mood
46      */
47     @SerializedName("used")
48     private Integer isUsed;
49
50     /**
51      * Whether or not this mood can be controlled with a t5 input
52      */
53     @SerializedName("t5")
54     private Boolean isT5Controlled;
55
56     /**
57      * If a mood is marked as static it cannot be deleted or modified in any way.
58      * But it can be moved within and between favorite and additional lists.
59      */
60     @SerializedName("static")
61     private Boolean isStatic;
62
63     private LxControlLightControllerV2 controller;
64
65     /**
66      * This constructor will be called by the default JSON deserialization
67      */
68     LxControlMood() {
69         super(null);
70     }
71
72     @Override
73     public void initialize(LxControlConfig config) {
74         super.initialize(config);
75     }
76
77     public void initialize(LxControlConfig config, LxControlLightControllerV2 controller, LxUuid uuid) {
78         this.uuid = uuid;
79         this.controller = controller;
80         super.initialize(config);
81         // the 'all off' mood can't be operated as a switch, but needs to be present on the moods list for the
82         // lighting controller
83         // currently the API does not give a hint how to figure out the 'all off' mood
84         // empirically this is the only mood that is not editable by the user and has a static flag set on
85         // we will assume that the only static mood is 'all off' mood
86         if (isStatic != null && isStatic) {
87             removeAllChannels();
88         }
89     }
90
91     @Override
92     String getLabel() {
93         return "Mood / " + super.getLabel();
94     }
95
96     /**
97      * Get an ID of this mood. ID identifies the mood within a light controller.
98      * It is equal to the mood ID received from the Miniserver.
99      *
100      * @return mood ID
101      */
102     Integer getId() {
103         return moodId;
104     }
105
106     /**
107      * Mix the mood into active moods.
108      *
109      * @throws IOException when something went wrong with communication
110      */
111     @Override
112     void on() throws IOException {
113         if (controller != null) {
114             controller.addMood(moodId);
115         }
116     }
117
118     /**
119      * Mix the mood out of active moods.
120      *
121      * @throws IOException when something went wrong with communication
122      */
123     @Override
124     void off() throws IOException {
125         if (controller != null) {
126             controller.removeMood(moodId);
127         }
128     }
129
130     /**
131      * Return whether the mood is active of not.
132      *
133      * @return 1 if mood is active and 0 otherwise
134      */
135     @Override
136     OnOffType getSwitchState() {
137         if (controller != null && controller.isMoodOk(moodId)) {
138             if (controller.isMoodActive(moodId)) {
139                 return OnOffType.ON;
140             }
141             return OnOffType.OFF;
142         }
143         return null;
144     }
145 }