forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[yeelight] Add support for yeelight 650 with ambient light (Closes #6… (
openhab#6749) * [yeelight] Add support for yeelight 650 with ambient light (Closes openhab#6227) Signed-off-by: Viktor Koop <[email protected]>
- Loading branch information
Showing
30 changed files
with
889 additions
and
197 deletions.
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
...java/org/openhab/binding/yeelight/internal/handler/YeelightCeilingWithAmbientHandler.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,59 @@ | ||
/** | ||
* Copyright (c) 2010-2020 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.handler; | ||
|
||
import org.eclipse.smarthome.core.library.types.DecimalType; | ||
import org.eclipse.smarthome.core.library.types.HSBType; | ||
import org.eclipse.smarthome.core.library.types.OnOffType; | ||
import org.eclipse.smarthome.core.library.types.PercentType; | ||
import org.eclipse.smarthome.core.thing.ChannelUID; | ||
import org.eclipse.smarthome.core.thing.Thing; | ||
import org.eclipse.smarthome.core.types.Command; | ||
import org.openhab.binding.yeelight.internal.YeelightBindingConstants; | ||
import org.openhab.binding.yeelight.internal.lib.device.DeviceStatus; | ||
import org.openhab.binding.yeelight.internal.lib.enums.ActiveMode; | ||
|
||
/** | ||
* The {@link YeelightCeilingWithAmbientHandler} is responsible for handling commands, which are | ||
* sent to one of the channels. | ||
* | ||
* @author Viktor Koop - Initial contribution | ||
*/ | ||
public class YeelightCeilingWithAmbientHandler extends YeelightCeilingHandler { | ||
|
||
public YeelightCeilingWithAmbientHandler(Thing thing) { | ||
super(thing); | ||
} | ||
|
||
@Override | ||
public void handleCommand(ChannelUID channelUID, Command command) { | ||
handleCommandHelper(channelUID, command, "Handle ceiling ambient light command"); | ||
} | ||
|
||
@Override | ||
protected void updateUI(DeviceStatus status) { | ||
super.updateUI(status); | ||
|
||
if (status.isBackgroundIsPowerOff()) { | ||
updateState(YeelightBindingConstants.CHANNEL_BACKGROUND_COLOR, PercentType.ZERO); | ||
} else { | ||
final HSBType hsbType = new HSBType(new DecimalType(status.getBackgroundHue()), | ||
new PercentType(status.getBackgroundSat()), new PercentType(status.getBackgroundBrightness())); | ||
|
||
updateState(YeelightBindingConstants.CHANNEL_BACKGROUND_COLOR, hsbType); | ||
} | ||
|
||
updateState(YeelightBindingConstants.CHANNEL_NIGHTLIGHT, | ||
(status.getActiveMode() == ActiveMode.MOONLIGHT_MODE) ? OnOffType.ON : OnOffType.OFF); | ||
} | ||
} |
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
105 changes: 105 additions & 0 deletions
105
...java/org/openhab/binding/yeelight/internal/lib/device/CeilingDeviceWithAmbientDevice.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,105 @@ | ||
/** | ||
* Copyright (c) 2010-2020 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.enums.ActiveMode; | ||
import org.openhab.binding.yeelight.internal.lib.enums.DeviceType; | ||
import org.openhab.binding.yeelight.internal.lib.enums.MethodAction; | ||
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 CeilingDeviceWithAmbientDevice} contains methods for handling the ceiling device with ambient light. | ||
* | ||
* @author Viktor Koop - Initial contribution | ||
*/ | ||
public class CeilingDeviceWithAmbientDevice extends CeilingDevice | ||
implements DeviceWithAmbientLight, DeviceWithNightlight { | ||
private final Logger logger = LoggerFactory.getLogger(CeilingDeviceWithAmbientDevice.class); | ||
|
||
public CeilingDeviceWithAmbientDevice(String id) { | ||
super(id); | ||
|
||
mDeviceType = DeviceType.ceiling4; | ||
} | ||
|
||
@Override | ||
public void onNotify(String msg) { | ||
logger.debug("Got state: {}", msg); | ||
|
||
JsonObject result = new JsonParser().parse(msg).getAsJsonObject(); | ||
|
||
if (result.has("id")) { | ||
String id = result.get("id").getAsString(); | ||
// for cmd transaction. | ||
|
||
if (mQueryList.contains(id)) { | ||
JsonArray status = result.get("result").getAsJsonArray(); | ||
|
||
final String backgroundPowerState = status.get(4).toString(); | ||
if ("\"off\"".equals(backgroundPowerState)) { | ||
mDeviceStatus.setBackgroundIsPowerOff(true); | ||
} else if ("\"on\"".equals(backgroundPowerState)) { | ||
mDeviceStatus.setBackgroundIsPowerOff(false); | ||
} | ||
|
||
final int backgroundBrightness = status.get(5).getAsInt(); | ||
mDeviceStatus.setBackgroundBrightness(backgroundBrightness); | ||
|
||
final int backgroundHue = status.get(6).getAsInt(); | ||
mDeviceStatus.setBackgroundHue(backgroundHue); | ||
|
||
final int backgroundSaturation = status.get(7).getAsInt(); | ||
mDeviceStatus.setBackgroundSat(backgroundSaturation); | ||
|
||
final int activeMode = status.get(8).getAsInt(); | ||
mDeviceStatus.setActiveMode(ActiveMode.values()[activeMode]); | ||
} | ||
} | ||
|
||
super.onNotify(msg); | ||
|
||
} | ||
|
||
@Override | ||
public void setBackgroundColor(int hue, int saturation, int duration) { | ||
mConnection | ||
.invoke(MethodFactory.buildBackgroundHSVMethod(hue, saturation, DeviceMethod.EFFECT_SMOOTH, duration)); | ||
} | ||
|
||
@Override | ||
public void setBackgroundBrightness(int brightness, int duration) { | ||
mConnection | ||
.invoke(MethodFactory.buildBackgroundBrightnessMethd(brightness, DeviceMethod.EFFECT_SMOOTH, duration)); | ||
} | ||
|
||
@Override | ||
public void setBackgroundPower(boolean on, int duration) { | ||
mConnection.invoke(new DeviceMethod(MethodAction.BG_SWITCH, | ||
new Object[] { on ? "on" : "off", DeviceMethod.EFFECT_SMOOTH, duration })); | ||
} | ||
|
||
@Override | ||
public void toggleNightlightMode(boolean turnOn) { | ||
if (turnOn) { | ||
mConnection.invoke( | ||
new DeviceMethod(MethodAction.SCENE, new Object[] { "nightlight", mDeviceStatus.getBrightness() })); | ||
} else { | ||
mConnection.invoke(MethodFactory.buildCTMethod(mDeviceStatus.getCt(), DeviceMethod.EFFECT_SMOOTH, 500)); | ||
} | ||
} | ||
} |
Oops, something went wrong.