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.enums.ActiveMode;
16 import org.openhab.binding.yeelight.internal.lib.enums.DeviceType;
17 import org.openhab.binding.yeelight.internal.lib.enums.MethodAction;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 import com.google.gson.JsonArray;
22 import com.google.gson.JsonObject;
23 import com.google.gson.JsonParser;
26 * The {@link CeilingDeviceWithNightDevice} contains methods for handling the ceiling device with ambient light.
28 * @author Nikita Pogudalov - Initial contribution
30 public class CeilingDeviceWithNightDevice extends CeilingDevice implements DeviceWithNightlight {
31 private final Logger logger = LoggerFactory.getLogger(CeilingDeviceWithNightDevice.class);
33 public CeilingDeviceWithNightDevice(String id) {
36 mDeviceType = DeviceType.ceiling1;
40 public void onNotify(String msg) {
41 logger.debug("Got state: {}", msg);
43 JsonObject result = JsonParser.parseString(msg).getAsJsonObject();
45 if (result.has("id")) {
46 String id = result.get("id").getAsString();
47 // for cmd transaction.
49 if (mQueryList.contains(id)) {
50 JsonArray status = result.get("result").getAsJsonArray();
52 final int activeMode = status.get(8).getAsInt();
53 mDeviceStatus.setActiveMode(ActiveMode.values()[activeMode]);
61 public void toggleNightlightMode(boolean turnOn) {
64 new DeviceMethod(MethodAction.SCENE, new Object[] { "nightlight", mDeviceStatus.getBrightness() }));
66 mConnection.invoke(MethodFactory.buildCTMethod(mDeviceStatus.getCt(), DeviceMethod.EFFECT_SMOOTH, 500));