示例#1
0
    def testRequestSetOk(self):
        self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325'])

        myDevice = Device("Device22")
        myDevice._add_control_field(name="Temperature",
                                    typename="int",
                                    value="15")

        self.xmpp['xep_0325'].register_node(nodeId="Device22",
                                            device=myDevice,
                                            commTimeout=0.5)

        self.recv("""
            <iq type='set'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='1'>
                <set xmlns='urn:xmpp:iot:control'>
                    <int name="Temperature" value="17"/>
                </set>
            </iq>
        """)

        self.send("""
            <iq type='result'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='1'>
                <setResponse xmlns='urn:xmpp:iot:control' responseCode="OK" />
            </iq>
            """)

        self.assertEqual(myDevice._get_field_value("Temperature"), "17")
示例#2
0
    def testDirectSetOk(self):
        self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325'])

        myDevice = Device("Device22")
        myDevice._add_control_field(name="Temperature",
                                    typename="int",
                                    value="15")

        self.xmpp['xep_0325'].register_node(nodeId="Device22",
                                            device=myDevice,
                                            commTimeout=0.5)

        self.recv("""
            <message
                from='[email protected]/amr'
                to='*****@*****.**'>
                <set xmlns='urn:xmpp:iot:control'>
                    <int name="Temperature" value="17"/>
                </set>
            </message>
        """)

        time.sleep(0.5)

        self.assertEqual(myDevice._get_field_value("Temperature"), "17")
示例#3
0
    def testRequestSetOk(self):
        self.stream_start(mode='component',
                          plugins=['xep_0030',
                                   'xep_0325'])

        myDevice = Device("Device22");
        myDevice._add_control_field(name="Temperature", typename="int", value="15");

        self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5);

        self.recv("""
            <iq type='set'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='1'>
                <set xmlns='urn:xmpp:iot:control'>
                    <int name="Temperature" value="17"/>
                </set>
            </iq>
        """)

        self.send("""
            <iq type='result'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='1'>
                <setResponse xmlns='urn:xmpp:iot:control' responseCode="OK" />
            </iq>
            """)

        self.assertEqual(myDevice._get_field_value("Temperature"), "17");
示例#4
0
    def testRequestSetFail(self):
        self.stream_start(mode='component',
                          plugins=['xep_0030',
                                   'xep_0325'])

        myDevice = Device("Device23");
        myDevice._add_control_field(name="Temperature", typename="int", value="15");

        self.xmpp['xep_0325'].register_node(nodeId="Device23", device=myDevice, commTimeout=0.5);

        self.recv("""
            <iq type='set'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='9'>
                <set xmlns='urn:xmpp:iot:control'>
                    <int name="Voltage" value="17"/>
                </set>
            </iq>
        """)

        self.send("""
            <iq type='error'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='9'>
                <setResponse xmlns='urn:xmpp:iot:control' responseCode='NotFound'>
                    <parameter name='Voltage' />
                    <error var='Output'>Invalid field Voltage</error>
                </setResponse>
            </iq>
            """)

        self.assertEqual(myDevice._get_field_value("Temperature"), "15");
        self.assertFalse(myDevice.has_control_field("Voltage", "int"));
示例#5
0
    def testDirectSetFail(self):
        self.stream_start(mode='component',
                          plugins=['xep_0030',
                                   'xep_0325'])

        myDevice = Device("Device22");
        myDevice._add_control_field(name="Temperature", typename="int", value="15");

        self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5);

        self.recv("""
            <message
                from='[email protected]/amr'
                to='*****@*****.**'>
                <set xmlns='urn:xmpp:iot:control'>
                    <int name="Voltage" value="17"/>
                </set>
            </message>
        """)

        self.assertEqual(myDevice._get_field_value("Temperature"), "15");
        self.assertFalse(myDevice.has_control_field("Voltage", "int"));
示例#6
0
    def testRequestSetFail(self):
        self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325'])

        myDevice = Device("Device23")
        myDevice._add_control_field(name="Temperature",
                                    typename="int",
                                    value="15")

        self.xmpp['xep_0325'].register_node(nodeId="Device23",
                                            device=myDevice,
                                            commTimeout=0.5)

        self.recv("""
            <iq type='set'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='9'>
                <set xmlns='urn:xmpp:iot:control'>
                    <int name="Voltage" value="17"/>
                </set>
            </iq>
        """)

        self.send("""
            <iq type='error'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='9'>
                <setResponse xmlns='urn:xmpp:iot:control' responseCode='NotFound'>
                    <parameter name='Voltage' />
                    <error var='Output'>Invalid field Voltage</error>
                </setResponse>
            </iq>
            """)

        self.assertEqual(myDevice._get_field_value("Temperature"), "15")
        self.assertFalse(myDevice.has_control_field("Voltage", "int"))