Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[automation] add tags to item modules #2378

Merged
merged 2 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"name": "command",
"type": "TEXT",
"label": "Command",
"description": "the default command to be sent if none is passed as an input value",
"required": true,
"description": "the command to be sent (overrides a potential input value)",
"required": false,
"limitToOptions": false,
"options": [
{
Expand Down Expand Up @@ -53,7 +53,10 @@
"name": "command",
"type": "command",
"label": "Command",
"description": "command that will be sent to the item."
"description": "command that will be sent to the item.",
"tags": [
"command"
]
}
]
},
Expand All @@ -74,8 +77,8 @@
"name": "state",
"type": "TEXT",
"label": "State",
"description": "the default state to be used to update the item if none is passed as an input value",
"required": true,
"description": "the state to update the item to (overrides a potential input value)",
"required": false,
"limitToOptions": false,
"options": [
{
Expand Down Expand Up @@ -110,7 +113,10 @@
"name": "state",
"type": "state",
"label": "State",
"description": "state that the item will be set to."
"description": "state that the item will be set to",
"tags": [
"state"
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
"name": "command",
"type": "command",
"description": "the received command",
"label": "Command"
"label": "Command",
"tags": [
"command"
]
},
{
"name": "event",
Expand Down Expand Up @@ -117,7 +120,10 @@
"name": "state",
"type": "state",
"description": "the item state",
"label": "State"
"label": "State",
"tags": [
"state"
]
},
{
"name": "event",
Expand Down Expand Up @@ -215,7 +221,10 @@
"name": "newState",
"type": "state",
"description": "the new item state",
"label": "New State"
"label": "New State",
"tags": [
"state"
]
},
{
"name": "oldState",
Expand Down Expand Up @@ -285,13 +294,19 @@
"name": "triggeringItem",
"type": "org.openhab.core.items.Item",
"description": "the member of the group that received the command",
"label": "Triggering Item"
"label": "Triggering Item",
"tags": [
"item"
]
},
{
"name": "command",
"type": "command",
"description": "the received command",
"label": "Command"
"label": "Command",
"tags": [
"command"
]
},
{
"name": "event",
Expand Down Expand Up @@ -355,13 +370,19 @@
"name": "triggeringItem",
"type": "org.openhab.core.items.Item",
"description": "the member of the group that updated its state",
"label": "Triggering Item"
"label": "Triggering Item",
"tags": [
"item"
]
},
{
"name": "state",
"type": "state",
"description": "the item state",
"label": "State"
"label": "State",
"tags": [
"state"
]
},
{
"name": "event",
Expand Down Expand Up @@ -459,13 +480,19 @@
"name": "triggeringItem",
"type": "org.openhab.core.items.Item",
"description": "the member of the group that changed its state",
"label": "Triggering Item"
"label": "Triggering Item",
"tags": [
"item"
]
},
{
"name": "newState",
"type": "state",
"description": "the new item state",
"label": "New State"
"label": "New State",
"tags": [
"state"
]
},
{
"name": "oldState",
Expand Down