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.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.
47 final class ChannelSceneSilentmode extends ChannelHandlerTemplate {
48 private static final Logger LOGGER = LoggerFactory.getLogger(ChannelSceneSilentmode.class);
51 * ************************
52 * ***** Constructors *****
55 // Suppress default constructor for non-instantiability
57 private ChannelSceneSilentmode() {
58 throw new AssertionError();
62 * Communication method to update the real world according to the passed channel value (or command).
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 ...
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.");
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,
90 boolean silentMode = command.equals(OnOffType.ON);
91 LOGGER.debug("handleCommand(): setting silent mode to {}.", silentMode);
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