-
-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend ChannelType by command options (#540)
This addresses eclipse-archived/smarthome#5099 by adding a command description with command options along with the state description. Command options will give a hint to UIs about the specific commands a channel provides. Command options could be rendered as a drop down and also represent the current state or rendered as push buttons to simply send a command to the ThingHandler. The infrstructure basically copies the StateDescription infrastructure with CommandDescriptionProviders and an `DynamicCommandDescriptionProvider` interface for bindings to hook in and provide dynamic command options. Signed-off-by: Henning Treu <[email protected]>
- Loading branch information
Showing
34 changed files
with
947 additions
and
30 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
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
76 changes: 76 additions & 0 deletions
76
.../main/java/org/eclipse/smarthome/core/thing/xml/internal/CommandDescriptionConverter.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,76 @@ | ||
/** | ||
* Copyright (c) 2014,2019 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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.eclipse.smarthome.core.thing.xml.internal; | ||
|
||
import org.eclipse.smarthome.config.xml.util.GenericUnmarshaller; | ||
import org.eclipse.smarthome.config.xml.util.NodeIterator; | ||
import org.eclipse.smarthome.config.xml.util.NodeList; | ||
import org.eclipse.smarthome.config.xml.util.NodeValue; | ||
import org.eclipse.smarthome.core.types.CommandDescription; | ||
import org.eclipse.smarthome.core.types.CommandDescriptionBuilder; | ||
import org.eclipse.smarthome.core.types.CommandOption; | ||
|
||
import com.thoughtworks.xstream.converters.ConversionException; | ||
import com.thoughtworks.xstream.converters.Converter; | ||
import com.thoughtworks.xstream.converters.UnmarshallingContext; | ||
import com.thoughtworks.xstream.io.HierarchicalStreamReader; | ||
|
||
/** | ||
* The {@link CommandDescriptionConverter} is a concrete implementation of the {@code XStream} {@link Converter} | ||
* interface used to convert a command description within an XML document into a {@link CommandDescription} object. | ||
* <p> | ||
* This converter converts {@code command} XML tags. | ||
* | ||
* @author Henning Treu - Initial Contribution | ||
*/ | ||
public class CommandDescriptionConverter extends GenericUnmarshaller<CommandDescription> { | ||
|
||
public CommandDescriptionConverter() { | ||
super(CommandDescription.class); | ||
} | ||
|
||
@Override | ||
public final CommandDescription unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { | ||
NodeList nodes = (NodeList) context.convertAnother(context, NodeList.class); | ||
NodeIterator nodeIterator = new NodeIterator(nodes.getList()); | ||
|
||
NodeList commandOptionsNode = (NodeList) nodeIterator.next(); | ||
if (commandOptionsNode != null) { | ||
if ("options".equals(commandOptionsNode.getNodeName())) { | ||
|
||
CommandDescriptionBuilder commandDescriptionBuilder = CommandDescriptionBuilder.create(); | ||
for (Object coNodeObject : commandOptionsNode.getList()) { | ||
NodeValue optionsNode = (NodeValue) coNodeObject; | ||
|
||
if ("option".equals(optionsNode.getNodeName())) { | ||
String name = (String) optionsNode.getValue(); | ||
String command = optionsNode.getAttributes().get("value"); | ||
|
||
if (name != null && command != null) { | ||
commandDescriptionBuilder.withCommandOption(new CommandOption(command, name)); | ||
} | ||
} else { | ||
throw new ConversionException("The 'options' node must only contain 'option' nodes!"); | ||
} | ||
} | ||
|
||
nodeIterator.assertEndOfType(); | ||
return commandDescriptionBuilder.build(); | ||
} | ||
} | ||
|
||
nodeIterator.assertEndOfType(); | ||
return null; | ||
} | ||
|
||
} |
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
Oops, something went wrong.