/** 打开开关 */ public void setPlugOn(final CompletionHandler handler) throws MiotException { if (!mDevice.isConnectionEstablished()) { throw new MiotException("device not configurated connection"); } final ActionInfo actionInfo = ActionInfoFactory.create(getService(), ACTION_setPlugOn); if (actionInfo == null) { throw new MiotException("actionInfo is null"); } DeviceManipulator op = MiotManager.getDeviceManipulator(); op.invoke( actionInfo, new DeviceManipulator.InvokeCompletionHandler() { @Override public void onSucceed(ActionInfo info) { handler.onSucceed(); } @Override public void onFailed(final int errCode, final String description) { handler.onFailed(errCode, description); } }); }
/** 读取所有可读属性 */ public void getProperties(final GetPropertiesCompletionHandler handler) throws MiotException { if (!mDevice.isConnectionEstablished()) { throw new MiotException("device not configurated connection"); } PropertyInfo propertyInfo = PropertyInfoFactory.create(getService()); propertyInfo.addProperty(getService().getProperty(PROPERTY_UsbStatus)); propertyInfo.addProperty(getService().getProperty(PROPERTY_PowerStatus)); DeviceManipulator op = MiotManager.getDeviceManipulator(); op.readProperty( propertyInfo, new DeviceManipulator.ReadPropertyCompletionHandler() { @Override public void onSucceed(PropertyInfo info) { Boolean usbStatus = (Boolean) info.getValue(PROPERTY_UsbStatus); Boolean powerStatus = (Boolean) info.getValue(PROPERTY_PowerStatus); handler.onSucceed(usbStatus, powerStatus); } @Override public void onFailed(int errCode, String description) { handler.onFailed(errCode, description); } }); }