Search in sources :

Example 1 with IoTSetRequest

use of org.jivesoftware.smackx.iot.control.element.IoTSetRequest 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 IoTSetRequest

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

the class IoTControlManager method setUsingIq.

/**
     * Control a thing by sending a collection of {@link SetData} instructions.
     *
     * @param jid the thing to control.
     * @param data a collection of {@link SetData} instructions.
     * @return the {@link IoTSetResponse} if successful.
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException
     */
public IoTSetResponse setUsingIq(FullJid jid, Collection<? extends SetData> data) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    IoTSetRequest request = new IoTSetRequest(data);
    request.setTo(jid);
    IoTSetResponse response = connection().createStanzaCollectorAndSend(request).nextResultOrThrow();
    return response;
}
Also used : IoTSetRequest(org.jivesoftware.smackx.iot.control.element.IoTSetRequest) IoTSetResponse(org.jivesoftware.smackx.iot.control.element.IoTSetResponse)

Aggregations

IoTSetRequest (org.jivesoftware.smackx.iot.control.element.IoTSetRequest)2 ArrayList (java.util.ArrayList)1 IoTSetResponse (org.jivesoftware.smackx.iot.control.element.IoTSetResponse)1 SetBoolData (org.jivesoftware.smackx.iot.control.element.SetBoolData)1 SetData (org.jivesoftware.smackx.iot.control.element.SetData)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