]> git.basschouten.com Git - openhab-addons.git/blob
f454a3d3d9cfb1000d9b37c5a1023b4722dec75d
[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.binding.somfytahoma.internal.handler;
14
15 import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.thing.ChannelUID;
19 import org.openhab.core.thing.Thing;
20 import org.openhab.core.types.Command;
21 import org.openhab.core.types.RefreshType;
22
23 /**
24  * The {@link SomfyTahomaBioclimaticPergolaHandler} is responsible for handling commands,
25  * which are sent to one of the channels of the bioclimatic pergola thing.
26  *
27  * @author Ondrej Pecta - Initial contribution
28  */
29 @NonNullByDefault
30 public class SomfyTahomaBioclimaticPergolaHandler extends SomfyTahomaBaseThingHandler {
31
32     public SomfyTahomaBioclimaticPergolaHandler(Thing thing) {
33         super(thing);
34         stateNames.put(SLATS, "core:SlatsOpenClosedState");
35         stateNames.put(ORIENTATION, "core:SlatsOrientationState");
36     }
37
38     @Override
39     public void handleCommand(ChannelUID channelUID, Command command) {
40         super.handleCommand(channelUID, command);
41
42         if (command instanceof RefreshType) {
43             return;
44         }
45
46         switch (channelUID.getId()) {
47             case PERGOLA_COMMAND:
48                 String cmd = getTahomaCommand(command.toString().toUpperCase());
49                 sendCommand(cmd);
50                 break;
51             case ORIENTATION:
52                 // Bioclimatic pergola can control only orientation and full closure, not partial closure
53                 String param = "[" + toInteger(command) + "]";
54                 sendCommand(COMMAND_SET_ORIENTATION, param);
55                 break;
56             default:
57                 return;
58         }
59     }
60
61     private String getTahomaCommand(String command) {
62         switch (command) {
63             case "OFF":
64             case "DOWN":
65             case "CLOSE":
66             case "CLOSESLATS":
67                 return COMMAND_CLOSE_SLATS;
68             case "ON":
69             case "UP":
70             case "OPEN":
71             case "OPENSLATS":
72                 return COMMAND_OPEN_SLATS;
73             default:
74                 return COMMAND_STOP;
75         }
76     }
77 }