2 * Copyright (c) 2010-2022 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.millheat.internal.model;
15 import java.time.LocalDateTime;
16 import java.time.ZoneOffset;
17 import java.util.ArrayList;
18 import java.util.List;
20 import org.openhab.binding.millheat.internal.dto.HomeDTO;
21 import org.openhab.core.library.types.OnOffType;
24 * The {@link Home} represents a home
26 * @author Arne Seime - Initial contribution
29 private final long id;
30 private final String name;
31 private final int type;
32 private final String zoneOffset;
33 private int holidayTemp;
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;
42 public Home(final HomeDTO dto) {
46 zoneOffset = dto.timeZone;
47 holidayTemp = dto.holidayTemp;
48 advancedVacationMode = dto.holidayTempType == 0;
49 if (dto.holidayStartTime != 0) {
50 vacationModeStart = convertFromEpoch(dto.holidayStartTime);
52 if (dto.holidayEndTime != 0) {
53 vacationModeEnd = convertFromEpoch(dto.holidayEndTime);
57 mode = new Mode(ModeType.VACATION, vacationModeStart, vacationModeEnd);
58 } else if (dto.alwaysHome) {
59 mode = new Mode(ModeType.ALWAYSHOME, null, null);
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);
68 private LocalDateTime convertFromEpoch(long epoch) {
69 return LocalDateTime.ofEpochSecond(epoch, 0, ZoneOffset.of(zoneOffset));
72 public void addRoom(final Room room) {
76 public void addHeater(final Heater heater) {
77 independentHeaters.add(heater);
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 + "]";
91 public String getName() {
95 public int getType() {
99 public String getTimezone() {
103 public int getHolidayTemp() {
107 public Mode getMode() {
111 public String getProgram() {
115 public List<Room> getRooms() {
119 public List<Heater> getIndependentHeaters() {
120 return independentHeaters;
123 public LocalDateTime getVacationModeStart() {
124 return vacationModeStart;
127 public LocalDateTime getVacationModeEnd() {
128 return vacationModeEnd;
131 public void setVacationModeStart(long epoch) {
132 vacationModeStart = convertFromEpoch(epoch);
133 updateVacationMode();
136 public void setVacationModeEnd(long epoch) {
137 vacationModeEnd = convertFromEpoch(epoch);
138 updateVacationMode();
141 public void setHolidayTemp(int holidayTemp) {
142 this.holidayTemp = holidayTemp;
143 updateVacationMode();
146 private void updateVacationMode() {
147 if (mode.getMode() == ModeType.VACATION) {
148 mode = new Mode(ModeType.VACATION, vacationModeStart, vacationModeEnd);
152 public void setVacationModeAdvanced(OnOffType command) {
153 advancedVacationMode = (OnOffType.ON == command);
156 public boolean isAdvancedVacationMode() {
157 return advancedVacationMode;
160 public void setAdvancedVacationMode(boolean advancedVacationMode) {
161 this.advancedVacationMode = advancedVacationMode;