]> git.basschouten.com Git - openhab-addons.git/blob
8ec33568b6e4ba6810bb204860eb0c522a6cc714
[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.mihome.internal.handler;
14
15 import static org.openhab.binding.mihome.internal.XiaomiGatewayBindingConstants.*;
16
17 import org.openhab.binding.mihome.internal.ChannelMapper;
18 import org.openhab.core.thing.Thing;
19
20 import com.google.gson.JsonObject;
21
22 /**
23  * Handles the Xiaomi aqara smart switch with two buttons
24  *
25  * @author Dieter Schmidt - Initial contribution
26  */
27 public class XiaomiAqaraSensorSwitch2Handler extends XiaomiSensorBaseHandler {
28
29     private static final String CHANNEL_0 = "channel_0";
30     private static final String CHANNEL_1 = "channel_1";
31     private static final String DUAL_CHANNEL = "dual_channel";
32
33     public XiaomiAqaraSensorSwitch2Handler(Thing thing) {
34         super(thing);
35     }
36
37     @Override
38     protected void parseReport(JsonObject data) {
39         if (data.has(CHANNEL_0)) {
40             triggerChannel(CHANNEL_SWITCH_CH0,
41                     ChannelMapper.getChannelEvent(data.get(CHANNEL_0).getAsString().toUpperCase()));
42         }
43         if (data.has(CHANNEL_1)) {
44             triggerChannel(CHANNEL_SWITCH_CH1,
45                     ChannelMapper.getChannelEvent(data.get(CHANNEL_1).getAsString().toUpperCase()));
46         }
47         if (data.has(DUAL_CHANNEL)) {
48             triggerChannel(CHANNEL_SWITCH_DUAL_CH,
49                     ChannelMapper.getChannelEvent(data.get(DUAL_CHANNEL).getAsString().toUpperCase()));
50         }
51     }
52 }