-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[yeelight] Add basic support for yeelight desklamp #4453
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if we can catch a more specific exception type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, i only copied a other light and changed the needed lines.
I will have a look into that at the weekend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to catch this exception more specific, normaly this exception should not be thrown. I can remove this exception but i don't know if that is a better solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind. It seems to be the way how this binding handles it. Let's do not touch it though.