2 * Copyright (c) 2010-2024 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.heliosventilation.internal;
15 import java.io.IOException;
17 import java.util.Enumeration;
18 import java.util.HashMap;
20 import java.util.Properties;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.core.thing.ThingTypeUID;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * The {@link HeliosVentilationBindingConstants} class defines common constants, which are
29 * used across the whole binding.
31 * @author Raphael Mack - Initial contribution
34 public class HeliosVentilationBindingConstants {
36 public static final String BINDING_ID = "heliosventilation";
38 public static final String DATAPOINT_FILE = "datapoints.properties";
40 // List of all Thing Type UIDs
41 public static final ThingTypeUID THING_TYPE_HELIOS_VENTILATION = new ThingTypeUID(BINDING_ID, "ventilation");
43 public static final Map<Byte, HeliosVentilationDataPoint> DATAPOINTS;
45 private static final Logger LOGGER;
47 /* logger is used by readChannelProperties() so we need to initialize logger first. */
48 LOGGER = LoggerFactory.getLogger(HeliosVentilationBindingConstants.class);
49 DATAPOINTS = readChannelProperties();
51 // List of all Channel ids
52 // Channel ids are only in datapoints.properties and thing-types.xml
55 * parse datapoints from properties
58 private static Map<Byte, HeliosVentilationDataPoint> readChannelProperties() {
59 HashMap<Byte, HeliosVentilationDataPoint> result = new HashMap<>();
61 URL resource = Thread.currentThread().getContextClassLoader().getResource(DATAPOINT_FILE);
62 Properties properties = new Properties();
64 properties.load(resource.openStream());
66 Enumeration<Object> keys = properties.keys();
67 while (keys.hasMoreElements()) {
68 String channel = (String) keys.nextElement();
69 HeliosVentilationDataPoint dp;
71 dp = new HeliosVentilationDataPoint(channel, properties.getProperty(channel));
72 if (result.containsKey(dp.address())) {
73 result.get(dp.address()).append(dp);
75 result.put(dp.address(), dp);
77 } catch (HeliosPropertiesFormatException e) {
78 LOGGER.warn("could not read resource file {}, binding will probably fail: {}", DATAPOINT_FILE,
82 } catch (IOException e) {
83 LOGGER.warn("could not read resource file {}, binding will probably fail: {}", DATAPOINT_FILE,