]> git.basschouten.com Git - openhab-addons.git/blob
1c8a6e1c34d7628058da7837ee11a5c9f9d113fc
[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.velux.internal.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.velux.internal.VeluxBindingProperties;
18 import org.openhab.binding.velux.internal.bridge.VeluxBridgeSetSceneVelocity;
19 import org.openhab.binding.velux.internal.handler.utils.ThingConfiguration;
20 import org.openhab.binding.velux.internal.things.VeluxScene;
21 import org.openhab.binding.velux.internal.things.VeluxScene.SceneName;
22 import org.openhab.core.library.types.OnOffType;
23 import org.openhab.core.thing.ChannelUID;
24 import org.openhab.core.types.Command;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29  * <B>Channel-specific retrieval and modification.</B>
30  * <P>
31  * This class implements the Channel <B>silentMode</B> of the Thing <B>scene</B> :
32  * <UL>
33  * <LI><I>Velux</I> <B>bridge</B> &rarr; <B>OpenHAB</B>:
34  * <P>
35  * Information retrieval by method {@link #handleRefresh}.</LI>
36  * </UL>
37  * <UL>
38  * <LI><B>OpenHAB</B> Event Bus &rarr; <I>Velux</I> <B>bridge</B>
39  * <P>
40  * Sending commands and value updates by method {@link #handleCommand}.</LI>
41  * </UL>
42  *
43  * @author Guenther Schreiner - Initial contribution.
44  */
45 @Deprecated
46 @NonNullByDefault
47 final class ChannelSceneSilentmode extends ChannelHandlerTemplate {
48     private static final Logger LOGGER = LoggerFactory.getLogger(ChannelSceneSilentmode.class);
49
50     /*
51      * ************************
52      * ***** Constructors *****
53      */
54
55     // Suppress default constructor for non-instantiability
56
57     private ChannelSceneSilentmode() {
58         throw new AssertionError();
59     }
60
61     /**
62      * Communication method to update the real world according to the passed channel value (or command).
63      *
64      * @param channelUID The item passed as type {@link ChannelUID} for which to following command is addressed to.
65      * @param channelId The same item passed as type {@link String} for which a refresh is intended.
66      * @param command The command passed as type {@link Command} for the mentioned item.
67      * @param thisBridgeHandler The Velux bridge handler with a specific communication protocol which provides
68      *            information for this channel.
69      * @return newValue ...
70      */
71     static @Nullable Command handleCommand(ChannelUID channelUID, String channelId, Command command,
72             VeluxBridgeHandler thisBridgeHandler) {
73         LOGGER.debug("handleCommand({},{},{},{}) called.", channelUID, channelId, command, thisBridgeHandler);
74         Command newValue = null;
75         do { // just for common exit
76             assert thisBridgeHandler.bridgeParameters.scenes.getChannel().existingScenes != null
77                     : "VeluxBridgeHandler.existingScenes not initialized.";
78             if (!ThingConfiguration.exists(thisBridgeHandler, channelUID, VeluxBindingProperties.PROPERTY_SCENE_NAME)) {
79                 LOGGER.trace("handleCommand(): aborting processing as scene name is not set.");
80                 break;
81             }
82             String sceneName = (String) ThingConfiguration.getValue(thisBridgeHandler, channelUID,
83                     VeluxBindingProperties.PROPERTY_SCENE_NAME);
84             if (!thisBridgeHandler.bridgeParameters.scenes.getChannel().existingScenes
85                     .isRegistered(new SceneName(sceneName))) {
86                 LOGGER.info("handleCommand({},{}): cannot modify unknown scene: {}.", channelUID.getAsString(), command,
87                         sceneName);
88                 break;
89             }
90             boolean silentMode = command.equals(OnOffType.ON);
91             LOGGER.debug("handleCommand(): setting silent mode to {}.", silentMode);
92
93             VeluxScene thisScene = thisBridgeHandler.bridgeParameters.scenes.getChannel().existingScenes
94                     .get(new SceneName(sceneName));
95             LOGGER.trace("handleCommand(): working on scene {}.", thisScene);
96             int sceneNumber = thisScene.getBridgeSceneIndex().toInt();
97             new VeluxBridgeSetSceneVelocity().setSilentMode(thisBridgeHandler.thisBridge, sceneNumber, silentMode);
98             LOGGER.trace("handleCommand(): change of velocity done.");
99         } while (false); // common exit
100         return newValue;
101     }
102 }