2 * Copyright (c) 2010-2021 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.innogysmarthome.internal.client.entity.device;
15 import static org.openhab.binding.innogysmarthome.internal.InnogyBindingConstants.*;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.List;
21 import org.openhab.binding.innogysmarthome.internal.client.entity.capability.Capability;
22 import org.openhab.binding.innogysmarthome.internal.client.entity.location.Location;
23 import org.openhab.binding.innogysmarthome.internal.client.entity.message.Message;
25 import com.google.gson.annotations.SerializedName;
28 * Defines the structure of a {@link Device}.
30 * @author Oliver Kuhl - Initial contribution
34 public static final String DEVICE_MANUFACTURER_RWE = "RWE";
35 public static final String DEVICE_MANUFACTURER_INNOGY = "innogy";
37 protected static final String PROTOCOL_ID_COSIP = "Cosip";
38 protected static final String PROTOCOL_ID_VIRTUAL = "Virtual";
39 protected static final String PROTOCOL_ID_WMBUS = "wMBus";
41 public static final List<String> EMPTY_CAPABILITY_LINK_LIST = new ArrayList<>();
44 * Unique id for the device, always available in model.
49 * Identifier of the manufacturer, always available in model
51 private String manufacturer;
54 * Version number of the device for the domain model.
56 * If the functionality of the device changes, the version must
57 * be increased to indicate that there are new or changed attributes
58 * of the device. Always available in model.
60 private String version;
63 * Defines the product, which is used as an identifier for selecting the
64 * right add-in to support the functionality of the device.
65 * Remark: one add-in can support multiple devices, e.g.
66 * core.RWE, which supports all RWE hardware devices (also referred to as core devices).
67 * Always available in model.
69 private String product;
72 * Device number or id like SGTIN given by the manufacturer. Optional.
74 private String serialnumber;
77 * Specifies the type of the device, which is defined by the manufacturer. The triple of device type, manufacturer
78 * and the version must be unique.
79 * Always available in model.
83 private DeviceConfig config;
86 * Contains a list of the device capabilities.
90 @SerializedName("capabilities")
91 private List<String> capabilityLinkList;
93 private HashMap<String, Capability> capabilityMap;
95 private DeviceState deviceState;
98 * The tag container can contain any number of properties for grouping of the devices in the client, e.g. category
99 * of device like “security related”. The tags can be freely chosen by the client and will not be considered by the
100 * system for any business logic.
105 // private List<Property> tagList;
108 * The location contains the link to the location of the device. Optional.
110 @SerializedName("location")
111 private String locationLink;
113 private transient Location location;
115 private List<Message> messageList;
117 private boolean lowBattery;
119 * Stores the message id, that contains the low battery state. This is needed to identify the device, when the
121 * with that id is deleted (thus low battery state is false again).
123 private String lowBatteryMessageId;
126 * Stores, if the {@link Device} is battery powered.
128 private boolean batteryPowered = false;
133 public String getId() {
138 * @param id the id to set
140 public void setId(String id) {
145 * @return the manufacturer
147 public String getManufacturer() {
152 * @param manufacturer the manufacturer to set
154 public void setManufacturer(String manufacturer) {
155 this.manufacturer = manufacturer;
159 * @return the version
161 public String getVersion() {
166 * @param version the version to set
168 public void setVersion(String version) {
169 this.version = version;
173 * @return the product
175 public String getProduct() {
180 * @param product the product to set
182 public void setProduct(String product) {
183 this.product = product;
187 * @return the serialnumber
189 public String getSerialnumber() {
194 * @param serialnumber the serialnumber to set
196 public void setSerialnumber(String serialnumber) {
197 this.serialnumber = serialnumber;
201 * Returns true, if the {@link Device} has a serial number.
205 public boolean hasSerialNumber() {
206 return (serialnumber != null && serialnumber != "");
212 public String getType() {
217 * @param type the type to set
219 public void setType(String type) {
226 public DeviceConfig getConfig() {
231 * @param config the config to set
233 public void setConfig(DeviceConfig config) {
234 this.config = config;
238 * Returns the {@link DeviceState}. Only available, if device has a state. Better check with
239 * {@link Device#hasDeviceState()} first!
241 * @return the entityState or null
243 public DeviceState getDeviceState() {
248 * @param deviceState the deviceState to set
250 public void setDeviceState(DeviceState deviceState) {
251 this.deviceState = deviceState;
255 * Returns, if the {@link Device} has a state. Not all {@link Device}s have a state.
259 public boolean hasDeviceState() {
260 return deviceState != null;
264 * @return the capabilityList
266 public List<String> getCapabilityLinkList() {
267 if (capabilityLinkList != null) {
268 return capabilityLinkList;
270 return EMPTY_CAPABILITY_LINK_LIST;
275 * @param capabilityList the capabilityList to set
277 public void setCapabilityList(List<String> capabilityList) {
278 this.capabilityLinkList = capabilityList;
282 * @param capabilityMap the capabilityMap to set
284 public void setCapabilityMap(HashMap<String, Capability> capabilityMap) {
285 this.capabilityMap = capabilityMap;
289 * @return the capabilityMap
291 public HashMap<String, Capability> getCapabilityMap() {
292 return this.capabilityMap;
296 * Returns the {@link Capability} with the given id.
301 public Capability getCapabilityWithId(String id) {
302 return this.capabilityMap.get(id);
306 * @return the locationLink
308 public String getLocationLink() {
313 * @param locationList the locationList to set
315 public void setLocation(String locationLink) {
316 this.locationLink = locationLink;
320 * Returns the id of the {@link Location}
324 public String getLocationId() {
325 if (locationLink != null) {
326 return locationLink.replace("/location/", "");
332 * Returns the {@link Location} of the {@link Device}. Better check with {@link Device#hasLocation()} first, as not
333 * all devices have one.
335 * @return the location
337 public Location getLocation() {
342 * @param location the location to set
344 public void setLocation(Location location) {
345 this.location = location;
349 * Returns, if the {@link Device} has a {@link Location}. Not all devices have a {@link Location}...
351 * @return boolean true, if a {@link Location} is set, else false
353 public boolean hasLocation() {
354 return location != null;
358 * @return the messageList
360 public List<Message> getMessageList() {
365 * @param messageList the messageList to set
367 public void setMessageList(List<Message> messageList) {
368 this.messageList = messageList;
370 for (final Message m : messageList) {
371 setLowBattery(Message.TYPE_DEVICE_LOW_BATTERY.equals(m.getType()));
372 setReachable(!Message.TYPE_DEVICE_UNREACHABLE.equals(m.getType()));
377 * Sets if the {@link Device} is reachable;
381 public void setReachable(boolean isReachable) {
382 if (getDeviceState().hasIsReachableState()) {
383 getDeviceState().setReachable(isReachable);
388 * Returns if the {@link Device} is reachable.
392 public boolean isReachable() {
393 return getDeviceState().getState().getIsReachable().getValue();
397 * Sets the low battery state for the {@link Device}.
399 * @param hasLowBattery
401 public void setLowBattery(boolean hasLowBattery) {
402 this.lowBattery = hasLowBattery;
406 * Returns true if the {@link Device} has a low battery warning. Only available on battery devices.
410 public boolean hasLowBattery() {
414 public String getLowBatteryMessageId() {
415 return this.lowBatteryMessageId;
418 public void setLowBatteryMessageId(String messageId) {
419 this.lowBatteryMessageId = messageId;
423 * Returns true, if the {@link Device} is battery powered.
427 public boolean isBatteryPowered() {
428 return batteryPowered;
432 * Sets if the device is battery powered.
436 public void setIsBatteryPowered(boolean hasBattery) {
437 batteryPowered = hasBattery;
441 * Returns true, if the {@link Device} has {@link Message}s.
445 public boolean hasMessages() {
446 return (messageList != null && !messageList.isEmpty());
450 * Returns true if the device is a controller (SHC).
454 public boolean isController() {
455 return DEVICE_SHC.equals(type) || DEVICE_SHCA.equals(type);
459 * Returns true, if the device is made by RWE.
463 public boolean isRWEDevice() {
464 return DEVICE_MANUFACTURER_RWE.equals(manufacturer);
468 * Returns true, if the device is made by innogy.
472 public boolean isInnogyDevice() {
473 return DEVICE_MANUFACTURER_INNOGY.equals(manufacturer);
477 * Returns true, if the {@link Device} is a virtual device (e.g. a VariableActuator).
481 public boolean isVirtualDevice() {
482 return PROTOCOL_ID_VIRTUAL.equals(getConfig().getProtocolId());
486 * Returns true, if the {@link Device} is a radio device.
490 public boolean isRadioDevice() {
491 return PROTOCOL_ID_COSIP.equals(getConfig().getProtocolId())
492 || PROTOCOL_ID_WMBUS.equals(getConfig().getProtocolId());
496 * Returns true, if the {@link Device} is a CoSip device.
500 public boolean isCoSipDevice() {
501 return PROTOCOL_ID_COSIP.equals(getConfig().getProtocolId());
505 * Returns true, if the {@link Device} is a W-Mbus device.
509 public boolean isWMBusDevice() {
510 return PROTOCOL_ID_WMBUS.equals(getConfig().getProtocolId());
514 public String toString() {
515 final String string = "Device [" + "id=" + getId() + " manufacturer=" + getManufacturer() + " version="
516 + getVersion() + " product=" + getProduct() + " serialnumber=" + getSerialnumber() + " type="
517 + getType() + " name=" + getConfig().getName() + "]";