]> git.basschouten.com Git - openhab-addons.git/blob
03359bb7f3dd1b0d4b77e3b13f415d9986328f71
[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.smartthings.internal.converter;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.smartthings.internal.dto.SmartthingsStateData;
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.State;
22
23 /**
24  * Converter class for Door Control.
25  * This can't use the default because when closing the door the command that comes in as "closed" but "close" needs to
26  * be
27  * sent to Smartthings
28  *
29  * @author Bob Raker - Initial contribution
30  */
31 @NonNullByDefault
32 public class SmartthingsOpenCloseControlConverter extends SmartthingsConverter {
33
34     public SmartthingsOpenCloseControlConverter(Thing thing) {
35         super(thing);
36     }
37
38     @Override
39     public String convertToSmartthings(ChannelUID channelUid, Command command) {
40         String smartthingsValue = ("open".equals(command.toString().toLowerCase())) ? "open" : "close";
41         smartthingsValue = surroundWithQuotes(smartthingsValue);
42
43         return String.format("{\"capabilityKey\": \"%s\", \"deviceDisplayName\": \"%s\", \"value\": %s}", thingTypeId,
44                 smartthingsName, smartthingsValue);
45     }
46
47     @Override
48     public State convertToOpenHab(@Nullable String acceptedChannelType, SmartthingsStateData dataFromSmartthings) {
49         return defaultConvertToOpenHab(acceptedChannelType, dataFromSmartthings);
50     }
51 }