]> git.basschouten.com Git - openhab-addons.git/blob
121abc759db321f7a81e28c273a146ae7aabc379
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.CHANNEL_LEAK;
16
17 import org.openhab.core.library.types.OnOffType;
18 import org.openhab.core.thing.Thing;
19
20 import com.google.gson.JsonObject;
21
22 /**
23  * Handles the Xiaomi water leak sensor
24  *
25  * @author Kuba Wolanin - Initial contribution
26  */
27 public class XiaomiSensorWaterHandler extends XiaomiSensorBaseHandler {
28
29     private static final String STATUS = "status";
30     private static final String LEAK = "leak";
31
32     @Override
33     void parseReport(JsonObject data) {
34         boolean leak = data.has(STATUS) && LEAK.equals(data.get(STATUS).getAsString());
35
36         if (leak) {
37             updateState(CHANNEL_LEAK, OnOffType.ON);
38         } else {
39             updateState(CHANNEL_LEAK, OnOffType.OFF);
40         }
41     }
42
43     public XiaomiSensorWaterHandler(Thing thing) {
44         super(thing);
45     }
46 }