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.StringType;
23 import org.openhab.core.types.Command;
24 import org.openhab.io.imperihome.internal.model.device.AbstractDevice;
25 import org.openhab.io.imperihome.internal.model.device.DeviceType;
28 * Action setting a thermostat setpoint.
30 * @author Pepijn de Geus - Initial contribution
32 public class SetSetPointAction extends Action {
34 public SetSetPointAction(EventPublisher eventPublisher) {
35 super(eventPublisher);
39 public boolean supports(AbstractDevice device, Item item) {
40 if (device.getType() != DeviceType.THERMOSTAT) {
43 List<Class<? extends Command>> acceptedCommandTypes = item.getAcceptedCommandTypes();
44 return acceptedCommandTypes.contains(DecimalType.class) || acceptedCommandTypes.contains(StringType.class);
48 public void perform(AbstractDevice device, Item item, String value) {
49 List<Class<? extends Command>> acceptedCommandTypes = item.getAcceptedCommandTypes();
52 if (acceptedCommandTypes.contains(DecimalType.class)) {
53 command = new DecimalType(value);
54 } else if (acceptedCommandTypes.contains(StringType.class)) {
55 command = new StringType(value);
57 logger.error("Item {} doesn't support Decimal or String type", item);
61 ItemCommandEvent event = ItemEventFactory.createCommandEvent(item.getName(), command, COMMAND_SOURCE);
62 eventPublisher.post(event);