2 * Copyright (c) 2010-2020 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.velux.internal.handler;
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;
29 * <B>Channel-specific retrieval and modification.</B>
31 * This class implements the Channel <B>silentMode</B> of the Thing <B>scene</B> :
33 * <LI><I>Velux</I> <B>bridge</B> → <B>OpenHAB</B>:
35 * Information retrieval by method {@link #handleRefresh}.</LI>
38 * <LI><B>OpenHAB</B> Event Bus → <I>Velux</I> <B>bridge</B>
40 * Sending commands and value updates by method {@link #handleCommand}.</LI>
43 * @author Guenther Schreiner - Initial contribution.
46 final class ChannelSceneSilentmode extends ChannelHandlerTemplate {
47 private static final Logger LOGGER = LoggerFactory.getLogger(ChannelSceneSilentmode.class);
50 * ************************
51 * ***** Constructors *****
54 // Suppress default constructor for non-instantiability
56 private ChannelSceneSilentmode() {
57 throw new AssertionError();
61 * Communication method to update the real world according to the passed channel value (or command).
63 * @param channelUID The item passed as type {@link ChannelUID} for which to following command is addressed to.
64 * @param channelId The same item passed as type {@link String} for which a refresh is intended.
65 * @param command The command passed as type {@link Command} for the mentioned item.
66 * @param thisBridgeHandler The Velux bridge handler with a specific communication protocol which provides
67 * information for this channel.
68 * @return newValue ...
70 static @Nullable Command handleCommand(ChannelUID channelUID, String channelId, Command command,
71 VeluxBridgeHandler thisBridgeHandler) {
72 LOGGER.debug("handleCommand({},{},{},{}) called.", channelUID, channelId, command, thisBridgeHandler);
73 Command newValue = null;
74 do { // just for common exit
75 assert thisBridgeHandler.bridgeParameters.scenes
76 .getChannel().existingScenes != null : "VeluxBridgeHandler.existingScenes not initialized.";
77 if (!ThingConfiguration.exists(thisBridgeHandler, channelUID, VeluxBindingProperties.PROPERTY_SCENE_NAME)) {
78 LOGGER.trace("handleCommand(): aborting processing as scene name is not set.");
81 String sceneName = (String) ThingConfiguration.getValue(thisBridgeHandler, channelUID,
82 VeluxBindingProperties.PROPERTY_SCENE_NAME);
83 if (!thisBridgeHandler.bridgeParameters.scenes.getChannel().existingScenes
84 .isRegistered(new SceneName(sceneName))) {
85 LOGGER.info("handleCommand({},{}): cannot modify unknown scene: {}.", channelUID.getAsString(), command,
89 boolean silentMode = command.equals(OnOffType.ON);
90 LOGGER.debug("handleCommand(): setting silent mode to {}.", silentMode);
92 VeluxScene thisScene = thisBridgeHandler.bridgeParameters.scenes.getChannel().existingScenes
93 .get(new SceneName(sceneName));
94 LOGGER.trace("handleCommand(): working on scene {}.", thisScene);
95 int sceneNumber = thisScene.getBridgeSceneIndex().toInt();
96 new VeluxBridgeSetSceneVelocity().setSilentMode(thisBridgeHandler.thisBridge, sceneNumber, silentMode);
97 LOGGER.trace("handleCommand(): change of velocity done.");
98 } while (false); // common exit