]> git.basschouten.com Git - openhab-addons.git/blob
8e4341213e6eb98f8dc64a0cc90a8b3bfd8e9e17
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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_DENSITY;
16
17 import java.util.HashMap;
18 import java.util.Map;
19
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.thing.Thing;
22
23 import com.google.gson.JsonObject;
24
25 /**
26  * Handles the Xiaomi smoke sensor
27  *
28  * @author Dieter Schmidt - Initial contribution
29  */
30 public class XiaomiSensorSmokeHandler extends XiaomiSensorBaseAlarmHandler {
31
32     private static final Map<Integer, String> ALARM_STATUS_MAP = new HashMap<>();
33
34     private static final String DENSITY = "density";
35
36     static {
37         ALARM_STATUS_MAP.put(0, "OK");
38         ALARM_STATUS_MAP.put(1, "Fire alarm");
39         ALARM_STATUS_MAP.put(2, "Analog alarm");
40         ALARM_STATUS_MAP.put(8, "Battery fault alarm");
41         ALARM_STATUS_MAP.put(64, "Sensitivity fault alarm");
42         ALARM_STATUS_MAP.put(32768, "I2C communication failure");
43     }
44
45     public XiaomiSensorSmokeHandler(Thing thing) {
46         super(thing);
47     }
48
49     @Override
50     void parseReport(JsonObject data) {
51         super.parseReport(data);
52         if (data.has(DENSITY)) {
53             Integer density = data.get(DENSITY).getAsInt();
54             updateState(CHANNEL_DENSITY, new DecimalType(density));
55         }
56     }
57 }