]> git.basschouten.com Git - openhab-addons.git/blob
82d8c0c01c5704be87e5e4ce71526657e74b71b7
[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.zoneminder.internal.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * The {@link Monitor} represents the attributes of a Zoneminder monitor
22  * that are relevant to this binding.
23  *
24  * @author Mark Hilbush - Initial contribution
25  */
26 @NonNullByDefault
27 public class Monitor {
28
29     private final Logger logger = LoggerFactory.getLogger(Monitor.class);
30
31     private String id;
32     private String name;
33     private String function;
34     private Boolean enabled;
35     private String status;
36     private Boolean alarm = Boolean.FALSE;
37     private MonitorState state = MonitorState.UNKNOWN;
38     private Integer hourEvents = 0;
39     private Integer dayEvents = 0;
40     private Integer weekEvents = 0;
41     private Integer monthEvents = 0;
42     private Integer totalEvents = 0;
43     private String imageUrl = "";
44     private String videoUrl = "";
45     private @Nullable Event lastEvent = null;
46
47     public Monitor(String monitorId, String name, String function, String enabled, String status) {
48         this.id = monitorId;
49         this.name = name;
50         this.function = function;
51         this.enabled = "1".equals(enabled);
52         this.status = status;
53     }
54
55     public String getId() {
56         return id;
57     }
58
59     public String setId(String id) {
60         return this.id = id;
61     }
62
63     public String getName() {
64         return name;
65     }
66
67     public void setName(String name) {
68         this.name = name;
69     }
70
71     public String getFunction() {
72         return function;
73     }
74
75     public void setFunction(String function) {
76         this.function = function;
77     }
78
79     public boolean isEnabled() {
80         return enabled;
81     }
82
83     public void setEnabled(boolean enabled) {
84         this.enabled = enabled;
85     }
86
87     public String getStatus() {
88         return status;
89     }
90
91     public void setStatus(String status) {
92         this.status = status;
93     }
94
95     public Boolean isAlarm() {
96         return alarm;
97     }
98
99     public MonitorState getState() {
100         return state;
101     }
102
103     public void setState(MonitorState state) {
104         this.alarm = (state != MonitorState.IDLE && state != MonitorState.UNKNOWN);
105         this.state = state;
106     }
107
108     public Integer getHourEvents() {
109         return hourEvents;
110     }
111
112     public void setHourEvents(@Nullable String hourEvents) {
113         if (hourEvents != null) {
114             try {
115                 this.hourEvents = Integer.parseInt(hourEvents);
116             } catch (NumberFormatException e) {
117                 logger.debug("Monitor object contains invalid hourEvents: {}", hourEvents);
118             }
119         }
120     }
121
122     public Integer getDayEvents() {
123         return dayEvents;
124     }
125
126     public void setDayEvents(@Nullable String dayEvents) {
127         if (dayEvents != null) {
128             try {
129                 this.dayEvents = Integer.parseInt(dayEvents);
130             } catch (NumberFormatException e) {
131                 logger.debug("Monitor object contains invalid dayEvents: {}", dayEvents);
132             }
133         }
134     }
135
136     public Integer getWeekEvents() {
137         return weekEvents;
138     }
139
140     public void setWeekEvents(@Nullable String weekEvents) {
141         if (weekEvents != null) {
142             try {
143                 this.weekEvents = Integer.parseInt(weekEvents);
144             } catch (NumberFormatException e) {
145                 logger.debug("Monitor object contains invalid totalEvents: {}", weekEvents);
146             }
147         }
148     }
149
150     public Integer getMonthEvents() {
151         return monthEvents;
152     }
153
154     public void setMonthEvents(@Nullable String monthEvents) {
155         if (monthEvents != null) {
156             try {
157                 this.monthEvents = Integer.parseInt(monthEvents);
158             } catch (NumberFormatException e) {
159                 logger.debug("Monitor object contains invalid monthEvents: {}", monthEvents);
160             }
161         }
162     }
163
164     public Integer getTotalEvents() {
165         return totalEvents;
166     }
167
168     public void setTotalEvents(@Nullable String totalEvents) {
169         if (totalEvents != null) {
170             try {
171                 this.totalEvents = Integer.parseInt(totalEvents);
172             } catch (NumberFormatException e) {
173                 logger.debug("Monitor object contains invalid totalEvents: {}", totalEvents);
174             }
175         }
176     }
177
178     public String getImageUrl() {
179         return imageUrl;
180     }
181
182     public void setImageUrl(String imageUrl) {
183         this.imageUrl = imageUrl;
184     }
185
186     public String getVideoUrl() {
187         return videoUrl;
188     }
189
190     public void setVideoUrl(String videoUrl) {
191         this.videoUrl = videoUrl;
192     }
193
194     public @Nullable Event getMostRecentCompletedEvent() {
195         return lastEvent;
196     }
197
198     public void setLastEvent(@Nullable Event lastEvent) {
199         this.lastEvent = lastEvent;
200     }
201
202     @Override
203     public String toString() {
204         StringBuffer sb = new StringBuffer();
205         sb.append("id=").append(id);
206         sb.append(", name=").append(name);
207         sb.append(", function=").append(function);
208         sb.append(", enabled=").append(enabled);
209         sb.append(", status=").append(status);
210         sb.append(", alarm=").append(alarm);
211         sb.append(", state=").append(state);
212         sb.append(", events=(").append(hourEvents);
213         sb.append(",").append(dayEvents);
214         sb.append(",").append(weekEvents);
215         sb.append(",").append(monthEvents);
216         sb.append(",").append(totalEvents);
217         sb.append(")");
218         return sb.toString();
219     }
220 }