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