]> git.basschouten.com Git - openhab-addons.git/blob
f40fda15dee8fb9c4b3d4a29cafdd3f46bc9eafa
[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.nobohub.internal.model;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * A Zone contains one or more {@link Component}s.
20  *
21  * @author Jørgen Austvik - Initial contribution
22  * @author Espen Fossen - Initial contribution
23  */
24 @NonNullByDefault
25 public final class Zone {
26
27     private final int id;
28     private final String name;
29     private int activeWeekProfileId;
30     private int comfortTemperature;
31     private int ecoTemperature;
32     private final boolean allowOverrides;
33     private @Nullable Double temperature;
34
35     public Zone(int id, String name, int activeWeekProfileId, int comfortTemperature, int ecoTemperature,
36             boolean allowOverrides) throws NoboDataException {
37         this.id = id;
38         this.name = name;
39         this.activeWeekProfileId = activeWeekProfileId;
40         this.comfortTemperature = comfortTemperature;
41         this.ecoTemperature = ecoTemperature;
42         this.allowOverrides = allowOverrides;
43     }
44
45     public static Zone fromH01(String h01) throws NoboDataException {
46         String[] parts = h01.split(" ", 8);
47
48         if (parts.length != 8) {
49             throw new NoboDataException(
50                     String.format("Unexpected number of parts from hub on H1 call: %d", parts.length));
51         }
52
53         return new Zone(Integer.parseInt(parts[1]), ModelHelper.toJavaString(parts[2]), Integer.parseInt(parts[3]),
54                 Integer.parseInt(parts[4]), Integer.parseInt(parts[5]), "1".equals(parts[6]));
55     }
56
57     public String generateCommandString(final String command) {
58         return String.join(" ", command, Integer.toString(id), ModelHelper.toHubString(name),
59                 Integer.toString(activeWeekProfileId), Integer.toString(comfortTemperature),
60                 Integer.toString(ecoTemperature), allowOverrides ? "1" : "0", "-1"); // "Active override id" is
61                                                                                      // deprecated
62     }
63
64     public int getId() {
65         return id;
66     }
67
68     public String getName() {
69         return name;
70     }
71
72     public int getActiveWeekProfileId() {
73         return activeWeekProfileId;
74     }
75
76     public int getComfortTemperature() {
77         return comfortTemperature;
78     }
79
80     public int getEcoTemperature() {
81         return ecoTemperature;
82     }
83
84     public boolean getAllowOverrides() {
85         return allowOverrides;
86     }
87
88     public void setTemperature(@Nullable Double temperature) {
89         this.temperature = temperature;
90     }
91
92     public @Nullable Double getTemperature() {
93         return temperature;
94     }
95
96     public void setComfortTemperature(int temp) {
97         comfortTemperature = temp;
98     }
99
100     public void setEcoTemperature(int temp) {
101         ecoTemperature = temp;
102     }
103
104     public void setWeekProfile(int weekProfileId) {
105         activeWeekProfileId = weekProfileId;
106     }
107 }