2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mihome.internal.handler;
15 import static org.openhab.binding.mihome.internal.XiaomiGatewayBindingConstants.*;
17 import org.openhab.core.library.types.OnOffType;
18 import org.openhab.core.thing.ChannelUID;
19 import org.openhab.core.thing.Thing;
20 import org.openhab.core.types.Command;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import com.google.gson.JsonObject;
27 * Handles the Xiaomi aqara wall switch with two buttons
29 * @author Dieter Schmidt - Initial contribution
31 public class XiaomiAqaraActorSwitch2Handler extends XiaomiActorBaseHandler {
33 private final Logger logger = LoggerFactory.getLogger(XiaomiAqaraActorSwitch2Handler.class);
35 private static final String CHANNEL_0 = "channel_0";
36 private static final String CHANNEL_1 = "channel_1";
37 private static final String ON = "on";
39 public XiaomiAqaraActorSwitch2Handler(Thing thing) {
44 void execute(ChannelUID channelUID, Command command) {
45 String status = command.toString().toLowerCase();
46 switch (channelUID.getId()) {
47 case CHANNEL_SWITCH_CH0:
48 getXiaomiBridgeHandler().writeToDevice(getItemId(), new String[] { CHANNEL_0 },
49 new Object[] { status });
51 case CHANNEL_SWITCH_CH1:
52 getXiaomiBridgeHandler().writeToDevice(getItemId(), new String[] { CHANNEL_1 },
53 new Object[] { status });
56 // Only gets here, if no condition was met
57 logger.error("Can't handle command {} on channel {}", command, channelUID);
61 void parseReport(JsonObject data) {
66 void parseHeartbeat(JsonObject data) {
71 void parseReadAck(JsonObject data) {
76 void parseWriteAck(JsonObject data) {
77 logger.debug("Got write ack message but ignoring it to prevent item state toggling");
81 void parseDefault(JsonObject data) {
82 if (data.has(CHANNEL_0)) {
83 boolean isOn = ON.equalsIgnoreCase(data.get(CHANNEL_0).getAsString());
84 updateState(CHANNEL_SWITCH_CH0, OnOffType.from(isOn));
85 } else if (data.has(CHANNEL_1)) {
86 boolean isOn = ON.equalsIgnoreCase(data.get(CHANNEL_1).getAsString());
87 updateState(CHANNEL_SWITCH_CH1, OnOffType.from(isOn));