]> git.basschouten.com Git - openhab-addons.git/blob
36521ea767a68fb67612e2a89bf2020c7447ebbc
[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.VeluxItemType;
18 import org.openhab.binding.velux.internal.bridge.VeluxBridgeWLANConfig;
19 import org.openhab.binding.velux.internal.handler.utils.StateUtils;
20 import org.openhab.core.thing.ChannelUID;
21 import org.openhab.core.types.State;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * <B>Channel-specific retrieval and modification.</B>
27  * <P>
28  * This class implements the Channels <B>WLANSSID</B> and <B>WLANPassword</B> of the Thing <B>klf200</B> :
29  * <UL>
30  * <LI><I>Velux</I> <B>bridge</B> &rarr; <B>OpenHAB</B>:
31  * <P>
32  * Information retrieval by method {@link #handleRefresh}.</LI>
33  * </UL>
34  *
35  * @author Guenther Schreiner - Initial contribution.
36  */
37 @NonNullByDefault
38 final class ChannelBridgeWLANconfig extends ChannelHandlerTemplate {
39     private static final Logger LOGGER = LoggerFactory.getLogger(ChannelBridgeWLANconfig.class);
40
41     /*
42      * ************************
43      * ***** Constructors *****
44      */
45
46     // Suppress default constructor for non-instantiability
47
48     private ChannelBridgeWLANconfig() {
49         throw new AssertionError();
50     }
51
52     /**
53      * Communication method to retrieve information to update the channel value.
54      *
55      * @param channelUID The item passed as type {@link ChannelUID} for which a refresh is intended.
56      * @param channelId The same item passed as type {@link String} for which a refresh is intended.
57      * @param thisBridgeHandler The Velux bridge handler with a specific communication protocol which provides
58      *            information for this channel.
59      * @return newState The value retrieved for the passed channel, or <I>null</I> in case if there is no (new) value.
60      */
61     static @Nullable State handleRefresh(ChannelUID channelUID, String channelId,
62             VeluxBridgeHandler thisBridgeHandler) {
63         LOGGER.debug("handleRefresh({},{},{}) called.", channelUID, channelId, thisBridgeHandler);
64         State newState = null;
65         thisBridgeHandler.bridgeParameters.wlanConfig = new VeluxBridgeWLANConfig()
66                 .retrieve(thisBridgeHandler.thisBridge);
67         if (thisBridgeHandler.bridgeParameters.wlanConfig.isRetrieved) {
68             VeluxItemType itemType = VeluxItemType.getByThingAndChannel(thisBridgeHandler.thingTypeUIDOf(channelUID),
69                     channelUID.getId());
70             switch (itemType) {
71                 case BRIDGE_WLANSSID:
72                     newState = StateUtils.createState(thisBridgeHandler.bridgeParameters.wlanConfig.openHABwlanSSID);
73                     break;
74                 case BRIDGE_WLANPASSWORD:
75                     newState = StateUtils
76                             .createState(thisBridgeHandler.bridgeParameters.wlanConfig.openHABwlanPassword);
77                     break;
78                 default:
79             }
80         }
81         LOGGER.trace("handleRefresh() returns {}.", newState);
82         return newState;
83     }
84 }