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.binding.enocean.internal.eep.A5_11;
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
17 import java.util.function.Function;
19 import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
20 import org.openhab.binding.enocean.internal.messages.ERP1Message;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.library.types.PercentType;
23 import org.openhab.core.library.types.QuantityType;
24 import org.openhab.core.library.unit.Units;
25 import org.openhab.core.types.State;
26 import org.openhab.core.types.UnDefType;
30 * @author Dominik Krickl-Vorreiter - Initial contribution
32 public class A5_11_03 extends _4BSMessage {
34 public A5_11_03(ERP1Message packet) {
38 protected boolean isErrorState() {
41 int state = (db1 >> 4) & 0x03;
43 // TODO: display error state on thing
47 protected State getPositionData() {
49 boolean pvf = getBit(db1, 7);
54 boolean motp = getBit(db0, 6);
55 int bsp = getDB_3Value();
57 if ((bsp >= 0) && (bsp <= 100)) {
58 return new PercentType(motp ? 100 - bsp : bsp);
62 return UnDefType.UNDEF;
65 protected State getAngleData() {
67 boolean avf = getBit(db1, 6);
72 boolean as = getBit(db2, 7);
73 int an = (db2 & 0x7F) * 2;
75 if ((an >= 0) && (an <= 180)) {
76 return new QuantityType<>(as ? an * -1 : an, Units.DEGREE_ANGLE);
80 return UnDefType.UNDEF;
84 protected State convertToStateImpl(String channelId, String channelTypeId,
85 Function<String, State> getCurrentStateFunc, Configuration config) {
87 return UnDefType.UNDEF;
91 case CHANNEL_ROLLERSHUTTER:
92 return getPositionData();
94 return getAngleData();
97 return UnDefType.UNDEF;