-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[yeelight] Add basic support for yeelight desklamp (#4453)
* Add basic support for yeelight desklamp Fixes #4452 Signed-off-by: Sebastian Rakel <[email protected]>
- Loading branch information
1 parent
18622e6
commit b83b6ae
Showing
10 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
addons/binding/org.openhab.binding.yeelight/ESH-INF/thing/desklamp.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<thing:thing-descriptions bindingId="yeelight" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:thing="http://eclipse.org/smarthome/schemas/thing-description/v1.0.0" | ||
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/thing-description/v1.0.0 http://eclipse.org/smarthome/schemas/thing-description-1.0.0.xsd"> | ||
|
||
<thing-type id="desklamp"> | ||
<label>Yeelight MI LED Desk Lamp</label> | ||
<description>Yeelight MI LED Desk Lamp</description> | ||
|
||
<channels> | ||
<channel id="brightness" typeId="brightness" /> | ||
<channel id="colorTemperature" typeId="colorTemperature" /> | ||
</channels> | ||
|
||
<config-description> | ||
<parameter name="deviceId" type="text" required="true"> | ||
<label>Device ID</label> | ||
<description>Id of the Yeelight device to connect with.</description> | ||
</parameter> | ||
</config-description> | ||
</thing-type> | ||
</thing:thing-descriptions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...elight/src/main/java/org/openhab/binding/yeelight/internal/lib/device/DesklampDevice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Copyright (c) 2010-2019 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.yeelight.internal.lib.device; | ||
|
||
import org.openhab.binding.yeelight.internal.lib.device.connection.WifiConnection; | ||
import org.openhab.binding.yeelight.internal.lib.enums.DeviceType; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
|
||
/** | ||
* The {@link DesklampDevice} contains methods for handling the desklamp device. | ||
* | ||
* @author Sebastian Rakel - Initial contribution | ||
*/ | ||
public class DesklampDevice extends DeviceBase { | ||
private final Logger logger = LoggerFactory.getLogger(DesklampDevice.class); | ||
|
||
public DesklampDevice(String id) { | ||
super(id); | ||
mDeviceType = DeviceType.desklamp; | ||
mConnection = new WifiConnection(this); | ||
mMinCt = 2700; | ||
mMaxCt = 6500; | ||
} | ||
|
||
@Override | ||
public void onNotify(String msg) { | ||
JsonObject result = new JsonParser().parse(msg).getAsJsonObject(); | ||
try { | ||
String id = "-1"; | ||
if (result.has("id")) { | ||
id = result.get("id").getAsString(); | ||
// for cmd transaction. | ||
|
||
if (mQueryList.contains(id)) { | ||
mQueryList.remove(id); | ||
// DeviceMethod(MethodAction.PROP, new Object[] { "power", "name", "bright", "ct" }); | ||
JsonArray status = result.get("result").getAsJsonArray(); | ||
|
||
// power: | ||
if (status.get(0).toString().equals("\"off\"")) { | ||
mDeviceStatus.setPowerOff(true); | ||
} else if (status.get(0).toString().equals("\"on\"")) { | ||
mDeviceStatus.setPowerOff(false); | ||
} | ||
|
||
// name: | ||
mDeviceStatus.setName(status.get(1).getAsString()); | ||
|
||
// brightness: | ||
mDeviceStatus.setBrightness(status.get(2).getAsInt()); | ||
|
||
// ct: | ||
mDeviceStatus.setCt(status.get(3).getAsInt()); | ||
} | ||
} | ||
} catch (Exception e) { | ||
logger.debug("Problem setting values: {}", e); | ||
} | ||
|
||
super.onNotify(msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,6 @@ public enum DeviceType { | |
ceiling, | ||
ceiling1, | ||
ceiling3, | ||
stripe | ||
stripe, | ||
desklamp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters