Esempio n. 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")
Esempio n. 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(.5)

        self.assertEqual(myDevice._get_field_value("Temperature"), "17")
Esempio n. 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");
Esempio n. 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"));
Esempio n. 5
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(.5)

        self.assertEqual(myDevice._get_field_value("Temperature"), "17");
Esempio n. 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"))
 def __init__(self, nodeId):
     SensorDevice.__init__(self, nodeId)
     ControlDevice.__init__(self, nodeId)
     self.counter = 0
     self.relay = 0