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.D2_05;
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
17 import java.util.function.Function;
19 import org.openhab.binding.enocean.internal.eep.Base._VLDMessage;
20 import org.openhab.binding.enocean.internal.messages.ERP1Message;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
23 import org.openhab.core.library.types.PercentType;
24 import org.openhab.core.library.types.StopMoveType;
25 import org.openhab.core.library.types.UpDownType;
26 import org.openhab.core.types.Command;
27 import org.openhab.core.types.RefreshType;
28 import org.openhab.core.types.State;
29 import org.openhab.core.types.UnDefType;
33 * @author Daniel Weber - Initial contribution
35 public class D2_05_00 extends _VLDMessage {
37 protected final byte cmdMask = 0x0f;
38 protected final byte outputValueMask = 0x7f;
39 protected final byte outputChannelMask = 0x1f;
41 protected final byte CMD_ACTUATOR_SET_POSITION = 0x01;
42 protected final byte CMD_ACTUATOR_STOP = 0x02;
43 protected final byte CMD_ACTUATOR_POSITION_QUERY = 0x03;
44 protected final byte CMD_ACTUATOR_POSITION_RESPONE = 0x04;
46 protected final byte AllChannels_Mask = 0x1e;
47 protected final byte ChannelA_Mask = 0x00;
49 protected final byte DOWN = 0x64; // 100%
50 protected final byte UP = 0x00; // 0%
56 public D2_05_00(ERP1Message packet) {
60 protected byte getCMD() {
61 return (byte) (bytes[bytes.length - 1] & cmdMask);
64 protected void setPositionData(Command command, byte outputChannel) {
65 if (command instanceof UpDownType) {
66 if (command == UpDownType.DOWN) {
67 setData(DOWN, (byte) 0x00, (byte) 0x00, (byte) (outputChannel + CMD_ACTUATOR_SET_POSITION));
69 setData(UP, (byte) 0x00, (byte) 0x00, (byte) (outputChannel + CMD_ACTUATOR_SET_POSITION));
71 } else if (command instanceof StopMoveType) {
72 if (command == StopMoveType.STOP) {
73 setData((byte) (outputChannel + CMD_ACTUATOR_STOP));
75 } else if (command instanceof PercentType) {
76 setData((byte) (((PercentType) command).intValue()), (byte) 0x00, (byte) 0x00,
77 (byte) (outputChannel + CMD_ACTUATOR_SET_POSITION));
81 protected void setPositionQueryData(byte outputChannel) {
82 setData((byte) (outputChannel + CMD_ACTUATOR_POSITION_QUERY));
85 protected State getPositionData() {
86 if (getCMD() == CMD_ACTUATOR_POSITION_RESPONE) {
87 int position = bytes[0] & 0x7f;
88 if (position != 127) {
89 return new PercentType(position);
93 return UnDefType.UNDEF;
96 protected byte getChannel() {
97 return (byte) (bytes[1] & outputChannelMask);
101 public void addConfigPropertiesTo(DiscoveryResultBuilder discoveredThingResultBuilder) {
102 discoveredThingResultBuilder.withProperty(PARAMETER_SENDINGEEPID, getEEPType().getId())
103 .withProperty(PARAMETER_RECEIVINGEEPID, getEEPType().getId());
107 protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
108 Function<String, State> getCurrentStateFunc, Configuration config) {
109 if (channelId.equals(CHANNEL_ROLLERSHUTTER)) {
110 if (command == RefreshType.REFRESH) {
111 setPositionQueryData(ChannelA_Mask);
113 setPositionData(command, ChannelA_Mask);
119 protected State convertToStateImpl(String channelId, String channelTypeId,
120 Function<String, State> getCurrentStateFunc, Configuration config) {
122 case CHANNEL_ROLLERSHUTTER:
123 return getPositionData();
126 return UnDefType.UNDEF;