]> git.basschouten.com Git - openhab-addons.git/blob
b6a1bebf11b964f20f118aabf0936c0514666067
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.openhab.core.i18n.TimeZoneProvider;
18 import org.openhab.core.library.types.OpenClosedType;
19
20 /**
21  * A class to store the state of a zone
22  *
23  * @author Laurent Garnier - Initial contribution
24  */
25 public class PowermaxZoneState extends PowermaxStateContainer {
26
27     public BooleanValue tripped = new BooleanValue(this, TRIPPED, OpenClosedType.OPEN, OpenClosedType.CLOSED);
28     public DateTimeValue lastTripped = new DateTimeValue(this, LAST_TRIP);
29     public BooleanValue lowBattery = new BooleanValue(this, LOW_BATTERY);
30     public BooleanValue bypassed = new BooleanValue(this, BYPASSED);
31     public BooleanValue armed = new BooleanValue(this, ARMED);
32
33     public DynamicValue<Boolean> locked = new DynamicValue<>(this, LOCKED, () -> {
34         return armed.getValue();
35     }, () -> {
36         Boolean isArmed = armed.getValue();
37         if (isArmed == null) {
38             return null;
39         }
40         return isArmed ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
41     });
42
43     public PowermaxZoneState(TimeZoneProvider timeZoneProvider) {
44         super(timeZoneProvider);
45     }
46
47     public boolean isLastTripBeforeTime(long refTime) {
48         return Boolean.TRUE.equals(tripped.getValue()) && (lastTripped.getValue() != null)
49                 && (lastTripped.getValue() < refTime);
50     }
51 }