2 * Copyright (c) 2010-2023 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.io.imperihome.internal.model.device;
15 import org.openhab.core.items.Item;
16 import org.openhab.core.library.types.DecimalType;
17 import org.openhab.core.library.types.OnOffType;
18 import org.openhab.core.library.types.OpenClosedType;
19 import org.openhab.core.library.types.StringType;
20 import org.openhab.core.types.State;
21 import org.openhab.io.imperihome.internal.model.param.DeviceParam;
22 import org.openhab.io.imperihome.internal.model.param.ParamType;
25 * Abstraction of devices that are trippable, i.e. DevDoor, DevFlood, DevMotion, DevSmoke, DevCO2Alert.
27 * @author Pepijn de Geus - Initial contribution
29 public class TrippableDevice extends AbstractDevice {
31 public TrippableDevice(DeviceType type, Item item) {
34 addParam(new DeviceParam(ParamType.ARMABLE, "0"));
35 addParam(new DeviceParam(ParamType.ARMED, "1"));
36 addParam(new DeviceParam(ParamType.ACKABLE, "0"));
40 public void stateUpdated(Item item, State newState) {
41 super.stateUpdated(item, newState);
43 boolean tripped = false;
45 if (item.getStateAs(OpenClosedType.class) != null) {
46 OpenClosedType state = item.getStateAs(OpenClosedType.class);
47 tripped = state == OpenClosedType.CLOSED;
48 } else if (item.getStateAs(OnOffType.class) != null) {
49 OnOffType state = item.getStateAs(OnOffType.class);
50 tripped = state == OnOffType.ON;
51 } else if (item.getStateAs(DecimalType.class) != null) {
52 DecimalType state = item.getStateAs(DecimalType.class);
53 tripped = state != null && state.intValue() != 0;
54 } else if (item.getStateAs(StringType.class) != null) {
55 StringType state = item.getStateAs(StringType.class);
56 tripped = state != null && !state.toString().isBlank() && !state.toString().trim().equals("ok");
58 logger.debug("Can't interpret state {} as tripped status", item.getState());
61 addParam(new DeviceParam(ParamType.TRIPPED, tripped ^ isInverted() ? "1" : "0"));
64 addParam(new DeviceParam(ParamType.LAST_TRIP, String.valueOf(System.currentTimeMillis())));