]> git.basschouten.com Git - openhab-addons.git/blob
9d749f68e5bf1f28dccec2606d4f0f0841abcda1
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.binding.nikobus.internal.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.library.types.OnOffType;
17 import org.openhab.core.library.types.StopMoveType;
18 import org.openhab.core.library.types.UpDownType;
19 import org.openhab.core.thing.Thing;
20 import org.openhab.core.types.Command;
21 import org.openhab.core.types.State;
22
23 /**
24  * The {@link NikobusRollershutterModuleHandler} is responsible for communication between Nikobus
25  * rollershutter-controller and binding.
26  *
27  * @author Boris Krivonog - Initial contribution
28  */
29 @NonNullByDefault
30 public class NikobusRollershutterModuleHandler extends NikobusModuleHandler {
31     public NikobusRollershutterModuleHandler(Thing thing) {
32         super(thing);
33     }
34
35     @Override
36     protected int valueFromCommand(Command command) {
37         if (command == UpDownType.DOWN || command == StopMoveType.MOVE) {
38             return 0x02;
39         }
40         if (command == UpDownType.UP) {
41             return 0x01;
42         }
43         if (command == StopMoveType.STOP) {
44             return 0x00;
45         }
46
47         throw new IllegalArgumentException("Command '" + command + "' not supported");
48     }
49
50     @Override
51     protected State stateFromValue(int value) {
52         if (value == 0x00) {
53             return OnOffType.OFF;
54         }
55         if (value == 0x01) {
56             return UpDownType.UP;
57         }
58         if (value == 0x02) {
59             return UpDownType.DOWN;
60         }
61         throw new IllegalArgumentException("Unexpected value " + value + " received");
62     }
63 }