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.DateTimeType;
18 import org.openhab.core.library.types.DecimalType;
19 import org.openhab.core.thing.Thing;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 import com.google.gson.JsonObject;
26 * Handles the Xiaomi Aqara Smart Motion Vibration Sensor
28 * @author Dieter Schmidt - Initial contribution
30 public class XiaomiSensorVibrationHandler extends XiaomiSensorBaseHandler {
32 private final Logger logger = LoggerFactory.getLogger(XiaomiSensorVibrationHandler.class);
33 private static final String STATUS = "status";
34 private static final String TILT_ANGLE = "final_tilt_angle";
35 private static final String ORIENTATIONS = "coordination";
36 private static final String BED_ACTIVITY = "bed_activity";
38 public XiaomiSensorVibrationHandler(Thing thing) {
43 void parseReport(JsonObject data) {
44 if (data.has(STATUS)) {
45 triggerChannel(CHANNEL_ACTION, data.get(STATUS).getAsString().toUpperCase());
46 updateState(CHANNEL_LAST_ACTION, new DateTimeType());
47 } else if (data.has(TILT_ANGLE)) {
48 updateState(CHANNEL_TILT_ANGLE, new DecimalType(Integer.parseInt((data.get(TILT_ANGLE).getAsString()))));
49 } else if (data.has(ORIENTATIONS)) {
54 x = Integer.parseInt((data.get(ORIENTATIONS).getAsString().split(",")[0]));
55 y = Integer.parseInt((data.get(ORIENTATIONS).getAsString().split(",")[1]));
56 z = Integer.parseInt((data.get(ORIENTATIONS).getAsString().split(",")[2]));
57 } catch (NumberFormatException e) {
58 logger.error("Could not parse coordinates", e);
60 updateState(CHANNEL_ORIENTATION_X, new DecimalType(x));
61 updateState(CHANNEL_ORIENTATION_Y, new DecimalType(y));
62 updateState(CHANNEL_ORIENTATION_Z, new DecimalType(z));
63 } else if (data.has(BED_ACTIVITY)) {
64 updateState(CHANNEL_BED_ACTIVITY,
65 new DecimalType(Integer.parseInt((data.get(BED_ACTIVITY).getAsString()))));