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.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.library.types.StringType;
23 import org.openhab.core.thing.ChannelUID;
24 import org.openhab.core.types.State;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * <B>Channel-specific retrieval and modification.</B>
31 * This class implements the Channels <B>WLANSSID</B> and <B>WLANPassword</B> of the Thing <B>klf200</B> :
33 * <LI><I>Velux</I> <B>bridge</B> → <B>OpenHAB</B>:
35 * Information retrieval by method {@link #handleRefresh}.</LI>
38 * @author Guenther Schreiner - Initial contribution.
41 final class ChannelBridgeWLANconfig extends ChannelHandlerTemplate {
42 private static final Logger LOGGER = LoggerFactory.getLogger(ChannelBridgeWLANconfig.class);
45 * ************************
46 * ***** Constructors *****
49 // Suppress default constructor for non-instantiability
51 private ChannelBridgeWLANconfig() {
52 throw new AssertionError();
56 * Communication method to retrieve information to update the channel value.
58 * @param channelUID The item passed as type {@link ChannelUID} for which a refresh is intended.
59 * @param channelId The same item passed as type {@link String} for which a refresh is intended.
60 * @param thisBridgeHandler The Velux bridge handler with a specific communication protocol which provides
61 * information for this channel.
62 * @return newState The value retrieved for the passed channel, or <I>null</I> in case if there is no (new) value.
64 static @Nullable State handleRefresh(ChannelUID channelUID, String channelId,
65 VeluxBridgeHandler thisBridgeHandler) {
66 LOGGER.debug("handleRefresh({},{},{}) called.", channelUID, channelId, thisBridgeHandler);
67 State newState = null;
68 thisBridgeHandler.bridgeParameters.wlanConfig = new VeluxBridgeWLANConfig()
69 .retrieve(thisBridgeHandler.thisBridge);
70 if (thisBridgeHandler.bridgeParameters.wlanConfig.isRetrieved) {
71 VeluxItemType itemType = VeluxItemType.getByThingAndChannel(thisBridgeHandler.thingTypeUIDOf(channelUID),
73 String msg = thisBridgeHandler.localization.getText("config.velux.bridge.unAvailable");
76 newState = StateUtils.createState(new StringType(msg));
77 ThingProperty.setValue(thisBridgeHandler, VeluxBindingConstants.PROPERTY_BRIDGE_WLANSSID, msg);
79 case BRIDGE_WLANPASSWORD:
80 newState = StateUtils.createState(new StringType(msg));
81 ThingProperty.setValue(thisBridgeHandler, VeluxBindingConstants.PROPERTY_BRIDGE_WLANPASSWORD, msg);
86 LOGGER.trace("handleRefresh() returns {}.", newState);