]> git.basschouten.com Git - openhab-addons.git/blob
e42cf9a9d4b7ddcbd0704a15ba66243d1c3e2fa2
[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.Objects;
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.OnOffType;
22 import org.openhab.io.imperihome.internal.model.device.AbstractDevice;
23
24 /**
25  * Action setting device status to 1 or 0.
26  * 
27  * @author Pepijn de Geus - Initial contribution
28  */
29 public class SetStatusAction extends Action {
30
31     public SetStatusAction(EventPublisher eventPublisher) {
32         super(eventPublisher);
33     }
34
35     @Override
36     public boolean supports(AbstractDevice device, Item item) {
37         return item.getAcceptedCommandTypes().contains(OnOffType.class);
38     }
39
40     @Override
41     public void perform(AbstractDevice device, Item item, String value) {
42         OnOffType cmdValue = OnOffType.OFF;
43         if (Objects.equals("1", value)) {
44             cmdValue = OnOffType.ON;
45         }
46
47         ItemCommandEvent event = ItemEventFactory.createCommandEvent(item.getName(), cmdValue, COMMAND_SOURCE);
48         eventPublisher.post(event);
49     }
50 }