]> git.basschouten.com Git - openhab-addons.git/blob
8661687d4c33281654dc1cfe10817b7fca28ad58
[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.VeluxBridgeLANConfig;
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>ipAddress</B>, <B>subnetMask</B>, <B>defaultGW</B> and <B>DHCP</B> of the Thing
29  * <B>klf200</B> :
30  * <UL>
31  * <LI><I>Velux</I> <B>bridge</B> &rarr; <B>OpenHAB</B>:
32  * <P>
33  * Information retrieval by method {@link #handleRefresh}.</LI>
34  * </UL>
35  *
36  * @author Guenther Schreiner - Initial contribution.
37  */
38 @NonNullByDefault
39 final class ChannelBridgeLANconfig extends ChannelHandlerTemplate {
40     private static final Logger LOGGER = LoggerFactory.getLogger(ChannelBridgeLANconfig.class);
41
42     /*
43      * ************************
44      * ***** Constructors *****
45      */
46
47     // Suppress default constructor for non-instantiability
48
49     private ChannelBridgeLANconfig() {
50         throw new AssertionError();
51     }
52
53     /**
54      * Communication method to retrieve information to update the channel value.
55      *
56      * @param channelUID The item passed as type {@link ChannelUID} for which a refresh is intended.
57      * @param channelId The same item passed as type {@link String} for which a refresh is intended.
58      * @param thisBridgeHandler The Velux bridge handler with a specific communication protocol which provides
59      *            information for this channel.
60      * @return newState The value retrieved for the passed channel, or <I>null</I> in case if there is no (new) value.
61      */
62     static @Nullable State handleRefresh(ChannelUID channelUID, String channelId,
63             VeluxBridgeHandler thisBridgeHandler) {
64         LOGGER.debug("handleRefresh({},{},{}) called.", channelUID, channelId, thisBridgeHandler);
65         State newState = null;
66         thisBridgeHandler.bridgeParameters.lanConfig = new VeluxBridgeLANConfig()
67                 .retrieve(thisBridgeHandler.thisBridge);
68         if (thisBridgeHandler.bridgeParameters.lanConfig.isRetrieved) {
69             VeluxItemType itemType = VeluxItemType.getByThingAndChannel(thisBridgeHandler.thingTypeUIDOf(channelUID),
70                     channelUID.getId());
71             switch (itemType) {
72                 case BRIDGE_ADDRESS:
73                     newState = StateUtils.createState(thisBridgeHandler.bridgeParameters.lanConfig.openHABipAddress);
74                     break;
75                 case BRIDGE_SUBNETMASK:
76                     newState = StateUtils.createState(thisBridgeHandler.bridgeParameters.lanConfig.openHABsubnetMask);
77                     break;
78                 case BRIDGE_DEFAULTGW:
79                     newState = StateUtils.createState(thisBridgeHandler.bridgeParameters.lanConfig.openHABdefaultGW);
80                     break;
81                 case BRIDGE_DHCP:
82                     newState = StateUtils.createState(thisBridgeHandler.bridgeParameters.lanConfig.openHABenabledDHCP);
83                 default:
84             }
85         }
86         LOGGER.trace("handleRefresh() returns {}.", newState);
87         return newState;
88     }
89 }