]> git.basschouten.com Git - openhab-addons.git/blob
9ef455f41633b8035c732aea003d8f4565064760
[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 org.openhab.core.events.EventPublisher;
16 import org.openhab.core.items.Item;
17 import org.openhab.core.items.events.ItemCommandEvent;
18 import org.openhab.core.items.events.ItemEventFactory;
19 import org.openhab.core.library.types.PercentType;
20 import org.openhab.io.imperihome.internal.model.device.AbstractDevice;
21
22 /**
23  * Action setting percentage level, e.g. dimmer.
24  *
25  * @author Pepijn de Geus - Initial contribution
26  */
27 public class SetLevelAction extends Action {
28
29     public SetLevelAction(EventPublisher eventPublisher) {
30         super(eventPublisher);
31     }
32
33     @Override
34     public boolean supports(AbstractDevice device, Item item) {
35         return item.getAcceptedCommandTypes().contains(PercentType.class);
36     }
37
38     @Override
39     public void perform(AbstractDevice device, Item item, String value) {
40         ItemCommandEvent event = ItemEventFactory.createCommandEvent(item.getName(), new PercentType(value),
41                 COMMAND_SOURCE);
42         eventPublisher.post(event);
43     }
44 }