Skip to content

Commit

Permalink
Merge pull request #13 from seime/group_rollershutter
Browse files Browse the repository at this point in the history
Add UP/DOWN support for group items

Former-commit-id: e4f4f5c
  • Loading branch information
seaside1 authored Jan 9, 2022
2 parents 36a78b6 + 7e90a9f commit 8d42039
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ public JRuleOpenClosedValue getOpenClosedValue(String itemName) {
return getOpenClosedValueFromState(state);
}

public JRuleUpDownValue getUpDownValue(String itemName) {
State state = getStateFromItem(itemName);
return getUpDownValueFromState(state);
}

private JRulePlayPauseValue getPlayPauseValueFromState(State state) {
final PlayPauseType playPauseType = PlayPauseType.valueOf(state.toFullString());
switch (playPauseType) {
Expand Down Expand Up @@ -269,6 +274,19 @@ private JRuleOpenClosedValue getOpenClosedValueFromState(State state) {
}
}

private JRuleUpDownValue getUpDownValueFromState(State state) {
final UpDownType playPauseType = UpDownType.valueOf(state.toFullString());
switch (playPauseType) {
case UP:
return JRuleUpDownValue.UP;
case DOWN:
return JRuleUpDownValue.DOWN;
default:
logError("Fail to transform up/down value");
return JRuleUpDownValue.UNDEF;
}
}

public State getStateFromItem(String itemName) {
if (itemRegistry == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.openhab.automation.jrule.internal.handler.JRuleEventHandler;
import org.openhab.automation.jrule.rules.value.JRuleOnOffValue;
import org.openhab.automation.jrule.rules.value.JRulePlayPauseValue;
import org.openhab.automation.jrule.rules.value.JRuleUpDownValue;

/**
* The {@link JRuleGroupItem} Items
Expand Down Expand Up @@ -46,6 +47,10 @@ public static JRulePlayPauseValue getStateAsPlayPauseValue(String itemName) {
return JRuleEventHandler.get().getPauseValue(itemName);
}

public static JRuleUpDownValue getStateAsUpDownValue(String itemName) {
return JRuleEventHandler.get().getUpDownValue(itemName);
}

public static void sendCommand(String itemName, JRulePlayPauseValue value) {
JRuleEventHandler.get().sendCommand(itemName, value);
}
Expand All @@ -54,6 +59,10 @@ public static void sendCommand(String itemName, JRuleOnOffValue value) {
JRuleEventHandler.get().sendCommand(itemName, value);
}

public static void sendCommand(String itemName, JRuleUpDownValue value) {
JRuleEventHandler.get().sendCommand(itemName, value);
}

public static void sendCommand(String itemName, String value) {
JRuleEventHandler.get().sendCommand(itemName, value);
}
Expand All @@ -69,4 +78,8 @@ public static void postUpdate(String itemName, JRulePlayPauseValue value) {
public static void postUpdate(String itemName, JRuleOnOffValue value) {
JRuleEventHandler.get().postUpdate(itemName, value);
}

public static void postUpdate(String itemName, JRuleUpDownValue value) {
JRuleEventHandler.get().postUpdate(itemName, value);
}
}
13 changes: 13 additions & 0 deletions src/main/resources/ItemClassGroup.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import java.util.Set;
import org.openhab.automation.jrule.items.JRuleGroupItem;
import org.openhab.automation.jrule.rules.value.JRuleOnOffValue;
import org.openhab.automation.jrule.rules.value.JRulePlayPauseValue;
import org.openhab.automation.jrule.rules.value.JRuleUpDownValue;

/**
* Automatically Generated Class
Expand All @@ -40,6 +41,10 @@ public class _ITEMNAME extends JRuleGroupItem {
return JRuleGroupItem.getStateAsPlayPauseValue(ITEM);
}

public static JRuleUpDownValue getStateAsUpDownValue() {
return JRuleGroupItem.getStateAsUpDownValue(ITEM);
}

public static void sendCommand(String value) {
JRuleGroupItem.sendCommand(ITEM, value);
}
Expand Down Expand Up @@ -71,4 +76,12 @@ public class _ITEMNAME extends JRuleGroupItem {
public static void postUpdate(JRulePlayPauseValue value) {
JRuleGroupItem.postUpdate(ITEM, value);
}

public static void sendCommand(JRuleUpDownValue value) {
JRuleGroupItem.sendCommand(ITEM, value);
}

public static void postUpdate(JRuleUpDownValue value) {
JRuleGroupItem.postUpdate(ITEM, value);
}
}

0 comments on commit 8d42039

Please sign in to comment.