2 * Copyright (c) 2010-2020 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.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;
23 * The class {@link ThingProperty} provides methods for dealing with
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>
31 * Noninstantiable utility class
34 * @author Guenther Schreiner - Initial contribution
37 public class ThingProperty {
38 private static final Logger LOGGER = LoggerFactory.getLogger(ThingProperty.class);
41 * ************************
42 * ***** Constructors *****
45 // Suppress default constructor for non-Instantiability
47 private ThingProperty() {
48 throw new AssertionError();
52 * **************************
53 * ***** Public Methods *****
57 * Modifies the property value of the given thing and the named property.
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.
64 public static void setValue(Thing thing, String propertyName, String propertyValue) {
65 thing.setProperty(propertyName, propertyValue);
66 LOGGER.trace("setValue() {} set to {}.", propertyName, propertyValue);
71 * Modifies the property value for the given bridge, which is a dedicated thing, and the named property.
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.
78 public static void setValue(ExtendedBaseBridgeHandler bridgeHandler, String propertyName, String propertyValue) {
79 setValue(bridgeHandler.getThing(), propertyName, propertyValue);
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.
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.
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);
101 setValue(thingOfChannel, propertyName, propertyValue);