]> git.basschouten.com Git - openhab-addons.git/blob
17136c5d6c272c9370d4f252e25c44af439e3f49
[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.utils;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.thing.ChannelUID;
17 import org.openhab.core.thing.Thing;
18 import org.openhab.core.thing.ThingUID;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /***
23  * The class {@link ThingProperty} provides methods for dealing with
24  * properties.
25  * <ul>
26  * <li>{@link ThingConfiguration#exists} Check existence of a property,</LI>
27  * <li>{@link ThingConfiguration#getValue} Returns a property value,</LI>
28  * <li>{@link #setValue} Modifies a property value.</LI>
29  * </UL>
30  * <P>
31  * Noninstantiable utility class
32  * </P>
33  *
34  * @author Guenther Schreiner - Initial contribution
35  */
36 @NonNullByDefault
37 public class ThingProperty {
38     private static final Logger LOGGER = LoggerFactory.getLogger(ThingProperty.class);
39
40     /*
41      * ************************
42      * ***** Constructors *****
43      */
44
45     // Suppress default constructor for non-Instantiability
46
47     private ThingProperty() {
48         throw new AssertionError();
49     }
50
51     /*
52      * **************************
53      * ***** Public Methods *****
54      */
55
56     /**
57      * Modifies the property value of the given thing and the named property.
58      * <p>
59      *
60      * @param thing which property will be modified,
61      * @param propertyName defines the property which is to be modified,
62      * @param propertyValue defines the new property value.
63      */
64     public static void setValue(Thing thing, String propertyName, String propertyValue) {
65         thing.setProperty(propertyName, propertyValue);
66         LOGGER.trace("setValue() {} set to {}.", propertyName, propertyValue);
67         return;
68     }
69
70     /**
71      * Modifies the property value for the given bridge, which is a dedicated thing, and the named property.
72      * <p>
73      *
74      * @param bridgeHandler which contains the properties,
75      * @param propertyName defines the property which is to be modified.
76      * @param propertyValue defines the new property value.
77      */
78     public static void setValue(ExtendedBaseBridgeHandler bridgeHandler, String propertyName, String propertyValue) {
79         setValue(bridgeHandler.getThing(), propertyName, propertyValue);
80     }
81
82     /**
83      * Modifies the property value for the given propertyName, identified by the given bridge and channel.desired
84      * propertyName which are defined within
85      * VeluxBindingProperties.
86      * <p>
87      *
88      * @param bridgeHandler which contains the properties,
89      * @param channelUID describes the channel to by scrutinized,
90      * @param propertyName defines the property which is to be modified.
91      * @param propertyValue defines the new property value.
92      */
93     public static void setValue(ExtendedBaseBridgeHandler bridgeHandler, ChannelUID channelUID, String propertyName,
94             String propertyValue) {
95         ThingUID channelTUID = channelUID.getThingUID();
96         Thing thingOfChannel = bridgeHandler.getThing().getThing(channelTUID);
97         if (thingOfChannel == null) {
98             LOGGER.warn("setValue(): Channel {} does not belong to a thing.", channelUID);
99             return;
100         }
101         setValue(thingOfChannel, propertyName, propertyValue);
102     }
103 }