Skip to content

Commit bfa9e38

Browse files
authored
[somfytahoma] Add closure channel and scaling for RS100 shutter motors (#20432)
* [somfytahoma] Add closure channel and scaling for RS100 shutter motors Signed-off-by: Hennie Hageman <hennie.hageman@gmail.com>
1 parent 17f131d commit bfa9e38

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaShutterHandler.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,38 @@ public class SomfyTahomaShutterHandler extends SomfyTahomaBaseThingHandler {
3333

3434
public SomfyTahomaShutterHandler(Thing thing) {
3535
super(thing);
36+
// Map the closure state directly to the existing CONTROL channel
37+
stateNames.put(CONTROL, "core:ClosureState");
3638
}
3739

3840
@Override
3941
public void handleCommand(ChannelUID channelUID, Command command) {
4042
super.handleCommand(channelUID, command);
41-
if (!CONTROL.equals(channelUID.getId())) {
43+
if (!CONTROL.equals(channelUID.getId()) || command instanceof RefreshType) {
4244
return;
4345
}
4446

45-
if (command instanceof RefreshType) {
46-
return;
47+
if (command instanceof DecimalType) {
48+
// Send percentage values directly
49+
sendCommand(COMMAND_SET_CLOSURE, "[" + toInteger(command) + "]");
4750
} else {
48-
if (command instanceof DecimalType) {
49-
sendCommand(toInteger(command) == 0 ? COMMAND_OPEN : COMMAND_CLOSE);
50-
} else {
51-
// Shutter understands "open", "close" and "stop" commands
52-
String cmd = getTahomaCommand(command.toString());
53-
if (cmd != null) {
54-
sendCommand(cmd);
51+
// Handle string commands (UP, DOWN, STOP)
52+
String cmd = getTahomaCommand(command.toString());
53+
if (COMMAND_STOP.equals(cmd)) {
54+
String executionId = getCurrentExecutions();
55+
if (executionId != null) {
56+
cancelExecution(executionId);
5557
} else {
56-
getLogger().debug("unsupported command: {}", command);
58+
sendCommand(COMMAND_STOP);
5759
}
60+
} else if (cmd != null) {
61+
// Only send if the command is recognized
62+
sendCommand(cmd, "[]");
5863
}
5964
}
6065
}
6166

62-
private @Nullable String getTahomaCommand(String command) {
67+
protected @Nullable String getTahomaCommand(String command) {
6368
switch (command) {
6469
case "OFF":
6570
case "DOWN":
@@ -72,6 +77,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
7277
case "STOP":
7378
return COMMAND_STOP;
7479
default:
80+
// Return null to ignore unsupported commands like MOVE
7581
return null;
7682
}
7783
}

0 commit comments

Comments
 (0)