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