def test_feature(self, address, unit, device_id, command, rssi):
        """ Do the tests 
            @param address : device address
            @param unit : device unit
            @param device_id : device id
            @param command
            @param rssi
        """

        # test 
        print(u"Device address = {0}".format(address))
        print(u"Device unit = {0}".format(unit))
        print(u"Device id = {0}".format(device_id))
        print(u"Check that a message with command = 'off' is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "ac.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"command" : command,
                                                  "address" : address,
                                                  "unit" : unit,
                                                  "rssi" : rssi},
                                          timeout = 60))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "open_close")
        print(sensor.get_last_value())
        #print("{0} VS {1}".format(sensor.get_last_value()[1], self.xpl_data.data['command']))
        from domogik_packages.plugin_rfxcom.conversion.from_off_on_to_DT_OpenClose import from_off_on_to_DT_OpenClose
        #print("{0} VS2 {1}".format(sensor.get_last_value()[1], from_off_on_to_DT_OpenClose(self.xpl_data.data['command'])))
        #print("{0} VS2 {1}".format(type(sensor.get_last_value()[1]), type(from_off_on_to_DT_OpenClose(self.xpl_data.data['command']))))
        # the data is converted to be inserted in database
        #self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['command'])
        self.assertTrue(int(sensor.get_last_value()[1]) == from_off_on_to_DT_OpenClose(self.xpl_data.data['command']))
    def test_0100_script(self):
        """ check if we receive the xpl-trig message and status is stored in database
            status is the value displayed as stdout
        """
        global devices
        command = "/var/lib/domogik/domogik_packages/plugin_script/tests/sample_string.sh"

        # test
        print (u"Command = {0}".format(command))
        print (u"Device id = {0}".format(devices[command]))

        print (u"Check that a message with the awaited string value is received")

        self.assertTrue(
            self.wait_for_xpl(
                xpltype="xpl-trig",
                xplschema="exec.basic",
                xplsource="domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                data={"type": "script_info_string", "command": command, "status": "a string"},
                timeout=60,
            )
        )
        print (u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "sensor_script_info_string")
        print (sensor.get_last_value())
        # the data is converted to be inserted in database
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data["status"])
    def test_0100_inbound_call(self):
        """ check if all the xpl messages for an inbound call is sent
            Example : 
            Sample messages : 
 
            xpl-trig : schema:cid.basic, data:{'calltype': 'inbound', 'phone' : '0102030405'}

        """
        global devices

        address = "/dev/ttyFAKE"
        device_id = devices[address]
        interval = 30

        print(u"Device address = {0}".format(address))
        print(u"Device id = {0}".format(device_id))
        print(u"Check that a message about inbound call is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "cid.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"calltype" : "inbound", 
                                                  "phone" : "0102030405"},
                                          timeout = interval))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "callerid")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['phone'])
    def test_0100_script(self):
        """ check if after a command is requested over rest, we receive the xpl-trig message and status is stored in database

        """
        global devices
        command = "/var/lib/domogik/domogik_packages/plugin_script/tests/sample_action.sh"
 

        # test 
        print(u"Command = {0}".format(command))
        print(u"Device id = {0}".format(devices[command]))

        # trigger command
        print(u"Call REST to send an '{0}'  command".format(1))
        tc = TestCommand(device_id, "cmd_script_action")
        # send command
        #tc.send_command(1)   # 1 is high
        tc.send_command({'status' : 1})   # 1 is high
        print(u"Check that a message with command = 'high' is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "exec.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"type" : "script_action",
                                                  "command" : command,
                                                  "status" : "executed"},
                                          timeout = 60))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "sensor_script_action")
        print(sensor.get_last_value())
        from domogik_packages.plugin_script.conversion.from_executed_to_DT_Trigger import from_executed_to_DT_Trigger
        # the data is converted to be inserted in database
        self.assertTrue(int(sensor.get_last_value()[1]) == from_executed_to_DT_Trigger(self.xpl_data.data['status']))
Beispiel #5
0
    def test_0100_ctrl_status(self):
        """ check if all the xpl messages for an inbound call is sent
            Example :
            Sample messages :

            xpl-trig : schema:cid.basic, data:{'calltype': 'inbound', 'phone' : '0102030405'}
        """
        global networkid
        global driver
        global device_id
        global timer_status

        r = subprocess.check_output('ps aux | grep ozwave', shell=True)
        print(u"----- Process : {0}".format(r))

        r = subprocess.check_output('ps aux', shell=True)
        print(u"----- ALL Process : {0}".format(r))

        data = {"ctrl-status": 1}
        self.assertTrue(
            self.wait_for_mq(device_id=device_id,
                             data=data,
                             timeout=timer_status * 2))
        time.sleep(1)
        print(
            u"Check that the values of the MQ message has been inserted in database"
        )
        sensor = TestSensor(device_id, "ctrl-status")
        self.assertTrue(sensor.get_last_value()[1] == str(data['ctrl-status']))
Beispiel #6
0
    def test_0100_ping_on(self):
        """ check if all the xpl messages for a device up is sent
            Example : 
            xpl-trig : schema:sensor.basic, data:{'type': 'input', 'current': 'high', 'device': 127.0.00.1'}
        """
        global devices

        address = "127.0.0.1"

        # test
        print(u"Device address = {0}".format(address))
        print(u"Device id = {0}".format(devices[address]))
        print(u"Check that a message with current = 'high' is sent.")

        self.assertTrue(
            self.wait_for_xpl(xpltype="xpl-stat",
                              xplschema="sensor.basic",
                              xplsource="domogik-{0}.{1}".format(
                                  self.name, get_sanitized_hostname()),
                              data={
                                  "type": "input",
                                  "device": address,
                                  "current": "high"
                              },
                              timeout=10))
        print(
            u"Check that the value of the xPL message has been inserted in database"
        )
        sensor = TestSensor(devices[address], "ping")
        print(sensor.get_last_value())
        from domogik_packages.plugin_ping.conversion.from_low_high_to_DT_Switch import from_low_high_to_DT_Switch
        # the data is converted to be inserted in database
        self.assertTrue(
            int(sensor.get_last_value()[1]) == from_low_high_to_DT_Switch(
                self.xpl_data.data['current']))
    def test_feature(self, address, unit, device_id, command, rest_command):
        """ Do the tests 
            @param address : device address
            @param unit : device unit
            @param device_id : device id
            @param command
            @param rest_command
        """

        # test 
        print(u"Device address = {0}".format(address))
        print(u"Device unit = {0}".format(unit))
        print(u"Device id = {0}".format(device_id))

        print(u"Call REST to send an '{0}'  command".format(rest_command))
        tc = TestCommand(device_id, "switch_lighting2")
        # send command
        tc.send_command(rest_command)
        print(u"Check that a message with command = 'off' is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "ac.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"command" : command,
                                                  "address" : address,
                                                  "unit" : unit},
                                          timeout = 60))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "switch_lighting2")
        print(sensor.get_last_value())
        from domogik_packages.plugin_rfxcom.conversion.from_off_on_to_DT_Switch import from_off_on_to_DT_Switch
        # the data is converted to be inserted in database
        self.assertTrue(int(sensor.get_last_value()[1]) == from_off_on_to_DT_Switch(self.xpl_data.data['command']))
 def test_0110_device_sensors(self):
     """ Test if the RFPlayer sensor infoType 4 5 6 7 9 is sent when a frame is received
     """
     for device in self.sensorsTest:
         Printc.infob(
             u"Check that a MQ message for all the sensors of device <{0}> id <{1}> are sent."
             .format(device['name'], device['device_id']))
         data = {}
         for value in device['values']:
             # do the test
             Printc.infob(
                 u"Check that a MQ message for the sensor <{0}> frame received is sent."
                 .format(value["sensor"]))
             data[value["sensor"]] = value["value"]
         self.assertTrue(
             self.wait_for_mq(device_id=device['device_id'],
                              data=data,
                              timeout=device['timeout']))
         time.sleep(1)
         for value in device['values']:
             Printc.infob(
                 u"Check that the values of the MQ message for the sensor <{0}> has been inserted in database"
                 .format(value["sensor"]))
             sensor = TestSensor(device['device_id'], value["sensor"])
             self.assertTrue(
                 sensor.get_last_value()[1] == str(value["value"]))
Beispiel #9
0
    def test_0101_ping_off(self):
        """ check if all the xpl messages for a device off is sent
            Example : 
            xpl-trig : schema:sensor.basic, data:{'type': 'input', 'current': 'low', 'device': 1.1.1.1'}
        """
        global devices

        address = "1.1.1.1"

        # test
        print(u"Device address = {0}".format(address))
        print(u"Device id = {0}".format(devices[address]))
        print(u"Check that a message with current = 'low' is sent.")

        self.assertTrue(
            self.wait_for_xpl(
                xpltype="xpl-stat",
                xplschema="sensor.basic",
                xplsource="domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                data={"type": "input", "device": address, "current": "low"},
                timeout=20,
            )
        )
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(devices[address], "ping")
        print(sensor.get_last_value())
        from domogik_packages.plugin_ping.conversion.from_low_high_to_DT_Switch import from_low_high_to_DT_Switch

        # the data is converted to be inserted in database
        print(int(sensor.get_last_value()[1]))
        print(from_low_high_to_DT_Switch(self.xpl_data.data["current"]))
        self.assertTrue(int(sensor.get_last_value()[1]) == from_low_high_to_DT_Switch(self.xpl_data.data["current"]))
    def test_0100_type20_smoke_sensor(self):
        """ check if all the xpl messages for a smoke sensor are sent
            Example : 
            Rfxcom trame : 200325b67e000650
            Sample messages : 
            xpl-trig : schema:x10.security, data:{'device': '0xb67e00', 'type': 'cn', 'command': 'panic'}
            xpl-trig : schema:x10.security, data:{'device': '0xb67e00', 'type': 'cn', 'command': 'normal'}

        """
        global devices
        address = "0xb67e00"
        device_id = devices[address]
        interval = 30

        print (u"Device address = {0}".format(address))
        print (u"Device id = {0}".format(device_id))
        print (u"Check that a message about alarm triger is sent.")

        self.assertTrue(
            self.wait_for_xpl(
                xpltype="xpl-trig",
                xplschema="x10.security",
                xplsource="domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                data={"type": "cn", "device": address, "command": "panic"},
                timeout=interval,
            )
        )
        print (u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "smoke")
        last_value = int(sensor.get_last_value()[1])
        self.assertTrue(last_value == from_normal_panic_to_DT_Switch(self.xpl_data.data["command"]))

        # chekc the "normal" message when alarm is finished (manually handled by the plugin 2 seconds after the
        # panic message
        print (u"Check that a message about end of alarm triger is sent.")

        self.assertTrue(
            self.wait_for_xpl(
                xpltype="xpl-trig",
                xplschema="x10.security",
                xplsource="domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                data={"type": "cn", "device": address, "command": "normal"},
                timeout=interval,
            )
        )
        print (u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "smoke")
        last_value = int(sensor.get_last_value()[1])
        self.assertTrue(last_value == from_normal_panic_to_DT_Switch(self.xpl_data.data["command"]))
Beispiel #11
0
 def _get_sensors_ref(self, statResult):
     """Return the sensor_ref stucture of an xpl_stat_ack of the command.
         return dict :
             sensor : TestSensor object
             name : sensor_reference
             param : a dict with key and value to check
     """
     sensorsRef = []
     xplStat = self.get_XplStat_id()
     if xplStat:
         #         print "dynamic params : {0}".format(self._device['xpl_stats'][xplStat]['parameters']['dynamic'])
         for aparam in self._device['xpl_stats'][xplStat]['parameters'][
                 'dynamic']:
             # Check if sensor exist
             for sensorId in self._device['sensors']:
                 if aparam['sensor_name'] == sensorId:
                     dynParam = {}
                     for k in statResult:
                         if aparam['key'] == k:
                             dynParam[k] = statResult[k]
                             break
                     sensor = TestSensor(self.device_id, sensorId)
                     sensorsRef.append({
                         'sensor': sensor,
                         'name': aparam['sensor_name'],
                         'param': dynParam
                     })
     return sensorsRef
    def test_0100_position(self):
        """ check if the xpl messages about total space are OK
            Sample message : 
            xpl-stat
            {
            hop=1
            source=domogik-geoloc.darkstar
            target=*
            }
            sensor.basic
            {
            device=test_device_geoloc
            type=position_degrees
            current=3,3
            }
        """
        global device_name
        global device_id
        global cfg

        # call he plugin url in a thread
        url = "http://{0}:{1}/position/{2}/{3}".format(cfg['host'], cfg['port'], device_name, "3,3")
        thr_url = Thread(None,
                         call_url,
                         "url",
                         (url,),
                         {})
        thr_url.start()

        # do the test
        # the 60s interval allows to launch the url call to geoloc plugin in a thread
        print(u"Check that a message about position is sent in less than 60 seconds")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-stat",
                                          xplschema = "sensor.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"type" : "position_degrees", 
                                                  "device" : device_name,
                                                  "current" : "3,3"},
                                          timeout = 60))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "position_degrees")
        print(sensor.get_last_value())
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['current'])
    def do_tests(self):
        global device
        global device_id

        # do the test
        print(u"Check that a MQ message for the frame received is sent.")

        data = {"rfp_status": 1}
        self._plugintest.assertTrue(
            self._plugintest.wait_for_mq(device_id=device_id,
                                         data=data,
                                         timeout=timer_status * 4))
        time.sleep(1)
        print(
            u"Check that the values of the MQ message has been inserted in database"
        )
        sensor = TestSensor(device_id, "rfp_status")
        self._plugintest.assertTrue(
            sensor.get_last_value()[1] == str(data['rfp_status']))
    def test_feature(self, address, unit, device_id, command, rssi):
        """ Do the tests 
            @param address : device address
            @param unit : device unit
            @param device_id : device id
            @param command
            @param rssi
        """

        # test
        print(u"Device address = {0}".format(address))
        print(u"Device unit = {0}".format(unit))
        print(u"Device id = {0}".format(device_id))
        print(u"Check that a message with command = 'off' is sent.")

        self.assertTrue(
            self.wait_for_xpl(xpltype="xpl-trig",
                              xplschema="ac.basic",
                              xplsource="domogik-{0}.{1}".format(
                                  self.name, get_sanitized_hostname()),
                              data={
                                  "command": command,
                                  "address": address,
                                  "unit": unit,
                                  "rssi": rssi
                              },
                              timeout=60))
        print(
            u"Check that the value of the xPL message has been inserted in database"
        )
        sensor = TestSensor(device_id, "open_close")
        print(sensor.get_last_value())
        #print("{0} VS {1}".format(sensor.get_last_value()[1], self.xpl_data.data['command']))
        from domogik_packages.plugin_rfxcom.conversion.from_off_on_to_DT_OpenClose import from_off_on_to_DT_OpenClose
        #print("{0} VS2 {1}".format(sensor.get_last_value()[1], from_off_on_to_DT_OpenClose(self.xpl_data.data['command'])))
        #print("{0} VS2 {1}".format(type(sensor.get_last_value()[1]), type(from_off_on_to_DT_OpenClose(self.xpl_data.data['command']))))
        # the data is converted to be inserted in database
        #self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['command'])
        self.assertTrue(
            int(sensor.get_last_value()[1]) == from_off_on_to_DT_OpenClose(
                self.xpl_data.data['command']))
    def test_0100_type20_smoke_sensor(self):
        """ check if all the xpl messages for a smoke sensor are sent
            Example : 
            Rfxcom trame : 200325b67e000650
            Sample messages : 
            xpl-trig : schema:x10.security, data:{'device': '0xb67e00', 'type': 'cn', 'command': 'panic'}
            xpl-trig : schema:x10.security, data:{'device': '0xb67e00', 'type': 'cn', 'command': 'normal'}

        """
        global devices
        address = "0xb67e00"
        device_id = devices[address]
        interval = 30

        print(u"Device address = {0}".format(address))
        print(u"Device id = {0}".format(device_id))
        print(u"Check that a message about alarm triger is sent.")

        self.assertTrue(
            self.wait_for_xpl(xpltype="xpl-trig",
                              xplschema="x10.security",
                              xplsource="domogik-{0}.{1}".format(
                                  self.name, get_sanitized_hostname()),
                              data={
                                  "type": "cn",
                                  "device": address,
                                  "command": "panic"
                              },
                              timeout=interval))
        print(
            u"Check that the value of the xPL message has been inserted in database"
        )
        sensor = TestSensor(device_id, "smoke")
        last_value = int(sensor.get_last_value()[1])
        self.assertTrue(last_value == from_normal_panic_to_DT_Switch(
            self.xpl_data.data['command']))

        # chekc the "normal" message when alarm is finished (manually handled by the plugin 2 seconds after the
        # panic message
        print(u"Check that a message about end of alarm triger is sent.")

        self.assertTrue(
            self.wait_for_xpl(xpltype="xpl-trig",
                              xplschema="x10.security",
                              xplsource="domogik-{0}.{1}".format(
                                  self.name, get_sanitized_hostname()),
                              data={
                                  "type": "cn",
                                  "device": address,
                                  "command": "normal"
                              },
                              timeout=interval))
        print(
            u"Check that the value of the xPL message has been inserted in database"
        )
        sensor = TestSensor(device_id, "smoke")
        last_value = int(sensor.get_last_value()[1])
        self.assertTrue(last_value == from_normal_panic_to_DT_Switch(
            self.xpl_data.data['command']))
Beispiel #16
0
    def test_0100_wol(self):
        """ check if after a command is requested over rest, we receive the xpl-trig message and status is sotred in database

        """
        global devices
        global wol_port
 
        mac = "112233445566"
        port = 9


        # test 
        print(u"Device mac address = {0}".format(mac))
        print(u"Device port = {0}".format(port))
        print(u"Device id = {0}".format(devices[mac]))

        print(u"Call REST to send an '{0}'  command".format(1))
        tc = TestCommand(device_id, "wol")
        # send command
        #tc.send_command(1)   # 1 is high
        tc.send_command({'current' : 1})   # 1 is high
        print(u"Check that a message with command = 'high' is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "sensor.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"device" : mac,
                                                  "port" : port,
                                                  "type" : "wakeonlan",
                                                  "current" : "high"},
                                          timeout = 60))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "wol")
        print(sensor.get_last_value())
        from domogik_packages.plugin_wol.conversion.from_high_to_DT_Trigger import from_high_to_DT_Trigger
        # the data is converted to be inserted in database
        self.assertTrue(int(sensor.get_last_value()[1]) == from_high_to_DT_Trigger(self.xpl_data.data['current']))
    def test_0100_rfplayer(self):
        """ Test if the RFPlayer sensor is sent when a frame is received
        """
        global timer_status
        global device
        global device_id

        self.testDevices = []

        # do the test
        Printc.infob(
            u"Check that a MQ message for RFPlayer status started is sent.")

        data = {"rfp_status": 1}
        self.assertTrue(
            self.wait_for_mq(device_id=device_id,
                             data=data,
                             timeout=timer_status * 2))
        time.sleep(1)
        Printc.infob(
            u"Check that the values of the MQ message has been inserted in database"
        )
        sensor = TestSensor(device_id, "rfp_status")
        self.assertTrue(sensor.get_last_value()[1] == str(data['rfp_status']))
    def test_feature(self, address, device_id, interval, temperature, battery, rssi):
        """ Do the tests 
            @param address : device address
            @param device_id : device id
            @param interval : timeout (max time before we assume the message is not sent)
            @param temperature
            @param battery
            @param rssi
        """

        # test temperature
        print(u"Device address = {0}".format(address))
        print(u"Device id = {0}".format(device_id))
        print(u"Check that a message about temperature is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "sensor.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"type" : "temp", 
                                                  "device" : address,
                                                  "current" : temperature},
                                          timeout = interval))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "temperature")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['current'])

        # test battery
        print(u"Check that a message about battery is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "sensor.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"type" : "battery", 
                                                  "device" : address,
                                                  "current" : battery},
                                          timeout = interval))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "battery")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['current'])

        # test rssi
        print(u"Check that a message about rssi is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "sensor.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"type" : "rssi", 
                                                  "device" : address,
                                                  "current" : rssi},
                                          timeout = interval))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "rssi")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['current'])
    def test_0100_script(self):
        """ 
            Two tests will be done with an interval of 1 minute. The script binary will return the number of minutes % 2
            => 0 for a pair minute
            => 1 for an impair minute
        """
        global devices
        command = "/var/lib/domogik/domogik_packages/plugin_script/tests/sample_binary.sh"
 

        # test 
        print(u"Command = {0}".format(command))
        print(u"Device id = {0}".format(devices[command]))

        print(u"Check that a message with the awaited binary value is received")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "exec.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"type" : "script_info_binary",
                                                  "command" : command},
                                          timeout = 60))
        waited_value = datetime.now().minute % 2
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "sensor_script_info_binary")
        print(sensor.get_last_value())
        # the data is converted to be inserted in database
        self.assertTrue(int(sensor.get_last_value()[1]) == waited_value)


        # second message
        print(u"Check that a second message with the awaited binary value is received")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "exec.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"type" : "script_info_binary",
                                                  "command" : command},
                                          timeout = 60))
        waited_value = datetime.now().minute % 2
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "sensor_script_info_binary")
        print(sensor.get_last_value())
        # the data is converted to be inserted in database
        self.assertTrue(int(sensor.get_last_value()[1]) == waited_value)
    def test_0100_hphc(self):
        """ Test if the teleinfo.basic schema is sent when a frame is received
        """
        global interval
        global device
        global device_id

        # do the test
        print(u"Check that a xPL message for the frame received is sent.")

        self.assertTrue(
            self.wait_for_xpl(xpltype="xpl-stat",
                              xplschema="teleinfo.basic",
                              xplsource="domogik-{0}.{1}".format(
                                  self.name, get_sanitized_hostname()),
                              data={
                                  "adco": "030928084432",
                                  "optarif": "HC..",
                                  "isousc": "45",
                                  "hchc": "024073045",
                                  "hchp": "030297217",
                                  "ptec": "HP..",
                                  "iinst": "001",
                                  "imax": "048",
                                  "papp": "00300",
                                  "hhphc": "D",
                                  "motdetat": "000000"
                              },
                              timeout=interval * 60))
        time.sleep(1)
        print(
            u"Check that the values of the xPL message has been inserted in database"
        )
        sensor = TestSensor(device_id, "adco")
        self.assertTrue(
            sensor.get_last_value()[1] == self.xpl_data.data['adco'])
        sensor = TestSensor(device_id, "optarif")
        self.assertTrue(
            sensor.get_last_value()[1] == self.xpl_data.data['optarif'])
        sensor = TestSensor(device_id, "isousc")
        self.assertTrue(
            sensor.get_last_value()[1] == self.xpl_data.data['isousc'])
        sensor = TestSensor(device_id, "hchc")
        self.assertTrue(
            sensor.get_last_value()[1] == self.xpl_data.data['hchc'])
        sensor = TestSensor(device_id, "hchp")
        self.assertTrue(
            sensor.get_last_value()[1] == self.xpl_data.data['hchp'])
        sensor = TestSensor(device_id, "ptec")
        self.assertTrue(
            sensor.get_last_value()[1] == self.xpl_data.data['ptec'])
        sensor = TestSensor(device_id, "iinst")
        self.assertTrue(
            sensor.get_last_value()[1] == self.xpl_data.data['iinst'])
        sensor = TestSensor(device_id, "imax")
        self.assertTrue(
            sensor.get_last_value()[1] == self.xpl_data.data['imax'])
        sensor = TestSensor(device_id, "papp")
        self.assertTrue(
            sensor.get_last_value()[1] == self.xpl_data.data['papp'])
        sensor = TestSensor(device_id, "hhphc")
        self.assertTrue(
            sensor.get_last_value()[1] == self.xpl_data.data['hhphc'])
        sensor = TestSensor(device_id, "motdetat")
        self.assertTrue(
            sensor.get_last_value()[1] == self.xpl_data.data['motdetat'])
    def test_0100_hphc(self):
        """ Test if the teleinfo.basic schema is sent when a frame is received
        """
        global interval
        global device
        global device_id

        # do the test
        print(u"Check that a xPL message for the frame received is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-stat",
                                          xplschema = "teleinfo.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"adco" : "030928084432",
                                                  "optarif" : "HC..",
                                                  "isousc" : "45",
                                                  "hchc" : "024073045",
                                                  "hchp" : "030297217",
                                                  "ptec" : "HP..",
                                                  "iinst" : "001",
                                                  "imax" : "048",
                                                  "papp" : "00300",
                                                  "hhphc" : "D",
                                                  "motdetat" : "000000"},
                                          timeout = interval * 60))
        time.sleep(1)
        print(u"Check that the values of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "adco")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['adco'])
        sensor = TestSensor(device_id, "optarif")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['optarif'])
        sensor = TestSensor(device_id, "isousc")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['isousc'])
        sensor = TestSensor(device_id, "hchc")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['hchc'])
        sensor = TestSensor(device_id, "hchp")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['hchp'])
        sensor = TestSensor(device_id, "ptec")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['ptec'])
        sensor = TestSensor(device_id, "iinst")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['iinst'])
        sensor = TestSensor(device_id, "imax")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['imax'])
        sensor = TestSensor(device_id, "papp")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['papp'])
        sensor = TestSensor(device_id, "hhphc")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['hhphc'])
        sensor = TestSensor(device_id, "motdetat")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['motdetat'])
Beispiel #22
0
    def test_0100_hphc(self):
        """ Test if the teleinfo.basic schema is sent when a frame is received
        """
        global interval
        global device
        global device_id

        # do the test
        print(u"Check that a MQ message for the frame received is sent.")
        
        data = {"adco" : "030928084432",
                "optarif" : "hc..",
                "isousc" : "45",
                "hchc" : "024073045",
                "hchp" : "030297217",
                "ptec" : "hp..",
                "iinst" : "001",
                "imax" : "048",
                "papp" : "00300",
                "hhphc" : "d",
                "motdetat" : "000000"}
        self.assertTrue(self.wait_for_mq( device_id = device_id,
                                          data = data,
                                          timeout = interval * 60))
        time.sleep(1)
        print(u"Check that the values of the MQ message has been inserted in database")
        sensor = TestSensor(device_id, "adco")
        self.assertTrue(sensor.get_last_value()[1] == data['adco'])
        sensor = TestSensor(device_id, "optarif")
        self.assertTrue(sensor.get_last_value()[1] == data['optarif'])
        sensor = TestSensor(device_id, "isousc")
        self.assertTrue(sensor.get_last_value()[1] == data['isousc'])
        sensor = TestSensor(device_id, "hchc")
        self.assertTrue(sensor.get_last_value()[1] == data['hchc'])
        sensor = TestSensor(device_id, "hchp")
        self.assertTrue(sensor.get_last_value()[1] == data['hchp'])
        sensor = TestSensor(device_id, "ptec")
        self.assertTrue(sensor.get_last_value()[1] == data['ptec'])
        sensor = TestSensor(device_id, "iinst")
        self.assertTrue(sensor.get_last_value()[1] == data['iinst'])
        sensor = TestSensor(device_id, "imax")
        self.assertTrue(sensor.get_last_value()[1] == data['imax'])
        sensor = TestSensor(device_id, "papp")
        self.assertTrue(sensor.get_last_value()[1] == data['papp'])
        sensor = TestSensor(device_id, "hhphc")
        self.assertTrue(sensor.get_last_value()[1] == data['hhphc'])
        sensor = TestSensor(device_id, "motdetat")
        self.assertTrue(sensor.get_last_value()[1] == data['motdetat'])
    def test_feature(self, address, device_id, interval, temperature, humidity, humidity_desc, battery, rssi):
        """ Do the tests 
            @param address : device address
            @param device_id : device id
            @param interval : timeout (max time before we assume the message is not sent)
            @param temperature
            @param humidity
            @param humidity_desc
            @param battery
            @param rssi
        """

        # test temperature
        print(u"Device address = {0}".format(address))
        print(u"Device id = {0}".format(device_id))
        print(u"Check that a message about temperature is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "sensor.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"type" : "temp", 
                                                  "device" : address,
                                                  "current" : temperature},
                                          timeout = interval))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "temperature")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['current'])

        # test humidity
        print(u"Check that a message about humidity is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "sensor.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"type" : "humidity", 
                                                  "device" : address,
                                                  "current" : humidity},
                                          timeout = interval))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "humidity")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['current'])

        # test battery
        print(u"Check that a message about battery is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "sensor.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"type" : "battery", 
                                                  "device" : address,
                                                  "current" : battery},
                                          timeout = interval))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "battery")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['current'])

        # test rssi
        print(u"Check that a message about rssi is sent.")
        
        self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                                          xplschema = "sensor.basic",
                                          xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                                          data = {"type" : "rssi", 
                                                  "device" : address,
                                                  "current" : rssi},
                                          timeout = interval))
        print(u"Check that the value of the xPL message has been inserted in database")
        sensor = TestSensor(device_id, "rssi")
        self.assertTrue(sensor.get_last_value()[1] == self.xpl_data.data['current'])