use of org.eclipse.smarthome.core.types.Command in project smarthome by eclipse.
the class ThingRegistryOSGiTest method assertThatThingRegistryDelegatesConfigUpdateToThingHandler.
@Test
public void assertThatThingRegistryDelegatesConfigUpdateToThingHandler() {
ThingUID thingUID = new ThingUID("binding:type:thing");
Thing thing = ThingBuilder.create(THING_TYPE_UID, thingUID).build();
ThingHandler thingHandler = new BaseThingHandler(thing) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
}
@Override
public void handleConfigurationUpdate(@NonNull Map<@NonNull String, @NonNull Object> configurationParameters) {
changedParameters = configurationParameters;
}
};
thing.setHandler(thingHandler);
ThingProvider thingProvider = new ThingProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<@NonNull Thing> listener) {
}
@Override
public Collection<@NonNull Thing> getAll() {
return Collections.singleton(thing);
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<@NonNull Thing> listener) {
}
};
registerService(thingProvider);
ThingRegistry thingRegistry = getService(ThingRegistry.class);
Map<String, Object> parameters = new HashMap<>();
parameters.put("param1", "value1");
parameters.put("param2", 1);
thingRegistry.updateConfiguration(thingUID, parameters);
assertThat(changedParameters.entrySet(), is(equalTo(parameters.entrySet())));
}
use of org.eclipse.smarthome.core.types.Command in project smarthome by eclipse.
the class ScriptBusEvent method sendCommand.
/**
* Sends a command for a specified item to the event bus.
*
* @param itemName the name of the item to send the command to
* @param commandString the command to send
*/
public Object sendCommand(String itemName, String commandString) {
if (eventPublisher != null && itemRegistry != null) {
try {
Item item = itemRegistry.getItem(itemName);
Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandString);
eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, command));
} catch (ItemNotFoundException e) {
LoggerFactory.getLogger(ScriptBusEvent.class).warn("Item '{}' does not exist.", itemName);
}
}
return null;
}
use of org.eclipse.smarthome.core.types.Command in project smarthome by eclipse.
the class ItemCommandActionHandler method execute.
@Override
public Map<String, Object> execute(Map<String, Object> inputs) {
String itemName = (String) module.getConfiguration().get(ITEM_NAME);
String command = (String) module.getConfiguration().get(COMMAND);
if (itemName != null && command != null && eventPublisher != null && itemRegistry != null) {
try {
Item item = itemRegistry.getItem(itemName);
Command commandObj = TypeParser.parseCommand(item.getAcceptedCommandTypes(), command);
ItemCommandEvent itemCommandEvent = ItemEventFactory.createCommandEvent(itemName, commandObj);
logger.debug("Executing ItemCommandAction on Item {} with Command {}", itemCommandEvent.getItemName(), itemCommandEvent.getItemCommand());
eventPublisher.post(itemCommandEvent);
} catch (ItemNotFoundException e) {
logger.error("Item with name {} not found in ItemRegistry.", itemName);
}
} else {
logger.error("Command was not posted because either the configuration was not correct or a service was missing: ItemName: {}, Command: {}, eventPublisher: {}, ItemRegistry: {}", itemName, command, eventPublisher, itemRegistry);
}
return null;
}
use of org.eclipse.smarthome.core.types.Command in project smarthome by eclipse.
the class ItemEventFactory method createCommandEvent.
private Event createCommandEvent(String topic, String payload, String source) {
String itemName = getItemName(topic);
ItemEventPayloadBean bean = deserializePayload(payload, ItemEventPayloadBean.class);
Command command = parseType(bean.getType(), bean.getValue(), Command.class);
return new ItemCommandEvent(topic, payload, itemName, command, source);
}
use of org.eclipse.smarthome.core.types.Command in project smarthome by eclipse.
the class RuleTriggerManager method internalGetCommandRules.
private void internalGetCommandRules(String name, Boolean isGroup, List<Class<? extends Command>> acceptedCommandTypes, Command command, List<Rule> result) {
final String mapName = (isGroup) ? GROUP_NAME_PREFIX + name : name;
for (Rule rule : getAllRules(COMMAND, mapName)) {
for (final EventTrigger t : rule.getEventtrigger()) {
String triggerCommandString = null;
if ((!isGroup) && (t instanceof CommandEventTrigger)) {
final CommandEventTrigger ct = (CommandEventTrigger) t;
if (ct.getItem().equals(name)) {
triggerCommandString = ct.getCommand();
} else {
continue;
}
} else if ((isGroup) && (t instanceof GroupMemberCommandEventTrigger)) {
final GroupMemberCommandEventTrigger gmct = (GroupMemberCommandEventTrigger) t;
if (gmct.getGroup().equals(name)) {
triggerCommandString = gmct.getCommand();
} else {
continue;
}
} else {
continue;
}
if (triggerCommandString != null) {
final Command triggerCommand = TypeParser.parseCommand(acceptedCommandTypes, triggerCommandString);
if (!command.equals(triggerCommand)) {
continue;
}
}
result.add(rule);
}
}
}
Aggregations