2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.velux.internal.handler.utils;
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;
24 * The class {@link ThingProperty} provides methods for dealing with
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>
32 * Noninstantiable utility class
35 * @author Guenther Schreiner - Initial contribution
38 public class ThingProperty {
39 private static final Logger LOGGER = LoggerFactory.getLogger(ThingProperty.class);
42 * ************************
43 * ***** Constructors *****
46 // Suppress default constructor for non-Instantiability
48 private ThingProperty() {
49 throw new AssertionError();
53 * **************************
54 * ***** Public Methods *****
58 * Modifies the property value of the given thing and the named property.
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.
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);
72 * Modifies the property value for the given bridge, which is a dedicated thing, and the named property.
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.
79 public static void setValue(ExtendedBaseBridgeHandler bridgeHandler, String propertyName,
80 @Nullable String propertyValue) {
81 setValue(bridgeHandler.getThing(), propertyName, propertyValue);
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.
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.
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);
103 setValue(thingOfChannel, propertyName, propertyValue);