]> git.basschouten.com Git - openhab-addons.git/blob
d38b6e7d34f624ca11b2500ecd19cc5cefc36ffd
[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.powermax.internal.state;
14
15 import static org.openhab.binding.powermax.internal.PowermaxBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.i18n.TimeZoneProvider;
19 import org.openhab.core.library.types.OpenClosedType;
20 import org.openhab.core.types.UnDefType;
21
22 /**
23  * A class to store the state of a zone
24  *
25  * @author Laurent Garnier - Initial contribution
26  */
27 @NonNullByDefault
28 public class PowermaxZoneState extends PowermaxStateContainer {
29
30     public BooleanValue tripped = new BooleanValue(this, TRIPPED, OpenClosedType.OPEN, OpenClosedType.CLOSED);
31     public DateTimeValue lastTripped = new DateTimeValue(this, LAST_TRIP);
32     public BooleanValue lowBattery = new BooleanValue(this, LOW_BATTERY);
33     public BooleanValue bypassed = new BooleanValue(this, BYPASSED);
34     public BooleanValue alarmed = new BooleanValue(this, ALARMED);
35     public BooleanValue tamperAlarm = new BooleanValue(this, TAMPER_ALARM);
36     public BooleanValue inactive = new BooleanValue(this, INACTIVE);
37     public BooleanValue tampered = new BooleanValue(this, TAMPERED);
38     public BooleanValue armed = new BooleanValue(this, ARMED);
39     public StringValue lastMessage = new StringValue(this, ZONE_LAST_MESSAGE);
40     public DateTimeValue lastMessageTime = new DateTimeValue(this, ZONE_LAST_MESSAGE_TIME);
41
42     public DynamicValue<Boolean> locked = new DynamicValue<>(this, LOCKED, () -> armed.getValue(), () -> {
43         Boolean isArmed = armed.getValue();
44         if (isArmed == null) {
45             return UnDefType.NULL;
46         }
47         return isArmed ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
48     });
49
50     public PowermaxZoneState(TimeZoneProvider timeZoneProvider) {
51         super(timeZoneProvider);
52     }
53
54     public boolean isLastTripBeforeTime(long refTime) {
55         Long lastTrippedValue = lastTripped.getValue();
56         return Boolean.TRUE.equals(tripped.getValue()) && (lastTrippedValue != null) && (lastTrippedValue < refTime);
57     }
58 }