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.yeelight.internal.lib.device;
15 import org.openhab.binding.yeelight.internal.lib.device.connection.WifiConnection;
16 import org.openhab.binding.yeelight.internal.lib.enums.DeviceType;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import com.google.gson.JsonArray;
21 import com.google.gson.JsonObject;
22 import com.google.gson.JsonParser;
25 * The {@link MonoDevice} contains methods for handling the mono color device.
27 * @author Coaster Li - Initial contribution
29 public class MonoDevice extends DeviceBase {
30 private final Logger logger = LoggerFactory.getLogger(MonoDevice.class);
32 public MonoDevice(String id) {
34 mDeviceType = DeviceType.mono;
35 mConnection = new WifiConnection(this);
39 public void onNotify(String msg) {
40 JsonObject result = JsonParser.parseString(msg).getAsJsonObject();
42 if (result.has("id")) {
43 String id = result.get("id").getAsString();
44 // for cmd transaction.
46 if (mQueryList.contains(id)) {
47 mQueryList.remove(id);
48 // DeviceMethod(MethodAction.PROP, new Object[] { "power", "name", "bright" });
49 JsonArray status = result.get("result").getAsJsonArray();
52 if ("\"off\"".equals(status.get(0).toString())) {
53 mDeviceStatus.setPowerOff(true);
54 } else if ("\"on\"".equals(status.get(0).toString())) {
55 mDeviceStatus.setPowerOff(false);
59 mDeviceStatus.setName(status.get(1).getAsString());
62 mDeviceStatus.setBrightness(status.get(2).getAsInt());
65 } catch (Exception e) {
66 logger.debug("Exception", e);