]> git.basschouten.com Git - openhab-addons.git/blob
7989c2d7717365c08fc1e14399ac5d55f2a1f2f8
[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.core.thing.ChannelUID;
18 import org.openhab.core.types.State;
19 import org.openhab.binding.velux.internal.VeluxBindingConstants;
20 import org.openhab.binding.velux.internal.VeluxItemType;
21 import org.openhab.binding.velux.internal.bridge.VeluxBridgeLANConfig;
22 import org.openhab.binding.velux.internal.handler.utils.StateUtils;
23 import org.openhab.binding.velux.internal.handler.utils.ThingProperty;
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>ipAddress</B>, <B>subnetMask</B>, <B>defaultGW</B> and <B>DHCP</B> of the Thing
31  * <B>klf200</B> :
32  * <UL>
33  * <LI><I>Velux</I> <B>bridge</B> &rarr; <B>OpenHAB</B>:
34  * <P>
35  * Information retrieval by method {@link #handleRefresh}.</LI>
36  * </UL>
37  *
38  * @author Guenther Schreiner - Initial contribution.
39  */
40 @NonNullByDefault
41 final class ChannelBridgeLANconfig extends ChannelHandlerTemplate {
42     private static final Logger LOGGER = LoggerFactory.getLogger(ChannelBridgeLANconfig.class);
43
44     /*
45      * ************************
46      * ***** Constructors *****
47      */
48
49     // Suppress default constructor for non-instantiability
50
51     private ChannelBridgeLANconfig() {
52         throw new AssertionError();
53     }
54
55     /**
56      * Communication method to retrieve information to update the channel value.
57      *
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.
63      */
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.lanConfig = new VeluxBridgeLANConfig()
69                 .retrieve(thisBridgeHandler.thisBridge);
70         if (thisBridgeHandler.bridgeParameters.lanConfig.isRetrieved) {
71             VeluxItemType itemType = VeluxItemType.getByThingAndChannel(thisBridgeHandler.thingTypeUIDOf(channelUID),
72                     channelUID.getId());
73             switch (itemType) {
74                 case BRIDGE_IPADDRESS:
75                     newState = StateUtils.createState(thisBridgeHandler.bridgeParameters.lanConfig.openHABipAddress);
76                     ThingProperty.setValue(thisBridgeHandler, VeluxBindingConstants.PROPERTY_BRIDGE_IPADDRESS,
77                             thisBridgeHandler.bridgeParameters.lanConfig.openHABipAddress.toString());
78                     break;
79                 case BRIDGE_SUBNETMASK:
80                     newState = StateUtils.createState(thisBridgeHandler.bridgeParameters.lanConfig.openHABsubnetMask);
81                     ThingProperty.setValue(thisBridgeHandler, VeluxBindingConstants.PROPERTY_BRIDGE_SUBNETMASK,
82                             thisBridgeHandler.bridgeParameters.lanConfig.openHABsubnetMask.toString());
83                     break;
84                 case BRIDGE_DEFAULTGW:
85                     newState = StateUtils.createState(thisBridgeHandler.bridgeParameters.lanConfig.openHABdefaultGW);
86                     ThingProperty.setValue(thisBridgeHandler, VeluxBindingConstants.PROPERTY_BRIDGE_DEFAULTGW,
87                             thisBridgeHandler.bridgeParameters.lanConfig.openHABdefaultGW.toString());
88                     break;
89                 case BRIDGE_DHCP:
90                     newState = StateUtils.createState(thisBridgeHandler.bridgeParameters.lanConfig.openHABenabledDHCP);
91                     ThingProperty.setValue(thisBridgeHandler, VeluxBindingConstants.PROPERTY_BRIDGE_DHCP,
92                             thisBridgeHandler.bridgeParameters.lanConfig.openHABenabledDHCP.toString());
93                 default:
94             }
95         }
96         LOGGER.trace("handleRefresh() returns {}.", newState);
97         return newState;
98     }
99 }