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.QuantityType;
18 import org.openhab.core.thing.Thing;
20 import com.google.gson.JsonObject;
23 * Handles the Xiaomi temperature & humidity sensor
25 * @author Patrick Boos - Initial contribution
26 * @author Daniel Walters - Add pressure support
28 public class XiaomiSensorHtHandler extends XiaomiSensorBaseHandler {
30 private static final String HUMIDITY = "humidity";
31 private static final String TEMPERATURE = "temperature";
32 private static final String VOLTAGE = "voltage";
33 private static final String PRESSURE = "pressure";
35 public XiaomiSensorHtHandler(Thing thing) {
40 void parseReport(JsonObject data) {
45 void parseHeartbeat(JsonObject data) {
50 void parseReadAck(JsonObject data) {
55 void parseDefault(JsonObject data) {
56 if (data.has(HUMIDITY)) {
57 float humidity = data.get(HUMIDITY).getAsFloat() / 100;
58 updateState(CHANNEL_HUMIDITY, new QuantityType<>(humidity, PERCENT_UNIT));
60 if (data.has(TEMPERATURE)) {
61 float temperature = data.get(TEMPERATURE).getAsFloat() / 100;
62 updateState(CHANNEL_TEMPERATURE, new QuantityType<>(temperature, TEMPERATURE_UNIT));
64 if (data.has(VOLTAGE)) {
65 Integer voltage = data.get(VOLTAGE).getAsInt();
66 calculateBatteryLevelFromVoltage(voltage);
68 if (data.has(PRESSURE)) {
69 float pressure = (float) (data.get(PRESSURE).getAsFloat() / 1000.0);
70 updateState(CHANNEL_PRESSURE, new QuantityType<>(pressure, PRESSURE_UNIT));