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.avmfritz.internal.dto;
15 import java.math.BigDecimal;
17 import javax.xml.bind.annotation.XmlAttribute;
18 import javax.xml.bind.annotation.XmlElement;
20 import org.eclipse.jdt.annotation.Nullable;
23 * See {@link DeviceListModel}.
25 * In the functionbitmask element value the following bits are used:
28 * <li>Bit 0: HAN-FUN Gerät</li>
29 * <li>Bit 2: Licht/Lampe</li>
30 * <li>Bit 3: HAN-FUN Button - undocumented</li>
31 * <li>Bit 4: Alarm-Sensor</li>
32 * <li>Bit 5: AVM-Button</li>
33 * <li>Bit 6: Comet DECT, Heizkörperregler</li>
34 * <li>Bit 7: Energie Messgerät</li>
35 * <li>Bit 8: Temperatursensor</li>
36 * <li>Bit 9: Schaltsteckdose</li>
37 * <li>Bit 10: AVM DECT Repeater</li>
38 * <li>Bit 11: Mikrofon</li>
39 * <li>Bit 13: HAN-FUN Unit</li>
40 * <li>Bit 15: an-/ausschaltbares Gerät / Steckdose / Lampe / Aktor</li>
41 * <li>Bit 16: Gerät mit einstellbarem Dimm-, Höhen- bzw. Niveau-Level</li>
42 * <li>Bit 17: Lampe mit einstellbarer Farbe/Farbtemperatur</li>
43 * <li>Bit 18: Rollladen - hoch, runter, stop und level 0% bis 100 %</li>
46 * @author Robert Bausdorf - Initial contribution
47 * @author Christoph Weitkamp - Added support for AVM FRITZ!DECT 300 and Comet DECT
48 * @author Christoph Weitkamp - Added support for groups
49 * @author Ulrich Mertin - Added support for HAN-FUN blinds
51 public abstract class AVMFritzBaseModel implements BatteryModel {
52 protected static final int HAN_FUN_DEVICE_BIT = 1; // Bit 0
53 protected static final int LIGHT_BIT = 1 << 2; // Bit 2
54 protected static final int HAN_FUN_BUTTON_BIT = 1 << 3; // Bit 3 - undocumented
55 protected static final int HAN_FUN_ALARM_SENSOR_BIT = 1 << 4; // Bit 4
56 protected static final int BUTTON_BIT = 1 << 5; // Bit 5
57 protected static final int HEATING_THERMOSTAT_BIT = 1 << 6; // Bit 6
58 protected static final int POWERMETER_BIT = 1 << 7; // Bit 7
59 protected static final int TEMPERATURE_SENSOR_BIT = 1 << 8; // Bit 8
60 protected static final int OUTLET_BIT = 1 << 9; // Bit 9
61 protected static final int DECT_REPEATER_BIT = 1 << 10; // Bit 10
62 protected static final int MICROPHONE_BIT = 1 << 11; // Bit 11
63 protected static final int HAN_FUN_UNIT_BIT = 1 << 13; // Bit 13
64 protected static final int HAN_FUN_ON_OFF_BIT = 1 << 15; // Bit 15
65 protected static final int DIMMABLE_LIGHT_BIT = 1 << 16; // Bit 16
66 protected static final int COLOR_LIGHT_BIT = 1 << 17; // Bit 17
67 protected static final int HAN_FUN_BLINDS_BIT = 1 << 18; // Bit 18
68 protected static final int HUMIDITY_SENSOR_BIT = 1 << 20; // Bit 20 - undocumented
70 @XmlAttribute(name = "identifier")
73 @XmlAttribute(name = "id")
74 private String deviceId;
76 @XmlAttribute(name = "functionbitmask")
79 @XmlAttribute(name = "fwversion")
80 private String firmwareVersion;
82 @XmlAttribute(name = "manufacturer")
83 private String deviceManufacturer;
85 @XmlAttribute(name = "productname")
86 private String productName;
88 @XmlElement(name = "present")
89 private Integer present;
91 @XmlElement(name = "name")
94 @XmlElement(name = "battery")
95 private BigDecimal battery;
97 @XmlElement(name = "batterylow")
98 private BigDecimal batterylow;
100 @XmlElement(name = "switch")
101 private SwitchModel switchModel;
103 @XmlElement(name = "simpleonoff")
104 private @Nullable SimpleOnOffModel simpleOnOffUnit;
106 @XmlElement(name = "powermeter")
107 private PowerMeterModel powermeterModel;
109 @XmlElement(name = "hkr")
110 private HeatingModel heatingModel;
112 public @Nullable SimpleOnOffModel getSimpleOnOffUnit() {
113 return simpleOnOffUnit;
116 public PowerMeterModel getPowermeter() {
117 return powermeterModel;
120 public void setPowermeter(PowerMeterModel powermeter) {
121 this.powermeterModel = powermeter;
124 public HeatingModel getHkr() {
128 public void setHkr(HeatingModel heatingModel) {
129 this.heatingModel = heatingModel;
132 public SwitchModel getSwitch() {
136 public void setSwitch(SwitchModel switchModel) {
137 this.switchModel = switchModel;
140 public String getIdentifier() {
141 return ident != null ? ident.replace(" ", "") : null;
144 public void setIdentifier(String identifier) {
145 this.ident = identifier;
148 public String getDeviceId() {
152 public boolean isHANFUNDevice() {
153 return (bitmask & HAN_FUN_DEVICE_BIT) > 0;
156 public boolean isHANFUNButton() {
157 return (bitmask & HAN_FUN_BUTTON_BIT) > 0;
160 public boolean isHANFUNAlarmSensor() {
161 return (bitmask & HAN_FUN_ALARM_SENSOR_BIT) > 0;
164 public boolean isButton() {
165 return (bitmask & BUTTON_BIT) > 0;
168 public boolean isSwitchableOutlet() {
169 return (bitmask & OUTLET_BIT) > 0;
172 public boolean isTemperatureSensor() {
173 return (bitmask & TEMPERATURE_SENSOR_BIT) > 0;
176 public boolean isHumiditySensor() {
177 return (bitmask & HUMIDITY_SENSOR_BIT) > 0;
180 public boolean isPowermeter() {
181 return (bitmask & POWERMETER_BIT) > 0;
184 public boolean isDectRepeater() {
185 return (bitmask & DECT_REPEATER_BIT) > 0;
188 public boolean isHeatingThermostat() {
189 return (bitmask & HEATING_THERMOSTAT_BIT) > 0;
192 public boolean hasMicrophone() {
193 return (bitmask & MICROPHONE_BIT) > 0;
196 public boolean isHANFUNUnit() {
197 return (bitmask & HAN_FUN_UNIT_BIT) > 0;
200 public boolean isHANFUNOnOff() {
201 return (bitmask / HAN_FUN_ON_OFF_BIT) > 0;
204 public boolean isDimmableLight() {
205 return (bitmask & DIMMABLE_LIGHT_BIT) > 0;
208 public boolean isColorLight() {
209 return (bitmask & COLOR_LIGHT_BIT) > 0;
212 public boolean isHANFUNBlinds() {
213 return (bitmask & HAN_FUN_BLINDS_BIT) > 0;
216 public String getFirmwareVersion() {
217 return firmwareVersion;
220 public String getManufacturer() {
221 return deviceManufacturer;
224 public String getProductName() {
228 public int getPresent() {
232 public String getName() {
237 public BigDecimal getBattery() {
242 public BigDecimal getBatterylow() {
247 public String toString() {
248 return new StringBuilder("[ain=").append(ident).append(",bitmask=").append(bitmask).append(",isHANFUNDevice=")
249 .append(isHANFUNDevice()).append(",isHANFUNButton=").append(isHANFUNButton())
250 .append(",isHANFUNAlarmSensor=").append(isHANFUNAlarmSensor()).append(",isButton=").append(isButton())
251 .append(",isSwitchableOutlet=").append(isSwitchableOutlet()).append(",isTemperatureSensor=")
252 .append(isTemperatureSensor()).append(",isHumiditySensor=").append(isHumiditySensor())
253 .append(",isPowermeter=").append(isPowermeter()).append(",isDectRepeater=").append(isDectRepeater())
254 .append(",isHeatingThermostat=").append(isHeatingThermostat()).append(",hasMicrophone=")
255 .append(hasMicrophone()).append(",isHANFUNUnit=").append(isHANFUNUnit()).append(",isHANFUNOnOff=")
256 .append(isHANFUNOnOff()).append(",isDimmableLight=").append(isDimmableLight()).append(",isColorLight=")
257 .append(isColorLight()).append(",isHANFUNBlind=").append(isHANFUNBlinds()).append(",id=")
258 .append(deviceId).append(",manufacturer=").append(deviceManufacturer).append(",productname=")
259 .append(productName).append(",fwversion=").append(firmwareVersion).append(",present=").append(present)
260 .append(",name=").append(name).append(",battery=").append(getBattery()).append(",batterylow=")
261 .append(getBatterylow()).append(",").append(getSwitch()).append(",").append(getSimpleOnOffUnit())
262 .append(",").append(getPowermeter()).append(",").append(getHkr()).append(",").toString();