Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
REST API: Extend support for TOGGLE command
Browse files Browse the repository at this point in the history
TOGGLE command works now with Player + Group items as well as with any other item that accepts toggleable commands

Signed-off-by: Patrick Fink <mail@pfink.de>
  • Loading branch information
pfink committed Nov 27, 2017
1 parent 7e1e42c commit db5b096
Showing 1 changed file with 12 additions and 10 deletions.
Expand Up @@ -55,9 +55,8 @@
import org.eclipse.smarthome.core.items.dto.GroupItemDTO;
import org.eclipse.smarthome.core.items.dto.ItemDTOMapper;
import org.eclipse.smarthome.core.items.events.ItemEventFactory;
import org.eclipse.smarthome.core.library.items.RollershutterItem;
import org.eclipse.smarthome.core.library.items.SwitchItem;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.PlayPauseType;
import org.eclipse.smarthome.core.library.types.UpDownType;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.State;
Expand Down Expand Up @@ -303,21 +302,24 @@ public Response postItemCommand(
Item item = getItem(itemname);
Command command = null;
if (item != null) {
if ("toggle".equalsIgnoreCase(value) && (item instanceof SwitchItem || item instanceof RollershutterItem)) {
List<Class<? extends Command>> acceptedCommands = item.getAcceptedCommandTypes();
if ("toggle".equalsIgnoreCase(value) && (acceptedCommands.contains(OnOffType.class)
|| acceptedCommands.contains(UpDownType.class) || acceptedCommands.contains(PlayPauseType.class))) {
if (OnOffType.ON.equals(item.getStateAs(OnOffType.class))) {
command = OnOffType.OFF;
}
if (OnOffType.OFF.equals(item.getStateAs(OnOffType.class))) {
} else if (OnOffType.OFF.equals(item.getStateAs(OnOffType.class))) {
command = OnOffType.ON;
}
if (UpDownType.UP.equals(item.getStateAs(UpDownType.class))) {
} else if (UpDownType.UP.equals(item.getStateAs(UpDownType.class))) {
command = UpDownType.DOWN;
}
if (UpDownType.DOWN.equals(item.getStateAs(UpDownType.class))) {
} else if (UpDownType.DOWN.equals(item.getStateAs(UpDownType.class))) {
command = UpDownType.UP;
} else if (PlayPauseType.PAUSE.equals(item.getStateAs(PlayPauseType.class))) {
command = PlayPauseType.PLAY;
} else if (PlayPauseType.PLAY.equals(item.getStateAs(PlayPauseType.class))) {
command = PlayPauseType.PAUSE;
}
} else {
command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), value);
command = TypeParser.parseCommand(acceptedCommands, value);
}
if (command != null) {
logger.debug("Received HTTP POST request at '{}' with value '{}'.", uriInfo.getPath(), value);
Expand Down

0 comments on commit db5b096

Please sign in to comment.