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.CHANNEL_SWITCH_CH0;
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 one button
29 * @author Dieter Schmidt - Initial contribution
31 public class XiaomiAqaraActorSwitch1Handler extends XiaomiActorBaseHandler {
33 private final Logger logger = LoggerFactory.getLogger(XiaomiAqaraActorSwitch1Handler.class);
35 private static final String CHANNEL_0 = "channel_0";
36 private static final String ON = "on";
38 public XiaomiAqaraActorSwitch1Handler(Thing thing) {
43 void execute(ChannelUID channelUID, Command command) {
44 if (CHANNEL_SWITCH_CH0.equals(channelUID.getId())) {
45 String status = command.toString().toLowerCase();
46 getXiaomiBridgeHandler().writeToDevice(getItemId(), new String[] { CHANNEL_0 }, new Object[] { status });
49 // Only gets here, if no condition was met
50 logger.error("Can't handle command {} on channel {}", command, channelUID);
54 void parseReport(JsonObject data) {
59 void parseHeartbeat(JsonObject data) {
64 void parseReadAck(JsonObject data) {
69 void parseWriteAck(JsonObject data) {
70 logger.debug("Got write ack message but ignoring it to prevent item state toggling");
74 void parseDefault(JsonObject data) {
75 if (data.has(CHANNEL_0)) {
76 boolean isOn = ON.equals(data.get(CHANNEL_0).getAsString().toLowerCase());
77 updateState(CHANNEL_SWITCH_CH0, isOn ? OnOffType.ON : OnOffType.OFF);