2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.io.imperihome.internal.action;
15 import java.util.List;
17 import org.openhab.core.events.EventPublisher;
18 import org.openhab.core.items.Item;
19 import org.openhab.core.items.events.ItemCommandEvent;
20 import org.openhab.core.items.events.ItemEventFactory;
21 import org.openhab.core.library.types.DecimalType;
22 import org.openhab.core.library.types.OnOffType;
23 import org.openhab.core.types.Command;
24 import org.openhab.io.imperihome.internal.model.device.AbstractDevice;
27 * Action performed on a DevScene. Sends an {@link OnOffType#ON} or {@link DecimalType} 1 to the Item.
29 * @author Pepijn de Geus - Initial contribution
31 public class LaunchSceneAction extends Action {
33 public LaunchSceneAction(EventPublisher eventPublisher) {
34 super(eventPublisher);
38 public boolean supports(AbstractDevice device, Item item) {
39 List<Class<? extends Command>> acceptedCommandTypes = item.getAcceptedCommandTypes();
40 return acceptedCommandTypes.contains(OnOffType.class) || acceptedCommandTypes.contains(DecimalType.class);
44 public void perform(AbstractDevice device, Item item, String value) {
45 ItemCommandEvent event = null;
47 List<Class<? extends Command>> acceptedCommandTypes = item.getAcceptedCommandTypes();
48 if (acceptedCommandTypes.contains(OnOffType.class)) {
49 event = ItemEventFactory.createCommandEvent(item.getName(), OnOffType.ON, COMMAND_SOURCE);
50 } else if (acceptedCommandTypes.contains(DecimalType.class)) {
51 event = ItemEventFactory.createCommandEvent(item.getName(), new DecimalType(1), COMMAND_SOURCE);
55 eventPublisher.post(event);