2 * Copyright (c) 2010-2022 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 DesklampDevice} contains methods for handling the desklamp device.
27 * @author Sebastian Rakel - Initial contribution
29 public class DesklampDevice extends DeviceBase {
30 private final Logger logger = LoggerFactory.getLogger(DesklampDevice.class);
32 public DesklampDevice(String id) {
34 mDeviceType = DeviceType.desklamp;
35 mConnection = new WifiConnection(this);
41 public void onNotify(String msg) {
42 JsonObject result = JsonParser.parseString(msg).getAsJsonObject();
44 if (result.has("id")) {
45 String id = result.get("id").getAsString();
46 // for cmd transaction.
48 if (mQueryList.contains(id)) {
49 mQueryList.remove(id);
50 // DeviceMethod(MethodAction.PROP, new Object[] { "power", "name", "bright", "ct" });
51 JsonArray status = result.get("result").getAsJsonArray();
54 if (status.get(0).toString().equals("\"off\"")) {
55 mDeviceStatus.setPowerOff(true);
56 } else if (status.get(0).toString().equals("\"on\"")) {
57 mDeviceStatus.setPowerOff(false);
61 mDeviceStatus.setName(status.get(1).getAsString());
64 mDeviceStatus.setBrightness(status.get(2).getAsInt());
67 mDeviceStatus.setCt(status.get(3).getAsInt());
70 } catch (Exception e) {
71 logger.debug("Problem setting values", e);