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.Objects;
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;
25 * Action setting device status to 1 or 0.
27 * @author Pepijn de Geus - Initial contribution
29 public class SetStatusAction extends Action {
31 public SetStatusAction(EventPublisher eventPublisher) {
32 super(eventPublisher);
36 public boolean supports(AbstractDevice device, Item item) {
37 return item.getAcceptedCommandTypes().contains(OnOffType.class);
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;
47 ItemCommandEvent event = ItemEventFactory.createCommandEvent(item.getName(), cmdValue, COMMAND_SOURCE);
48 eventPublisher.post(event);