2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.loxone.internal.controls;
15 import java.io.IOException;
17 import org.openhab.binding.loxone.internal.types.LxUuid;
18 import org.openhab.core.library.types.OnOffType;
20 import com.google.gson.annotations.SerializedName;
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
26 * A mood is deserialized using a default gson, not like {@link LxControl} which has a proprietary deserialization
29 * @author Pawel Pieczul - initial contribution
32 class LxControlMood extends LxControlSwitch {
35 * An ID that uniquely identifies this mood (e.g. inside activeMoods)
38 private Integer moodId;
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.
44 * 1: this mood is activated by a movement event
45 * 2: a T5 or other inputs activate/deactivate this mood
47 @SerializedName("used")
48 private Integer isUsed;
51 * Whether or not this mood can be controlled with a t5 input
54 private Boolean isT5Controlled;
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.
60 @SerializedName("static")
61 private Boolean isStatic;
63 private LxControlLightControllerV2 controller;
66 * This constructor will be called by the default JSON deserialization
73 public void initialize(LxControlConfig config) {
74 super.initialize(config);
77 public void initialize(LxControlConfig config, LxControlLightControllerV2 controller, LxUuid 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) {
93 return "Mood / " + super.getLabel();
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.
107 * Mix the mood into active moods.
109 * @throws IOException when something went wrong with communication
112 void on() throws IOException {
113 if (controller != null) {
114 controller.addMood(moodId);
119 * Mix the mood out of active moods.
121 * @throws IOException when something went wrong with communication
124 void off() throws IOException {
125 if (controller != null) {
126 controller.removeMood(moodId);
131 * Return whether the mood is active of not.
133 * @return 1 if mood is active and 0 otherwise
136 OnOffType getSwitchState() {
137 if (controller != null && controller.isMoodOk(moodId)) {
138 if (controller.isMoodActive(moodId)) {
141 return OnOffType.OFF;