forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[velbus] Add new functionality PRESSED and LONG PRESSED (openhab#10664)
* [velbus] Add new functionality PRESSED and LONG PRESSED and fix bug New functionality: Add the the possibility to simulate the PRESSED and LONG PRESSED message of an input. Module supported with button simulation : VMB1RYS (button : CH6) VMB6IN (buttons : CH1 ... CH6) VMB2PBN, VMB6PBN, VMB7IN, VMB8IR, VMB8PB, VMB8PBU, VMBEL1, VMBEL2, VMBEL4, VMBGP1, VMBGP1-2, VMBGP2, VMBGP2-2, VMBGP4, VMBGP4-2, VMBGP4PIR, VMBGP4PIR-2 (buttons : CH1 ... CH8) VMBELO, VMBGPOD, VMBGPOD-2 (buttons : CH1 ... CH32) Fix bug: The channels names were not correctly assigned to the thing properties. The last channel had the default name, not the one retrieved from the module. Also-by: cedricboon <cedric.boon@hotmail.com> Signed-off-by: Daniel Rosengarten <github@praetorians.be>
- Loading branch information
1 parent
f33c7b7
commit d8d6255
Showing
9 changed files
with
362 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...rc/main/java/org/openhab/binding/velbus/internal/handler/VelbusRelayWithInputHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.velbus.internal.handler; | ||
|
||
import static org.openhab.binding.velbus.internal.VelbusBindingConstants.*; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.velbus.internal.VelbusChannelIdentifier; | ||
import org.openhab.binding.velbus.internal.packets.VelbusButtonPacket; | ||
import org.openhab.binding.velbus.internal.packets.VelbusPacket; | ||
import org.openhab.core.library.types.StringType; | ||
import org.openhab.core.thing.ChannelUID; | ||
import org.openhab.core.thing.CommonTriggerEvents; | ||
import org.openhab.core.thing.Thing; | ||
import org.openhab.core.thing.ThingStatus; | ||
import org.openhab.core.thing.ThingStatusDetail; | ||
import org.openhab.core.thing.ThingTypeUID; | ||
import org.openhab.core.types.Command; | ||
|
||
/** | ||
* The {@link VelbusRelayWithInputHandler} is responsible for handling commands, which are | ||
* sent to one of the channels. | ||
* | ||
* @author Daniel Rosengarten - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class VelbusRelayWithInputHandler extends VelbusRelayHandler { | ||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = new HashSet<>(Arrays.asList(THING_TYPE_VMB1RYS)); | ||
|
||
private static final StringType PRESSED = new StringType("PRESSED"); | ||
private static final StringType LONG_PRESSED = new StringType("LONG_PRESSED"); | ||
|
||
public VelbusRelayWithInputHandler(Thing thing) { | ||
super(thing); | ||
} | ||
|
||
@Override | ||
public void handleCommand(ChannelUID channelUID, Command command) { | ||
super.handleCommand(channelUID, command); | ||
|
||
VelbusBridgeHandler velbusBridgeHandler = getVelbusBridgeHandler(); | ||
if (velbusBridgeHandler == null) { | ||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE); | ||
return; | ||
} | ||
|
||
if (isButtonChannel(channelUID) && command instanceof StringType) { | ||
StringType stringTypeCommand = (StringType) command; | ||
|
||
if (stringTypeCommand.equals(PRESSED) || stringTypeCommand.equals(LONG_PRESSED)) { | ||
VelbusButtonPacket packet = new VelbusButtonPacket(getModuleAddress().getChannelIdentifier(channelUID)); | ||
|
||
packet.Pressed(); | ||
velbusBridgeHandler.sendPacket(packet.getBytes()); | ||
triggerChannel("CH6t", CommonTriggerEvents.PRESSED); | ||
|
||
if (stringTypeCommand.equals(LONG_PRESSED)) { | ||
packet.LongPressed(); | ||
velbusBridgeHandler.sendPacket(packet.getBytes()); | ||
triggerChannel("CH6t", CommonTriggerEvents.LONG_PRESSED); | ||
} | ||
|
||
packet.Released(); | ||
velbusBridgeHandler.sendPacket(packet.getBytes()); | ||
triggerChannel("CH6t", CommonTriggerEvents.RELEASED); | ||
} else { | ||
throw new UnsupportedOperationException( | ||
"The command '" + command + "' is not supported on channel '" + channelUID + "'."); | ||
} | ||
} | ||
} | ||
|
||
private boolean isButtonChannel(ChannelUID channelUID) { | ||
return "CH6".equals(channelUID.toString().substring(channelUID.toString().length() - 3)); | ||
} | ||
|
||
private boolean isTriggerChannel(byte address, byte channel) { | ||
VelbusChannelIdentifier velbusChannelIdentifier = new VelbusChannelIdentifier(address, channel); | ||
|
||
if (getModuleAddress().getChannelNumber(velbusChannelIdentifier) == 6) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void onPacketReceived(byte[] packet) { | ||
super.onPacketReceived(packet); | ||
|
||
if (packet[0] == VelbusPacket.STX && packet.length >= 5) { | ||
byte command = packet[4]; | ||
|
||
if (command == COMMAND_PUSH_BUTTON_STATUS && packet.length >= 6) { | ||
byte address = packet[2]; | ||
|
||
byte channelJustPressed = packet[5]; | ||
if (isTriggerChannel(address, channelJustPressed)) { | ||
triggerChannel("CH6t", CommonTriggerEvents.PRESSED); | ||
} | ||
|
||
byte channelJustReleased = packet[6]; | ||
if (isTriggerChannel(address, channelJustReleased)) { | ||
triggerChannel("CH6t", CommonTriggerEvents.RELEASED); | ||
} | ||
|
||
byte channelLongPressed = packet[7]; | ||
if (isTriggerChannel(address, channelLongPressed)) { | ||
triggerChannel("CH6t", CommonTriggerEvents.LONG_PRESSED); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.