]> git.basschouten.com Git - openhab-addons.git/blob
b5b5cb82cabe1d6f9b0118961254774c9d124329
[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.max.internal.device;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.openhab.binding.max.internal.message.CMessage;
19 import org.openhab.binding.max.internal.message.Message;
20
21 /**
22  * Base class for configuration provided by the MAX! Cube C Message.
23  *
24  * @author Andreas Heil (info@aheil.de) - Initial contribution
25  */
26 public final class DeviceConfiguration {
27
28     private DeviceType deviceType;
29     private String rfAddress;
30     private String serialNumber;
31     private String name;
32     private int roomId = -1;
33     private String roomName;
34
35     /** Extended configuration properties **/
36     private Map<String, Object> properties = new HashMap<>();
37
38     private DeviceConfiguration() {
39     }
40
41     public static DeviceConfiguration create(Message message) {
42         final DeviceConfiguration configuration = new DeviceConfiguration();
43         configuration.setValues((CMessage) message);
44
45         return configuration;
46     }
47
48     public static DeviceConfiguration create(DeviceInformation di) {
49         DeviceConfiguration configuration = new DeviceConfiguration();
50         configuration.setValues(di.getRFAddress(), di.getDeviceType(), di.getSerialNumber(), di.getRoomId(),
51                 di.getName());
52         return configuration;
53     }
54
55     public void setValues(CMessage message) {
56         setValues(message.getRFAddress(), message.getDeviceType(), message.getSerialNumber(), message.getRoomID());
57         properties = new HashMap<>(message.getProperties());
58     }
59
60     private void setValues(String rfAddress, DeviceType deviceType, String serialNumber, int roomId, String name) {
61         setValues(rfAddress, deviceType, serialNumber, roomId);
62         this.name = name;
63     }
64
65     private void setValues(String rfAddress, DeviceType deviceType, String serialNumber, int roomId) {
66         this.rfAddress = rfAddress;
67         this.deviceType = deviceType;
68         this.serialNumber = serialNumber;
69         this.roomId = roomId;
70     }
71
72     public String getRFAddress() {
73         return rfAddress;
74     }
75
76     public DeviceType getDeviceType() {
77         return deviceType;
78     }
79
80     public String getSerialNumber() {
81         return serialNumber;
82     }
83
84     public String getName() {
85         if (name == null) {
86             return "";
87         } else {
88             return name;
89         }
90     }
91
92     public void setName(String name) {
93         this.name = name;
94     }
95
96     public int getRoomId() {
97         return roomId;
98     }
99
100     public void setRoomId(int roomId) {
101         this.roomId = roomId;
102     }
103
104     public String getRoomName() {
105         if (roomName == null) {
106             return "";
107         } else {
108             return roomName;
109         }
110     }
111
112     public void setRoomName(String roomName) {
113         this.roomName = roomName;
114     }
115
116     /**
117      * @return the properties
118      */
119     public Map<String, Object> getProperties() {
120         return properties;
121     }
122
123     /**
124      * @param properties the properties to set
125      */
126     public void setProperties(HashMap<String, Object> properties) {
127         this.properties = properties;
128     }
129 }