Search in sources :

Example 1 with SetData

use of org.jivesoftware.smackx.iot.control.element.SetData in project Smack by igniterealtime.

the class IoTSetRequestProvider method parse.

@Override
public IoTSetRequest parse(XmlPullParser parser, int initialDepth) throws Exception {
    List<SetData> data = new ArrayList<>(4);
    outerloop: while (true) {
        final int eventType = parser.next();
        final String name = parser.getName();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                switch(name) {
                    case "bool":
                        {
                            String valueName = parser.getAttributeValue(null, "name");
                            String valueString = parser.getAttributeValue(null, "value");
                            boolean value = Boolean.parseBoolean(valueString);
                            data.add(new SetBoolData(valueName, value));
                        }
                        break;
                    case "double":
                        {
                            String valueName = parser.getAttributeValue(null, "name");
                            String valueString = parser.getAttributeValue(null, "value");
                            double value = Double.parseDouble(valueString);
                            data.add(new SetDoubleData(valueName, value));
                        }
                        break;
                    case "int":
                        {
                            String valueName = parser.getAttributeValue(null, "name");
                            String valueString = parser.getAttributeValue(null, "value");
                            int value = Integer.parseInt(valueString);
                            data.add(new SetIntData(valueName, value));
                        }
                        break;
                    case "long":
                        {
                            String valueName = parser.getAttributeValue(null, "name");
                            String valueString = parser.getAttributeValue(null, "value");
                            long value = Long.parseLong(valueString);
                            data.add(new SetLongData(valueName, value));
                        }
                        break;
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return new IoTSetRequest(data);
}
Also used : SetIntData(org.jivesoftware.smackx.iot.control.element.SetIntData) SetLongData(org.jivesoftware.smackx.iot.control.element.SetLongData) ArrayList(java.util.ArrayList) SetBoolData(org.jivesoftware.smackx.iot.control.element.SetBoolData) SetData(org.jivesoftware.smackx.iot.control.element.SetData) IoTSetRequest(org.jivesoftware.smackx.iot.control.element.IoTSetRequest) SetDoubleData(org.jivesoftware.smackx.iot.control.element.SetDoubleData)

Example 2 with SetData

use of org.jivesoftware.smackx.iot.control.element.SetData in project Smack by igniterealtime.

the class IoTControlIntegrationTest method controlTest.

/**
     * Connection one provides a thing, which is controlled by connection two.
     *
     * @throws Exception 
     * @throws TimeoutException 
     */
@SmackIntegrationTest
public // @SmackSerialIntegrationTest
void controlTest() throws TimeoutException, Exception {
    final String key = StringUtils.randomString(12);
    final String sn = StringUtils.randomString(12);
    final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
    Thing controlThing = Thing.builder().setKey(key).setSerialNumber(sn).setControlRequestHandler(new ThingControlRequest() {

        @Override
        public void processRequest(Jid from, Collection<SetData> setData) throws XMPPErrorException {
            if (!from.equals(conTwo.getUser())) {
                return;
            }
            for (final SetData data : setData) {
                if (!data.getName().equals(testRunId))
                    continue;
                if (!(data instanceof SetBoolData))
                    continue;
                SetBoolData boolData = (SetBoolData) data;
                if (boolData.getBooleanValue()) {
                    syncPoint.signal();
                    break;
                }
            }
        }
    }).build();
    IoTControlManagerOne.installThing(controlThing);
    try {
        RosterIntegrationTest.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
        SetData data = new SetBoolData(testRunId, true);
        IoTSetResponse response = IoTControlManagerTwo.setUsingIq(conOne.getUser(), data);
        assertNotNull(response);
    } finally {
        IoTControlManagerOne.uninstallThing(controlThing);
        RosterIntegrationTest.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
    }
    syncPoint.waitForResult(timeout);
}
Also used : Jid(org.jxmpp.jid.Jid) ThingControlRequest(org.jivesoftware.smackx.iot.control.ThingControlRequest) Collection(java.util.Collection) SetBoolData(org.jivesoftware.smackx.iot.control.element.SetBoolData) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) SetData(org.jivesoftware.smackx.iot.control.element.SetData) IoTSetResponse(org.jivesoftware.smackx.iot.control.element.IoTSetResponse) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Aggregations

SetBoolData (org.jivesoftware.smackx.iot.control.element.SetBoolData)2 SetData (org.jivesoftware.smackx.iot.control.element.SetData)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)1 SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)1 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)1 ThingControlRequest (org.jivesoftware.smackx.iot.control.ThingControlRequest)1 IoTSetRequest (org.jivesoftware.smackx.iot.control.element.IoTSetRequest)1 IoTSetResponse (org.jivesoftware.smackx.iot.control.element.IoTSetResponse)1 SetDoubleData (org.jivesoftware.smackx.iot.control.element.SetDoubleData)1 SetIntData (org.jivesoftware.smackx.iot.control.element.SetIntData)1 SetLongData (org.jivesoftware.smackx.iot.control.element.SetLongData)1 Jid (org.jxmpp.jid.Jid)1