Skip to content

Commit

Permalink
[automation] add tags to item modules (openhab#2378)
Browse files Browse the repository at this point in the history
* add tags to item modules
* made state/command configuration optional

Signed-off-by: Kai Kreuzer <kai@openhab.org>
GitOrigin-RevId: 0343f44
  • Loading branch information
kaikreuzer authored and splatch committed Jul 11, 2023
1 parent 0a9e336 commit 023ff34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,24 @@ public Map<String, Object> execute(Map<String, Object> inputs) {
Item item = itemRegistry.getItem(itemName);

Command commandObj = null;
Object cmd = inputs.get(COMMAND);
if (command != null) {
commandObj = TypeParser.parseCommand(item.getAcceptedCommandTypes(), command);
} else {
Object cmd = inputs.get(COMMAND);

if (cmd instanceof Command) {
if (item.getAcceptedCommandTypes().contains(cmd.getClass())) {
commandObj = (Command) cmd;
if (cmd instanceof Command) {
if (item.getAcceptedCommandTypes().contains(cmd.getClass())) {
commandObj = (Command) cmd;
}
}
} else {
commandObj = TypeParser.parseCommand(item.getAcceptedCommandTypes(), command);
}
if (commandObj != null) {
ItemCommandEvent itemCommandEvent = ItemEventFactory.createCommandEvent(itemName, commandObj);
logger.debug("Executing ItemCommandAction on Item {} with Command {}",
itemCommandEvent.getItemName(), itemCommandEvent.getItemCommand());
eventPublisher.post(itemCommandEvent);
} else {
logger.warn("Command '{}' is not valid for item '{}'.", command, itemName);
logger.debug("Command '{}' is not valid for item '{}'.", command, itemName);
}
} catch (ItemNotFoundException e) {
logger.error("Item with name {} not found in ItemRegistry.", itemName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ public ItemStateUpdateActionHandler(Action module, EventPublisher eventPublisher
Item item = itemRegistry.getItem(itemName);

State stateObj = null;
final Object st = inputs.get(STATE);

if (st instanceof State) {
if (item.getAcceptedDataTypes().contains(st.getClass())) {
stateObj = (State) st;
}
} else {
if (state != null) {
stateObj = TypeParser.parseState(item.getAcceptedDataTypes(), state);
} else {
final Object st = inputs.get(STATE);

if (st instanceof State) {
if (item.getAcceptedDataTypes().contains(st.getClass())) {
stateObj = (State) st;
}
}
}
if (stateObj != null) {
final ItemStateEvent itemStateEvent = (ItemStateEvent) ItemEventFactory.createStateEvent(itemName,
Expand All @@ -81,7 +84,7 @@ public ItemStateUpdateActionHandler(Action module, EventPublisher eventPublisher
itemStateEvent.getItemState());
eventPublisher.post(itemStateEvent);
} else {
logger.warn("State '{}' is not valid for item '{}'.", state, itemName);
logger.debug("State '{}' is not valid for item '{}'.", state, itemName);
}
} catch (ItemNotFoundException e) {
logger.error("Item with name {} not found in ItemRegistry.", itemName);
Expand Down

0 comments on commit 023ff34

Please sign in to comment.