]> git.basschouten.com Git - openhab-addons.git/blob
827a25a5ac0b80da33819047b274d40e9de2a5cb
[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 java.time.LocalDateTime;
16 import java.time.ZoneOffset;
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import org.openhab.binding.millheat.internal.dto.HomeDTO;
21 import org.openhab.core.library.types.OnOffType;
22
23 /**
24  * The {@link Home} represents a home
25  *
26  * @author Arne Seime - Initial contribution
27  */
28 public class Home {
29     private final long id;
30     private final String name;
31     private final int type;
32     private final String zoneOffset;
33     private int holidayTemp;
34     private Mode mode;
35     private final String program = null;
36     private final List<Room> rooms = new ArrayList<>();
37     private final List<Heater> independentHeaters = new ArrayList<>();
38     private LocalDateTime vacationModeStart;
39     private LocalDateTime vacationModeEnd;
40     private boolean advancedVacationMode;
41
42     public Home(final HomeDTO dto) {
43         id = dto.homeId;
44         name = dto.name;
45         type = dto.homeType;
46         zoneOffset = dto.timeZone;
47         holidayTemp = dto.holidayTemp;
48         advancedVacationMode = dto.holidayTempType == 0;
49         if (dto.holidayStartTime != 0) {
50             vacationModeStart = convertFromEpoch(dto.holidayStartTime);
51         }
52         if (dto.holidayEndTime != 0) {
53             vacationModeEnd = convertFromEpoch(dto.holidayEndTime);
54         }
55
56         if (dto.holiday) {
57             mode = new Mode(ModeType.VACATION, vacationModeStart, vacationModeEnd);
58         } else if (dto.alwaysHome) {
59             mode = new Mode(ModeType.ALWAYSHOME, null, null);
60         } else {
61             final LocalDateTime modeStart = LocalDateTime.ofEpochSecond(dto.modeStartTime, 0,
62                     ZoneOffset.of(zoneOffset));
63             final LocalDateTime modeEnd = modeStart.withHour(dto.modeHour).withMinute(dto.modeMinute);
64             mode = new Mode(ModeType.valueOf(dto.currentMode), modeStart, modeEnd);
65         }
66     }
67
68     private LocalDateTime convertFromEpoch(long epoch) {
69         return LocalDateTime.ofEpochSecond(epoch, 0, ZoneOffset.of(zoneOffset));
70     }
71
72     public void addRoom(final Room room) {
73         rooms.add(room);
74     }
75
76     public void addHeater(final Heater heater) {
77         independentHeaters.add(heater);
78     }
79
80     @Override
81     public String toString() {
82         return "Home [id=" + id + ", name=" + name + ", type=" + type + ", zoneOffset=" + zoneOffset + ", holidayTemp="
83                 + holidayTemp + ", mode=" + mode + ", rooms=" + rooms + ", independentHeaters=" + independentHeaters
84                 + ", program=" + program + "]";
85     }
86
87     public Long getId() {
88         return id;
89     }
90
91     public String getName() {
92         return name;
93     }
94
95     public int getType() {
96         return type;
97     }
98
99     public String getTimezone() {
100         return zoneOffset;
101     }
102
103     public int getHolidayTemp() {
104         return holidayTemp;
105     }
106
107     public Mode getMode() {
108         return mode;
109     }
110
111     public String getProgram() {
112         return program;
113     }
114
115     public List<Room> getRooms() {
116         return rooms;
117     }
118
119     public List<Heater> getIndependentHeaters() {
120         return independentHeaters;
121     }
122
123     public LocalDateTime getVacationModeStart() {
124         return vacationModeStart;
125     }
126
127     public LocalDateTime getVacationModeEnd() {
128         return vacationModeEnd;
129     }
130
131     public void setVacationModeStart(long epoch) {
132         vacationModeStart = convertFromEpoch(epoch);
133         updateVacationMode();
134     }
135
136     public void setVacationModeEnd(long epoch) {
137         vacationModeEnd = convertFromEpoch(epoch);
138         updateVacationMode();
139     }
140
141     public void setHolidayTemp(int holidayTemp) {
142         this.holidayTemp = holidayTemp;
143         updateVacationMode();
144     }
145
146     private void updateVacationMode() {
147         if (mode.getMode() == ModeType.VACATION) {
148             mode = new Mode(ModeType.VACATION, vacationModeStart, vacationModeEnd);
149         }
150     }
151
152     public void setVacationModeAdvanced(OnOffType command) {
153         advancedVacationMode = (OnOffType.ON == command);
154     }
155
156     public boolean isAdvancedVacationMode() {
157         return advancedVacationMode;
158     }
159
160     public void setAdvancedVacationMode(boolean advancedVacationMode) {
161         this.advancedVacationMode = advancedVacationMode;
162     }
163 }