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.openhab.core.thing.ChannelUID;
17 import org.openhab.core.thing.Thing;
18 import org.openhab.core.thing.ThingUID;
19 import org.openhab.core.thing.binding.BaseBridgeHandler;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * The class {@link ThingConfiguration} provides methods for dealing with
27 * <li>{@link #exists} Check existence of a property,</LI>
28 * <li>{@link #getValue} Returns a property value.</LI>
31 * Noninstantiable utility class
34 * @author Guenther Schreiner - Initial contribution
37 public class ThingConfiguration {
38 private static final Logger LOGGER = LoggerFactory.getLogger(ThingConfiguration.class);
41 * ************************
42 * ***** Constructors *****
45 // Suppress default constructor for non-Instantiability
47 private ThingConfiguration() {
48 throw new AssertionError();
52 * **************************
53 * ***** Public Methods *****
57 * Check existence of the configuration value for the given channel and
58 * desired configName which are defined within VeluxBindingProperties.
61 * @param bridge which handles the mentioned Things,
62 * @param channelUID describes the channel to by scrutinized,
63 * @param configName defines the configuration entry which is to be evaluated.
64 * @return <b>exists</B> of type boolean.
66 public static boolean exists(BaseBridgeHandler bridge, ChannelUID channelUID, String configName) {
67 ThingUID channelTUID = channelUID.getThingUID();
68 Thing thingOfChannel = bridge.getThing().getThing(channelTUID);
69 boolean exists = false;
70 if (thingOfChannel == null) {
71 LOGGER.debug("exists(): Channel {} does not belong to a thing.", channelUID);
73 if (thingOfChannel.getConfiguration().get(configName) != null) {
77 LOGGER.trace("exists({},{}) returns {}.", channelUID, configName, exists);
82 * Return the property value of type Object for the given channel and
83 * desired propertyName which are defined within VeluxBindingProperties.
86 * @param bridge which handles the mentioned Things,
87 * @param channelUID describes the channel to by scrutinized,
88 * @param configName defines the configuration entry which is to be evaluated.
89 * @return <b>configurationValue</B> of type {@link Object}. Will return {@code null}, if not found, or if value
93 public static Object getValue(BaseBridgeHandler bridge, ChannelUID channelUID, String configName) {
94 ThingUID channelTUID = channelUID.getThingUID();
95 Thing thingOfChannel = bridge.getThing().getThing(channelTUID);
96 if (thingOfChannel == null) {
97 LOGGER.warn("getValue(): Channel {} does not belong to a thing.", channelUID);
100 Object configurationValue = thingOfChannel.getConfiguration().get(configName);
101 LOGGER.trace("getValue({},{}) returns {}.", channelUID, configName, configurationValue);
102 return configurationValue;