]> git.basschouten.com Git - openhab-addons.git/blob
a5923e92a07df9c5f3a5836ad772850d34f811fa
[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.handler.utils.StateUtils;
18 import org.openhab.core.thing.ChannelUID;
19 import org.openhab.core.types.State;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * <B>Channel-specific retrieval and modification.</B>
25  * <P>
26  * This class implements the Channel <B>products</B> of the Thing <B>klf200</B>:
27  * <UL>
28  * <LI><I>Velux</I> <B>bridge</B> &rarr; <B>OpenHAB</B>:
29  * <P>
30  * Information retrieval by method {@link #handleRefresh}.</LI>
31  * </UL>
32  *
33  * @author Guenther Schreiner - Initial contribution.
34  */
35 @NonNullByDefault
36 final class ChannelBridgeProducts extends ChannelHandlerTemplate {
37     private static final Logger LOGGER = LoggerFactory.getLogger(ChannelBridgeProducts.class);
38
39     /*
40      * ************************
41      * ***** Constructors *****
42      */
43
44     // Suppress default constructor for non-instantiability
45
46     private ChannelBridgeProducts() {
47         throw new AssertionError();
48     }
49
50     /**
51      * Communication method to retrieve information to update the channel value.
52      *
53      * @param channelUID The item passed as type {@link ChannelUID} for which a refresh is intended.
54      * @param channelId The same item passed as type {@link String} for which a refresh is intended.
55      * @param thisBridgeHandler The Velux bridge handler with a specific communication protocol which provides
56      *            information for this channel.
57      * @return newState The value retrieved for the passed channel, or <I>null</I> in case if there is no (new) value.
58      */
59     static @Nullable State handleRefresh(ChannelUID channelUID, String channelId,
60             VeluxBridgeHandler thisBridgeHandler) {
61         LOGGER.debug("handleRefresh({},{},{}) called.", channelUID, channelId, thisBridgeHandler);
62         State newState = null;
63         if (thisBridgeHandler.bridgeParameters.actuators.autoRefresh(thisBridgeHandler.thisBridge)) {
64             LOGGER.trace("handleCommand(): there are some existing products.");
65         }
66         String products = thisBridgeHandler.bridgeParameters.actuators.getChannel().existingProducts.toString();
67         LOGGER.trace("handleCommand(): found products {}.", products);
68         products = products.replaceAll("[^\\p{Punct}\\w]", "_");
69         newState = StateUtils.createState(products);
70         LOGGER.trace("handleRefresh() returns {}.", newState);
71         return newState;
72     }
73 }