All device can generate it's own status. The Status object define the item in general, and allow developer to change it's status.
package yourBundle; import com.infairy.cocina.SDK.gene.StatusImpl; ... public class WeightMeter implements BundleActivator{ .... } public void changeMyStatus(int kg){ /* * device id, alway use bundle id */ String deviceID=BundleID; StatusImpl status=new StatusImpl(deviceID); try { /* * channel is indicate different value from, default is 1 * if you have multi-channel, you can change the channel value and set different Value */ status.setData(StatusInterface.channel, "1"); /* * device alias */ status.setData(StatusInterface.DeviceAlias, "MyWeight")); /* * device value type, refer to com.infairy.cocina.SDK.DevicePool.DEVICE_VALUE_TYPE_xxx * value type must defined in the Infairy. */ status.setData(StatusInterface.DeviceType, device.DEVICE_VALUE_TYPE_BODYWEIGHT); /* * device value */ status.setData(StatusInterface.Value, kg); /* * unit , please refer to com.infairy.cocina.SDK.DevicePool.DEVICE_VALUE_UNIT_xxx */ status.setData(StatusInterface.Unit, device.DEVICE_VALUE_UNIT_Kg); /* * add status */ device.addStatus(status); } catch (StatusException e1) { } }How to get status, just do as follows:
/* * get status by device id */ StatusImpl[] Status=device.STATUS(deviceID); for(int m=0; m < Status.length; m++){ String channel=Status[m].getData(StatusInterface.channel); String Value=Status[m].getData(StatusInterface.Value); String Unit=Status[m].getData(StatusInterface.Unit); .... }Now, you learned how to set and get status.
but, if you want to let IFTTT object can get the status by value changed, you have to modify some code:
/* * get prevoius value & unit from the status */ StatusImpl[] oldStatus=device.STATUS(deviceID); String oldValue="", oldUnit=""; if(oldStatus!=null){ for(int m=0; m < oldStatus.length; m++){ String channel=oldStatus[m].getData(StatusInterface.channel); if(channel.equals(CHANNEL)){ oldValue=oldStatus[m].getData(StatusInterface.Value); oldUnit=oldStatus[m].getData(StatusInterface.Unit); break; } } } /* * set previous value and unit */ StatusImpl status=new StatusImpl(deviceID); try { status.setData(StatusInterface.Value, kg); status.setData(StatusInterface.Unit, device.DEVICE_VALUE_UNIT_Kg); /* * previous value */ status.setData(StatusInterface.preValue, oldValue); /* * previous unit , please refer to com.infairy.cocina.SDK.DevicePool.DEVICE_VALUE_UNIT_xxx */ status.setData(StatusInterface.preUnit, oldUnit); .... } catch (StatusException e1) { }Then, the IFTTT can be done by different value.