java lf_Java LFXLight.setPower方法代碼示例

import com.github.besherman.lifx.LFXLight; //導入方法依賴的package包/類

@Override

public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,

Integer targetBri, Integer targetBriInc, ColorData colorData, DeviceDescriptor device, String body) {

String theReturn = null;

float aBriValue;

float theValue;

log.debug("executing HUE api request to send message to LifxDevice: " + anItem.getItem().toString());

if(!validLifx) {

log.warn("Should not get here, no LifxDevice clients configured");

theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId

+ "\",\"description\": \"Should not get here, no LifxDevices configured\", \"parameter\": \"/lights/"

+ lightId + "state\"}}]";

} else {

LifxEntry lifxCommand = null;

if(anItem.getItem().isJsonObject())

lifxCommand = aGsonHandler.fromJson(anItem.getItem(), LifxEntry.class);

else

lifxCommand = aGsonHandler.fromJson(anItem.getItem().getAsString(), LifxEntry.class);

LifxDevice theDevice = getLifxDevice(lifxCommand.getName());

if (theDevice == null) {

log.warn("Should not get here, no LifxDevices available");

theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId

+ "\",\"description\": \"Should not get here, no Lifx clients available\", \"parameter\": \"/lights/"

+ lightId + "state\"}}]";

} else {

log.debug("calling LifxDevice: " + lifxCommand.getName());

if(theDevice.getType().equals(LifxDevice.LIGHT_TYPE)) {

LFXLight theLight = (LFXLight)theDevice.getLifxObject();

if(body.contains("true"))

theLight.setPower(true);

if(body.contains("false"))

theLight.setPower(false);

if(targetBri != null || targetBriInc != null) {

aBriValue = (float)BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc);

theValue = aBriValue/DIM_DIVISOR;

if(theValue > (float)1.0)

theValue = (float)0.99;

theLight.setBrightness(theValue);

}

} else if (theDevice.getType().equals(LifxDevice.GROUP_TYPE)) {

LFXGroup theGroup = (LFXGroup)theDevice.getLifxObject();

if(body.contains("true"))

theGroup.setPower(true);

if(body.contains("false"))

theGroup.setPower(false);

}

}

}

return theReturn;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值