]> git.basschouten.com Git - openhab-addons.git/blob
04fdcc37573ca1bdb6256d7795147409f8d67ac7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.imperihome.internal.action;
14
15 import java.util.List;
16
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;
25
26 /**
27  * Action performed on a DevScene. Sends an {@link OnOffType#ON} or {@link DecimalType} 1 to the Item.
28  *
29  * @author Pepijn de Geus - Initial contribution
30  */
31 public class LaunchSceneAction extends Action {
32
33     public LaunchSceneAction(EventPublisher eventPublisher) {
34         super(eventPublisher);
35     }
36
37     @Override
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);
41     }
42
43     @Override
44     public void perform(AbstractDevice device, Item item, String value) {
45         ItemCommandEvent event = null;
46
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);
52         }
53
54         if (event != null) {
55             eventPublisher.post(event);
56         }
57     }
58 }