]> git.basschouten.com Git - openhab-addons.git/blob
95c88c581f0be4820ef50839915164804977ab79
[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.millheat.internal.model;
14
15 import org.openhab.binding.millheat.internal.dto.DeviceDTO;
16
17 /**
18  * The {@link Heater} represents a heater, either connected to a room or independent
19  *
20  * @author Arne Seime - Initial contribution
21  */
22 public class Heater {
23     private Room room;
24     private final Long id;
25     private final String name;
26     private final String macAddress;
27     private final boolean heatingActive;
28     private boolean canChangeTemp = true;
29     private final int subDomain;
30     private final int currentTemp;
31     private Integer targetTemp;
32     private boolean fanActive;
33     private boolean powerStatus;
34     private final boolean windowOpen;
35
36     public Heater(final DeviceDTO dto) {
37         id = dto.deviceId;
38         name = dto.deviceName;
39         macAddress = dto.macAddress;
40         heatingActive = dto.heaterFlag;
41         canChangeTemp = dto.canChangeTemp;
42         subDomain = dto.subDomainId;
43         currentTemp = (int) dto.currentTemp;
44         setTargetTemp(dto.holidayTemp);
45         setFanActive(dto.fanStatus);
46         setPowerStatus(dto.powerStatus);
47         windowOpen = dto.openWindow;
48     }
49
50     public Heater(final DeviceDTO dto, final Room room) {
51         this.room = room;
52         id = dto.deviceId;
53         name = dto.deviceName;
54         macAddress = dto.macAddress;
55         heatingActive = dto.heaterFlag;
56         canChangeTemp = dto.canChangeTemp;
57         subDomain = dto.subDomainId;
58         currentTemp = (int) dto.currentTemp;
59         if (room != null && room.getMode() != null) {
60             switch (room.getMode()) {
61                 case COMFORT:
62                     setTargetTemp(room.getComfortTemp());
63                     break;
64                 case SLEEP:
65                     setTargetTemp(room.getSleepTemp());
66                     break;
67                 case AWAY:
68                     setTargetTemp(room.getAwayTemp());
69                     break;
70                 case OFF:
71                     setTargetTemp(null);
72                     break;
73                 default:
74                     // NOOP
75             }
76         }
77         setFanActive(dto.fanStatus);
78         setPowerStatus(dto.powerStatus);
79         windowOpen = dto.openWindow;
80     }
81
82     @Override
83     public String toString() {
84         return "Heater [room=" + room + ", id=" + id + ", name=" + name + ", macAddress=" + macAddress
85                 + ", heatingActive=" + heatingActive + ", canChangeTemp=" + canChangeTemp + ", subDomain=" + subDomain
86                 + ", currentTemp=" + currentTemp + ", targetTemp=" + getTargetTemp() + ", fanActive=" + fanActive()
87                 + ", powerStatus=" + powerStatus() + ", windowOpen=" + windowOpen + "]";
88     }
89
90     public Room getRoom() {
91         return room;
92     }
93
94     public Long getId() {
95         return id;
96     }
97
98     public String getName() {
99         return name;
100     }
101
102     public String getMacAddress() {
103         return macAddress;
104     }
105
106     public boolean isHeatingActive() {
107         return heatingActive;
108     }
109
110     public boolean canChangeTemp() {
111         return canChangeTemp;
112     }
113
114     public int getSubDomain() {
115         return subDomain;
116     }
117
118     public int getCurrentTemp() {
119         return currentTemp;
120     }
121
122     public Integer getTargetTemp() {
123         return targetTemp;
124     }
125
126     public boolean fanActive() {
127         return fanActive;
128     }
129
130     public boolean powerStatus() {
131         return powerStatus;
132     }
133
134     public boolean windowOpen() {
135         return windowOpen;
136     }
137
138     public void setTargetTemp(final Integer targetTemp) {
139         this.targetTemp = targetTemp;
140     }
141
142     public void setFanActive(final boolean fanActive) {
143         this.fanActive = fanActive;
144     }
145
146     public void setPowerStatus(final boolean powerStatus) {
147         this.powerStatus = powerStatus;
148     }
149 }