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']))
示例#2
0
 def test_0010_configure_the_plugin(self):
     # first, clean the plugin configuration
     print(u"Delete the current plugin configuration")
     self.assertTrue(delete_configuration("plugin", self.name, get_sanitized_hostname()))
     for key in self.configuration:
         print(u"Set up configuration : {0} = {1}".format(key, self.configuration[key]))
         self.assertTrue(configure("plugin", self.name, get_sanitized_hostname(), key, self.configuration[key]))
     for key in self.configuration:
         print(u"Validate the configuration : {0} = {1}".format(key, self.configuration[key]))
         self.assertTrue(check_config("plugin", self.name, get_sanitized_hostname(), key, self.configuration[key]))
示例#3
0
    def query(self, type, name, key=None):
        '''
        Ask the config system for the value. Calling this function will make
        your program wait until it got an answer

        @param type : the client type
        @param name : the client name of the item requesting the value, must exists in the config database
        @param key : the key to fetch corresponding value
        @return : the value if key != None
                  a dictionnary will all keys/values if key = None
        '''
        msg = MQMessage()
        msg.set_action('config.get')
        msg.add_data('type', type)
        msg.add_data('name', name)
        msg.add_data('host', get_sanitized_hostname())
        if key != None:
            msg.add_data('key', key)
        else:
            key = "*"
        self._log.info("Request query config for client {0} : key {1}".format(
            name, key))
        ret = self.cli.request('dbmgr', msg.get(), timeout=QUERY_CONFIG_WAIT)

        ### no response from dbmgr
        if ret is None:
            self._log.error(
                "Query config for client {0} on host {1}, key {2} : no response from dbmgr"
                .format(name, get_sanitized_hostname(), key))
            return None

        ### response from dbmgr
        else:
            dat = ret.get_data()
            if dat['status']:
                self._log.debug(
                    "Query config : successfull response : {0}".format(ret))
                if key == "*":
                    return dat['data']
                else:
                    val = dat['value']
                    # do some cast
                    if val == "None":
                        val = None
                    return val
            else:
                self._log.error(
                    "Query config : error returned. Reason : {0}".format(
                        dat['reason']))
                return None
    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"]))
示例#5
0
    def query(self, type, name, key=None):
        """
        Ask the config system for the value. Calling this function will make
        your program wait until it got an answer

        @param type : the client type
        @param name : the client name of the item requesting the value, must exists in the config database
        @param key : the key to fetch corresponding value
        @return : the value if key != None
                  a dictionnary will all keys/values if key = None
        """
        msg = MQMessage()
        msg.set_action("config.get")
        msg.add_data("type", type)
        msg.add_data("name", name)
        msg.add_data("host", get_sanitized_hostname())
        if key != None:
            msg.add_data("key", key)
        else:
            key = "*"
        self._log.info("Request query config for client {0} : key {1}".format(name, key))
        ret = self.cli.request("dbmgr", msg.get(), timeout=QUERY_CONFIG_WAIT)

        ### no response from dbmgr
        if ret is None:
            self._log.error(
                "Query config for client {0} on host {1}, key {2} : no response from dbmgr".format(
                    name, get_sanitized_hostname(), key
                )
            )
            return None

        ### response from dbmgr
        else:
            dat = ret.get_data()
            if dat["status"]:
                self._log.debug("Query config : successfull response : {0}".format(ret))
                if key == "*":
                    return dat["data"]
                else:
                    val = dat["value"]
                    # do some cast
                    if val == "None":
                        val = None
                    return val
            else:
                self._log.error("Query config : error returned. Reason : {0}".format(dat["reason"]))
                return None
    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"])
示例#7
0
    def query(self, plugin, key, element='', nb_test=QUERY_CONFIG_NUM_TRY):
        '''
        Ask the config system for the value. Calling this function will make
        your program wait until it got an answer

        @param plugin : the plugin of the item requesting the value,
        must exists in the config database
        @param element : the name of the element which requests config, None if
        it's a technolgy global parameter
        @param key : the key to fetch corresponding value, if it's an empty string,
        all the config items for this technology will be fetched
        '''
        msg = MQMessage()
        msg._action = 'config.get'
        msg._data = {
            'plugin': plugin,
            'key': key,
            'element': element,
            'hostname': get_sanitized_hostname()
        }
        ret = self.cli.request('dbmgr', msg.get(), timeout=QUERY_CONFIG_WAIT)
        if ret is None:
            return None
        else:
            if 'value' in ret._data.keys():
                return ret._data['value']
            else:
                return None
示例#8
0
    def get_sanitized_hostname(self):
        """ Get the sanitized hostname of the host 
        This will lower it and keep only the part before the first dot

        """
        #return gethostname().lower().split('.')[0].replace('-','')[0:16]
        return get_sanitized_hostname()
示例#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"]))
示例#10
0
    def get_sanitized_hostname(self):
        """ Get the sanitized hostname of the host 
        This will lower it and keep only the part before the first dot

        """
        #return gethostname().lower().split('.')[0].replace('-','')[0:16]
        return get_sanitized_hostname()
示例#11
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']))
示例#12
0
 def test_0010_configure_the_plugin(self):
     # first, clean the plugin configuration
     print(u"Delete the current plugin configuration")
     self.assertTrue(
         delete_configuration("plugin", self.name,
                              get_sanitized_hostname()))
     for key in self.configuration:
         print(u"Set up configuration : {0} = {1}".format(
             key, self.configuration[key]))
         self.assertTrue(
             configure("plugin", self.name, get_sanitized_hostname(), key,
                       self.configuration[key]))
     for key in self.configuration:
         print(u"Validate the configuration : {0} = {1}".format(
             key, self.configuration[key]))
         self.assertTrue(
             check_config("plugin", self.name, get_sanitized_hostname(),
                          key, self.configuration[key]))
def create_device():
    ### create the device, and if ok, get its id in device_id
    print(u"Creating the vigilocation device...")
    td = TestDevice()
    td.create_device("plugin", plugin, get_sanitized_hostname(), "test_vigilocation", "vigilightning.vigilocation")
    td.configure_global_parameters({"latitude " : "46.739868", "longitude" : "2.328084",
                "criticalradius" : 1, "nearbyradius" : 3, "approachradius" : 5,
                "releasetimes" : 3})
    print "Device vigilocation configured"
示例#14
0
    def __init__(self):
        ### init zmq
        zmqc = zmq.Context()

        ### init logger
        loginst = logger.Logger('butler')
        log = loginst.get_logger('butler')

        self.qry = QueryMQ(zmqc, log, get_sanitized_hostname())
示例#15
0
    def __init__(self):
        ### init zmq
        zmqc = zmq.Context() 

        ### init logger
        loginst = logger.Logger('butler')
        log = loginst.get_logger('butler')

        self.qry = QueryMQ(zmqc, log, get_sanitized_hostname())
示例#16
0
 def test_9900_hbeat(self):
     print(
         u"Check that a heartbeat is sent. This could take up to 5 minutes."
     )
     self.assertTrue(
         self.wait_for_xpl(xpltype="xpl-stat",
                           xplschema="hbeat.app",
                           xplsource="domogik-{0}.{1}".format(
                               self.name, get_sanitized_hostname()),
                           timeout=600))
示例#17
0
def get_openzwave_all_products(abort = False):
    data = {u'data': [], u'error': u''}
    if not abort :
        cli = MQSyncReq(app.zmq_context)
        msg = MQMessage()
        msg.set_action('ozwave.openzwave.getallproducts')
        res = cli.request('plugin-ozwave.{0}'.format(get_sanitized_hostname()), msg.get(), timeout=10)
        if res is not None:
            data = res.get_data()
        else : data['error'] =  u'Plugin timeout response.'
    return data
示例#18
0
def get_manager_status(abort = False):
    data = {u'status': u'dead', u'rfPlayers': [], u'error': u''}
    if not abort :
        cli = MQSyncReq(app.zmq_context )
        msg = MQMessage()
        msg.set_action('rfplayer.manager.getstatus')
        res = cli.request('plugin-rfplayer.{0}'.format(get_sanitized_hostname()), msg.get(), timeout=10)
        if res is not None:
            data = res.get_data()
        else : data['error'] =  u'Plugin timeout response.'
    return data
 def send_xplTrig(self, data):
     """ Send xPL fake message on network
     """
     global xpl_plugin
     
     msg = XplMessage()
     msg.set_type("xpl-trig")
     msg.set_header(source ="domogik-{0}.{1}".format(self.name, get_sanitized_hostname()))
     msg.set_schema("sensor.basic")
     msg.add_data(data)
     print (u"send fake xpl switch on : {0}".format(msg))
     xpl_plugin.myxpl.send(msg)
 def assert_Xpl_Stat_Ack_Wait(self, xplMsg) :
     """Assert a xpltrig for waiting a switch state"""
     print(u"Check that a message about xpl stat ack is sent. The message must be received once time.")
     schema,  data = xplMsg
     print "schema" , schema
     print "data", data
     self.assertTrue(self.wait_for_xpl(xpltype = "xpl-trig",
                               xplschema = schema,
                               xplsource = "domogik-{0}.{1}".format(self.name, get_sanitized_hostname()),
                               data = data,
                               timeout = 60))
     print "listener ack running"
示例#21
0
def get_openzwave_info(abort = False):
    data = {u'status': u'dead', u'PYOZWLibVers':u'unknown', u'ConfigPath': u'undefined', 'uUserPath': u'not init',
                u'Options' : {},
                u'error': u''}
    if not abort :
        cli = MQSyncReq(app.zmq_context)
        msg = MQMessage()
        msg.set_action('ozwave.openzwave.get')
        res = cli.request('plugin-ozwave.{0}'.format(get_sanitized_hostname()), msg.get(), timeout=10)
        if res is not None:
            data = res.get_data()
        else : data['error'] =  u'Plugin timeout response.'
    return data
示例#22
0
def get_controller_nodes(NetworkID, abort = False):
    data = { u'nodes': [],
                u'error': u''}
    if not abort :
        cli = MQSyncReq(app.zmq_context)
        msg = MQMessage()
        msg.set_action('ozwave.ctrl.nodes')
        msg.add_data('NetworkID', NetworkID)
        res = cli.request('plugin-ozwave.{0}'.format(get_sanitized_hostname()), msg.get(), timeout=10)
        if res is not None:
            data = res.get_data()
        else : data['error'] =  u'Plugin timeout response.'
    return data
示例#23
0
    def send_xplTrig(self, data):
        """ Send xPL fake message on network
        """
        global xpl_plugin

        msg = XplMessage()
        msg.set_type("xpl-trig")
        msg.set_header(source="domogik-{0}.{1}".format(
            self.name, get_sanitized_hostname()))
        msg.set_schema("sensor.basic")
        msg.add_data(data)
        print(u"send fake xpl switch on : {0}".format(msg))
        xpl_plugin.myxpl.send(msg)
示例#24
0
def create_device():
    ### create the device, and if ok, get its id in device_id
    client_id  = "plugin-{0}.{1}".format(plugin, get_sanitized_hostname())
    print("Creating the irtrans device...")
    td = TestDevice()
    params = td.get_params(client_id, "irtrans.irtrans_lan")
        # fill in the params
    params["device_type"] = "irtrans.irtrans_lan"
    params["name"] = "test_IRTrans_LAN"
    params["reference"] = "IRTrans Lan client"
    params["description"] = "Handle IRTrans modul"
    for idx, val in enumerate(params['global']):
        if params['global'][idx]['key'] == 'ir_coder' :  params['global'][idx]['value'] = ENCODER
        if params['global'][idx]['key'] == 'server_path' :  params['global'][idx]['value'] = DEVICE_PATH
        if params['global'][idx]['key'] == 'ip_server' :  params['global'][idx]['value'] = DEVICE_IP_SERVER
        if params['global'][idx]['key'] == 'irtrans_ip' :  params['global'][idx]['value'] = DEVICE_IP_IRTRANS

    for idx, val in enumerate(params['xpl']):
        params['xpl'][idx]['value'] = DEVICE_NAME

    # go and create
    td.create_device(params)
    print "Device IRTrans Lan {0} configured".format(DEVICE_NAME) 
    
    print("Creating the irwsserver device...")
    td = TestDevice()
    params = td.get_params(client_id, "irtrans.irwsserver")
        # fill in the params
    params["device_type"] = "irtrans.irwsserver"
    params["name"] = "test_IRTrans_WS"
    params["reference"] = "IR WebSockect client"
    params["description"] = "Handle IR WebSockect modul"
    for idx, val in enumerate(params['global']):
        if params['global'][idx]['key'] == 'ir_coder' :  params['global'][idx]['value'] = ENCODER
        elif params['global'][idx]['key'] == 'ip_server' :  params['global'][idx]['value'] = DEVICE2_IP_SERVER
        elif params['global'][idx]['key'] == 'port_server' :  params['global'][idx]['value'] = DEVICE2_PORT_SERVER
        elif params['global'][idx]['key'] == 'ssl_activate' :  params['global'][idx]['value'] = DEVICE2_SSL
        elif params['global'][idx]['key'] == 'ssl_certificate' :  params['global'][idx]['value'] = DEVICE2_CERTIFICATE
        elif params['global'][idx]['key'] == 'ssl_key' :  params['global'][idx]['value'] = DEVICE2_KEY
        elif params['global'][idx]['key'] == 'ir_repeat' :  params['global'][idx]['value'] = 3
        elif params['global'][idx]['key'] == 'ir_tolerance' :  params['global'][idx]['value'] = 150
        elif params['global'][idx]['key'] == 'ir_large_tolerance' :  params['global'][idx]['value'] = 300
        elif params['global'][idx]['key'] == 'ir_max_out' :  params['global'][idx]['value'] = 10

    for idx, val in enumerate(params['xpl']):
        params['xpl'][idx]['value'] = DEVICE2_NAME

    # go and create
    td.create_device(params)
    print "Device irwsserver {0} configured".format(DEVICE2_NAME) 
def create_device():
    ### create the device, and if ok, get its id in device_id
    client_id = "plugin-{0}.{1}".format(plugin, get_sanitized_hostname())
    print "Creating the SMS  device..."
    td = TestDevice()
    params = td.get_params(client_id, "notify.smsweb")
    # fill in the params
    params["device_type"] = "notify.smsweb"
    params["name"] = DEVICE_NAME
    params["reference"] = "reference"
    params["description"] = "description"
    for idx, val in enumerate(params['global']):
        if params['global'][idx]['key'] == 'operator':
            params['global'][idx]['value'] = OPERATOR
        if params['global'][idx]['key'] == 'login':
            params['global'][idx]['value'] = OP_LOGIN
        if params['global'][idx]['key'] == 'pwd':
            params['global'][idx]['value'] = OP_PWD

    for idx, val in enumerate(params['xpl']):
        params['xpl'][idx]['value'] = PHONE_TEL

    # go and create
    td.create_device(params)
    print "Device SMS {0} configured".format(DEVICE_NAME_NOTIFRY)

    print("Creating the Newtifry  device...")
    td = TestDevice()
    params = td.get_params(client_id, "notify.newtifry")
    # fill in the params
    params["device_type"] = "notify.newtifry"
    params["name"] = DEVICE_NAME_NOTIFRY
    params["reference"] = "reference"
    params["description"] = "description"
    for idx, val in enumerate(params['global']):
        if params['global'][idx]['key'] == 'sourcekey':
            params['global'][idx]['value'] = SOURCE_KEY
        if params['global'][idx]['key'] == 'defaulttitle':
            params['global'][idx]['value'] = 'Test message'
        if params['global'][idx]['key'] == 'backend':
            params['global'][idx]['value'] = BACKEND

    for idx, val in enumerate(params['xpl']):
        params['xpl'][idx]['value'] = TO

    # go and create
    td.create_device(params)

    print "Device Newtifry {0} configured".format(DEVICE_NAME_NOTIFRY)
示例#26
0
def get_controller_state(NetworkID, abort = False):
    data = {u'NetworkID': u'unknown', u'Node': 1, u'Init_state': u'unknown', u'Node count': 0, u'Protocol': u'unknown',
                u'Node sleeping': 0, u'ListNodeId': [], u'Library': u'undefined', u'state': u'dead', u'Version': u'undefined',
                u'HomeID': u'undefined', u'Primary controller': u'undefined', u'Model': u'undefined', u'Poll interval': 0,
                u'error': u''}
    if not abort :
        cli = MQSyncReq(app.zmq_context)
        msg = MQMessage()
        msg.set_action('ozwave.ctrl.get')
        msg.add_data('NetworkID', NetworkID)
        res = cli.request('plugin-ozwave.{0}'.format(get_sanitized_hostname()), msg.get(), timeout=10)
        if res is not None:
            data = res.get_data()
        else : data['error'] =  u'Plugin timeout response.'
    return data
示例#27
0
 def assert_Xpl_Stat_Ack_Wait(self, xplMsg):
     """Assert a xpltrig for waiting a switch state"""
     print(
         u"Check that a message about xpl stat ack is sent. The message must be received once time."
     )
     schema, data = xplMsg
     print "schema", schema
     print "data", data
     self.assertTrue(
         self.wait_for_xpl(xpltype="xpl-trig",
                           xplschema=schema,
                           xplsource="domogik-{0}.{1}".format(
                               self.name, get_sanitized_hostname()),
                           data=data,
                           timeout=60))
     print "listener ack running"
def get_StrikePoints(device_id):
    data = {u'status': u'fail', u'strikes': [], u'error': u''}
    cli = MQSyncReq(app.zmq_context)
    msg = MQMessage()
    msg.set_action('vigilightning.manager.getstrikes')
    msg.add_data('device_id', device_id)
    res = cli.request('plugin-vigilightning.{0}'.format(
        get_sanitized_hostname()),
                      msg.get(),
                      timeout=10)
    if res is not None:
        data = res.get_data()
    else:
        data['error'] = u'Plugin timeout response.'
    print(u"********* get_StrikePoints : {0}".format(data))
    return data
示例#29
0
 def assert_Xpl_Stat_Ack_Wait(self, *xplMsg, **kwargs):
     """Assert a xpltrig for waiting ack form command result
     """
     print(
         u"Check that a message about xpl stat ack is sent. The message must be received once time."
     )
     #        print xplMsg,  args
     schema, data, statResult = xplMsg
     self.managerTestCase.assertTrue(
         self.managerTestCase.wait_for_xpl(
             xpltype="xpl-trig",
             xplschema=schema,
             xplsource="domogik-{0}.{1}".format(self.managerTestCase.name,
                                                get_sanitized_hostname()),
             data=data,
             timeout=60))
     self.assert_get_last_command_in_db(statResult)
 def refreshRemoteDevice(self,  remote):
     """Request a refresh domogik device data for a remote."""
     cli = MQSyncReq(zmq.Context())
     msg = MQMessage()
     msg.set_action('device.get')
     msg.add_data('type', 'plugin')
     msg.add_data('name', self._xplPlugin.get_plugin_name())
     msg.add_data('host', get_sanitized_hostname())
     devices = cli.request('dbmgr', msg.get(), timeout=10).get()
     for a_devices in devices:
         if a_device['device_type_id'] == remote._device['device_type_id']  and a_device['id'] == remote._device['id'] :
             if a_device['name'] != remote.device['name'] : # rename and change key remote id
                 old_id = getRemoteId(remote._device)
                 self.remotes[getRemoteId(a_device)] = self.remotes.pop(old_id)
                 self._xplPlugin.log.info(u"Remote {0} is rename {1}".format(old_id,  getRemoteId(a_device)))
             remote.updateDevice(a_device)
             break
def create_device():
    ### create the device, and if ok, get its id in device_id
    client_id = "plugin-{0}.{1}".format(plugin, get_sanitized_hostname())
    print "Creating the PLCBUS  device..."
    td = TestDevice()
    params = td.get_params(client_id, "plcbus.switch")
    # fill in the params
    params["name"] = DEVICE_NAME
    params["reference"] = "reference"
    params["description"] = "description"

    for idx, val in enumerate(params["xpl"]):
        params["xpl"][idx]["value"] = ADDRESS

    # go and create
    td.create_device(params)
    print "Device PLCBUS {0} configured".format(DEVICE_NAME_PLCBUS)
示例#32
0
 def refreshClientDevice(self,  client):
     """Request a refresh domogik device data for a IRTrans Client."""
     cli = MQSyncReq(zmq.Context())
     msg = MQMessage()
     msg.set_action('device.get')
     msg.add_data('type', 'plugin')
     msg.add_data('name', self._xplPlugin.get_plugin_name())
     msg.add_data('host', get_sanitized_hostname())
     devices = cli.request('dbmgr', msg.get(), timeout=10).get()
     for a_device in devices:
         if a_device['device_type_id'] == client._device['device_type_id']  and a_device['id'] == client._device['id'] :
             if a_device['name'] != client.device['name'] : # rename and change key client id
                 old_id = getIRTransId(client._device)
                 self.irTransClients[getIRTransId(a_device)] = self.irTransClients.pop(old_id)
                 self._xplPlugin.log.info(u"IRTransciever Client {0} is rename {1}".format(old_id,  getIRTransId(a_device)))
             client.updateDevice(a_device)
             break
示例#33
0
def create_device():
    ### create the device, and if ok, get its id in device_id
    client_id = "plugin-{0}.{1}".format(plugin, get_sanitized_hostname())
    print "Creating the knx device..."
    td = TestDevice()
    params = td.get_params(client_id, "mirror")
    # fill in the params
    params["device_type"] = "switch"
    params["name"] = DEVICE_NAME_MIRROR
    params["Cmd_Datapoint"] = "1.001"
    params["Stat_Datapoint"] = "1.001"
    params["address_cmd"] = "1/1/1"
    params["address_stat"] = "1/0/1"

    # go and create
    td.create_device(params)
    print "Device KNX {0} configured".format(DEVICE_NAME_KAROTZ)
def create_device():
    ### create the device, and if ok, get its id in device_id
    client_id  = "plugin-{0}.{1}".format(plugin, get_sanitized_hostname())
    print("Creating the primary controller device...")
    td = TestDevice()
    params = td.get_params(client_id, "primary.controller")
    # fill in the params
    params["device_type"] = "primary.controller"
    params["name"] = "test_ozw_crtl"
    params["reference"] = "Z-Stick2"
    params["description"] = "Z-Stick2 USB"
    for idx, val in enumerate(params['global']):
#        if params['global'][idx]['key'] == 'network_id' :  params['global'][idx]['value'] = NETWORK_ID
        if params['global'][idx]['key'] == 'driver' :  params['global'][idx]['value'] = DRIVER
    for idx, val in enumerate(params['xpl']):
        params['xpl'][idx]['value'] = NETWORK_ID
    # go and create
    td.create_device(params)
    print "Device primary controller configured"
示例#35
0
def create_device():
    ### create the device, and if ok, get its id in device_id
    client_id = "plugin-{0}.{1}".format(plugin, get_sanitized_hostname())
    print "Creating the Hue device..."
    td = TestDevice()
    params = td.get_params(client_id, "hue")
    # fill in the params
    params["device_type"] = "hue"
    params["name"] = DEVICE_NAME_MIRROR
    params["address"] = ADDRESS
    for idx, val in enumerate(params['global']):
        if params['global'][idx]['key'] == 'name':
            params['global'][idx]['value'] = NAME
        if params['global'][idx]['key'] == 'address':
            params['global'][idx]['value'] = ADDRESS

    # go and create
    td.create_device(params)
    print "Device Hue {0} configured".format(DEVICE_NAME_KAROTZ)
示例#36
0
    def query(self, name, key = None):
        '''
        Ask the config system for the value. Calling this function will make
        your program wait until it got an answer

        @param name : the plugin of the item requesting the value, must exists in the config database
        @param key : the key to fetch corresponding value
        @return : the value if key != None
                  a dictionnary will all keys/values if key = None
        '''
        msg = MQMessage()
        msg.set_action('config.get')
        msg.add_data('type', 'plugin')
        msg.add_data('name', name)
        msg.add_data('host', get_sanitized_hostname())
        if key != None:
            msg.add_data('key', key)
        else:
            key = "*"
        self._log.info("Request query config for plugin {0} : key {1}".format(name, key))
        ret = self.cli.request('dbmgr', msg.get(), timeout=QUERY_CONFIG_WAIT)

        ### no response from dbmgr
        if ret is None:
            self._log.error("Query config for plugin {0} on host {1}, key {2} : no response from dbmgr".format(name, get_sanitized_hostname(), key))
            return None

        ### response from dbmgr
        else:
            dat = ret.get_data()
            if dat['status']:
                self._log.debug("Query config : successfull response : {0}".format(ret))
                if key == "*":
                    return dat['data']
                else:
                    val = dat['value']
                    # do some cast
                    if val == "None":
                        val = None
                    return val
            else:
                self._log.error("Query config : error returned. Reason : {0}".format(dat['reason']))
                return None
def create_device():
    ### create the device, and if ok, get its id in device_id
    client_id  = "plugin-{0}.{1}".format(plugin, get_sanitized_hostname())
    print "Creating the SMS  device..."
    td = TestDevice()
    params = td.get_params(client_id, "notify.smsweb")
        # fill in the params
    params["device_type"] = "notify.smsweb"
    params["name"] = DEVICE_NAME
    params["reference"] = "reference"
    params["description"] = "description"
    for idx, val in enumerate(params['global']):
        if params['global'][idx]['key'] == 'operator' :  params['global'][idx]['value'] = OPERATOR
        if params['global'][idx]['key'] == 'login' :  params['global'][idx]['value'] = OP_LOGIN
        if params['global'][idx]['key'] == 'pwd' :  params['global'][idx]['value'] = OP_PWD

    for idx, val in enumerate(params['xpl']):
        params['xpl'][idx]['value'] = PHONE_TEL

    # go and create
    td.create_device(params)
    print "Device SMS {0} configured".format(DEVICE_NAME_NOTIFRY)

    print("Creating the Newtifry  device...")
    td = TestDevice()
    params = td.get_params(client_id, "notify.newtifry")
        # fill in the params
    params["device_type"] = "notify.newtifry"
    params["name"] = DEVICE_NAME_NOTIFRY
    params["reference"] = "reference"
    params["description"] = "description"
    for idx, val in enumerate(params['global']):
        if params['global'][idx]['key'] == 'sourcekey' :  params['global'][idx]['value'] = SOURCE_KEY
        if params['global'][idx]['key'] == 'defaulttitle' :  params['global'][idx]['value'] = 'Test message'
        if params['global'][idx]['key'] == 'backend' :  params['global'][idx]['value'] = BACKEND

    for idx, val in enumerate(params['xpl']):
        params['xpl'][idx]['value'] = TO

    # go and create
    td.create_device(params)

    print "Device Newtifry {0} configured".format(DEVICE_NAME_NOTIFRY)
    def create_device(self, name, nodeidchildid, devicetype):
        """ Create a new device for this plugin
        """
        client_id = "plugin-mysensors.{0}".format(get_sanitized_hostname())
        # name = "Node xx" or SensorName/Node_id.Child_id
        # nodeidchildid = Node_id.Child_id
        # devicetype = "mysensors.node" or "mysensors.s_temp" ...
        devicedata = {
            'data': {
                u'name':
                name,
                u'description':
                "",
                u'reference':
                "",
                u'global': [{
                    u'key': u'nodesensor',
                    u'value': nodeidchildid,
                    u'type': u'string',
                    u'description': u'nodeid.sensorid'
                }],
                u'client_id':
                client_id,
                u'device_type':
                devicetype,
                u'xpl': [],
                u'xpl_commands': {},
                u'xpl_stats': {}
            }
        }

        cli = MQSyncReq(zmq.Context())
        msg = MQMessage()
        msg.set_action('device.create')
        msg.set_data(devicedata)
        response = cli.request('dbmgr', msg.get(), timeout=10).get()
        create_result = json.loads(response[1])  # response[1] is a string !
        self.log.debug(u"==> Create device result: '%s'" % response)
        if not create_result["status"]:
            self.log.error("### Failed to create device '%s' (%s) !" %
                           (nodeidchildid))
        '''
def create_device():
    ### create the device, and if ok, get its id in device_id
    client_id  = "plugin-{0}.{1}".format(plugin, get_sanitized_hostname())
    print("Creating the UPS device...")
    td = TestDevice()
    params = td.get_params(client_id, "ups.device")
        # fill in the params
    params["device_type"] = "ups.device"
    params["name"] = "test_UPS_Monitor"
    params["reference"] = "NUT Sockect client"
    params["description"] = "Monitor UPS"
    for idx, val in enumerate(params['global']):
        if params['global'][idx]['key'] == 'timer_poll' :  params['global'][idx]['value'] = TIMER_POLL

    for idx, val in enumerate(params['xpl']):
        params['xpl'][idx]['value'] = DEVICE_NAME

    # go and create
    td.create_device(params)
    print "Device UPS {0} configured".format(DEVICE_NAME) 
    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 create_device():
    ### create the device, and if ok, get its id in device_id
    client_id  = "plugin-{0}.{1}".format(plugin, get_sanitized_hostname())
    print("Creating the Remote device...")
    td = TestDevice()
    params = td.get_params(client_id, "daikcode.remotearc")
        # fill in the params
    params["device_type"] = "daikcode.remotearc"
    params["name"] = "test_daikcode.remotearc"
    params["reference"] = "ARC Remote"
    params["description"] = "Connected to {0}".format(DEVICE_IR)
    for idx, val in enumerate(params['global']):
        if params['global'][idx]['key'] == 'irdevice' :  params['global'][idx]['value'] = DEVICE_IR
        if params['global'][idx]['key'] == 'datatype' :  params['global'][idx]['value'] = DEVICE_DATATYPE

    for idx, val in enumerate(params['xpl']):
        params['xpl'][idx]['value'] = DEVICE_NAME

    # go and create
    td.create_device(params)
    print "Device Remote {0} configured".format(DEVICE_NAME) 
示例#42
0
    def query(self, plugin, key, element="", nb_test=QUERY_CONFIG_NUM_TRY):
        """
        Ask the config system for the value. Calling this function will make
        your program wait until it got an answer

        @param plugin : the plugin of the item requesting the value,
        must exists in the config database
        @param element : the name of the element which requests config, None if
        it's a technolgy global parameter
        @param key : the key to fetch corresponding value, if it's an empty string,
        all the config items for this technology will be fetched
        """
        msg = MQMessage()
        msg._action = "config.get"
        msg._data = {"plugin": plugin, "key": key, "element": element, "hostname": get_sanitized_hostname()}
        ret = self.cli.request("dbmgr", msg.get(), timeout=QUERY_CONFIG_WAIT)
        if ret is None:
            return None
        else:
            if "value" in ret._data.keys():
                return ret._data["value"]
            else:
                return None
def create_device():
    ### create the device, and if ok, get its id in device_id
    client_id = "plugin-{0}.{1}".format(plugin, get_sanitized_hostname())
    print("Creating the Remote device...")
    td = TestDevice()
    params = td.get_params(client_id, "daikcode.remotearc")
    # fill in the params
    params["device_type"] = "daikcode.remotearc"
    params["name"] = "test_daikcode.remotearc"
    params["reference"] = "ARC Remote"
    params["description"] = "Connected to {0}".format(DEVICE_IR)
    for idx, val in enumerate(params['global']):
        if params['global'][idx]['key'] == 'irdevice':
            params['global'][idx]['value'] = DEVICE_IR
        if params['global'][idx]['key'] == 'datatype':
            params['global'][idx]['value'] = DEVICE_DATATYPE

    for idx, val in enumerate(params['xpl']):
        params['xpl'][idx]['value'] = DEVICE_NAME

    # go and create
    td.create_device(params)
    print "Device Remote {0} configured".format(DEVICE_NAME)
示例#44
0
 def refreshClientDevice(self, client):
     """Request a refresh domogik device data for a IRTrans Client."""
     cli = MQSyncReq(zmq.Context())
     msg = MQMessage()
     msg.set_action('device.get')
     msg.add_data('type', 'plugin')
     msg.add_data('name', self._xplPlugin.get_plugin_name())
     msg.add_data('host', get_sanitized_hostname())
     devices = cli.request('dbmgr', msg.get(), timeout=10).get()
     for a_device in devices:
         if a_device['device_type_id'] == client._device[
                 'device_type_id'] and a_device['id'] == client._device[
                     'id']:
             if a_device['name'] != client.device[
                     'name']:  # rename and change key client id
                 old_id = getIRTransId(client._device)
                 self.irTransClients[getIRTransId(
                     a_device)] = self.irTransClients.pop(old_id)
                 self._xplPlugin.log.info(
                     u"IRTransciever Client {0} is rename {1}".format(
                         old_id, getIRTransId(a_device)))
             client.updateDevice(a_device)
             break
示例#45
0
 def refreshRemoteDevice(self, remote):
     """Request a refresh domogik device data for a remote."""
     cli = MQSyncReq(zmq.Context())
     msg = MQMessage()
     msg.set_action('device.get')
     msg.add_data('type', 'plugin')
     msg.add_data('name', self._xplPlugin.get_plugin_name())
     msg.add_data('host', get_sanitized_hostname())
     devices = cli.request('dbmgr', msg.get(), timeout=10).get()
     for a_devices in devices:
         if a_device['device_type_id'] == remote._device[
                 'device_type_id'] and a_device['id'] == remote._device[
                     'id']:
             if a_device['name'] != remote.device[
                     'name']:  # rename and change key remote id
                 old_id = getRemoteId(remote._device)
                 self.remotes[getRemoteId(a_device)] = self.remotes.pop(
                     old_id)
                 self._xplPlugin.log.info(
                     u"Remote {0} is rename {1}".format(
                         old_id, getRemoteId(a_device)))
             remote.updateDevice(a_device)
             break
示例#46
0
 def test_0050_start_the_plugin(self):
     tp = TestPlugin(self.name, get_sanitized_hostname())
     self.assertTrue(tp.request_startup())
     self.assertTrue(tp.wait_for_event(STATUS_ALIVE))
     # just wait 1 second to get clearer logs
     time.sleep(10)
示例#47
0
        if response.status_code != 200:
            raise RuntimeError("Error when configuring the device global parameters : {0}".format(response.text))
        if response.text == "":
            print(u"There is no device to delete")
            return
        devices = device = json.loads(response.text)
        for device in devices:
            #print(u"Id = {0} / Client_id = {1}".format(device['id'], device['client_id']))
            if device['client_id'] == client_id:
                self.del_device(device['id'])
        
        


if __name__ == "__main__":
    client_id = "plugin-diskfree.{0}".format(get_sanitized_hostname())
    td = TestDevice()
    params = td.get_params(client_id, "diskfree.disk_usage")

    # fill in the params
    params["device_type"] = "diskfree.disk_usage"
    params["name"] = "TestDevice"
    params["reference"] = "reference"
    params["description"] = "description"
    for idx, val in enumerate(params['global']):
        params['global'][idx]['value'] = 1
    for idx, val in enumerate(params['xpl']):
        params['xpl'][idx]['value'] = '/'

    # go and create
    td.create_device(params)
示例#48
0
 def test_9990_stop_the_plugin(self):
     tp = TestPlugin(self.name, get_sanitized_hostname())
     tp.request_stop()
     self.assertTrue(tp.wait_for_event(STATUS_STOPPED))
#!/usr/bin/python
#-*- coding: utf-8 -*-

from domogik.tests.common.helpers import configure, delete_configuration
from domogik.common.utils import get_sanitized_hostname

plugin = "notify"

host_id = get_sanitized_hostname()
delete_configuration("plugin", plugin, host_id)

configure("plugin", plugin, host_id, "msg_header", "Domogik notification")
configure("plugin", plugin, host_id, "send_at_start", True)
configure("plugin", plugin, host_id, "configured", True)
    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']))
#!/usr/bin/python
#-*- coding: utf-8 -*-

from domogik.tests.common.helpers import configure, delete_configuration
from domogik.common.utils import get_sanitized_hostname

plugin =  "notify"

host_id = get_sanitized_hostname()
delete_configuration("plugin", plugin, host_id)

configure("plugin", plugin, host_id, "msg_header", "Domogik notification")
configure("plugin", plugin, host_id, "send_at_start", True)
configure("plugin", plugin, host_id, "configured", True)
示例#52
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

from domogik.tests.common.testplugin import TestPlugin
from domogik.common.utils import get_sanitized_hostname
from domogikmq.reqrep.client import MQSyncReq
from domogikmq.message import MQMessage
import time
import zmq

tp = TestPlugin('test', get_sanitized_hostname())
tp.request_startup()

time.sleep(10)
cli = MQSyncReq(zmq.Context())
msg = MQMessage()
msg.set_action('client.list.get')
req = cli.request('manager', msg.get(), timeout=10)

if req:
    data = req.get()[1]
    found = False
    for cli in data:
        if cli == "plugin-test.{0}".format(get_sanitized_hostname()):
            found = True
            state = data[cli]["status"]
            if state != "alive":
                assert RuntimeError("MQ REQ client.list.get is saying the plugin is {0}".format(state))
    if not found:
        assert RuntimeError("MQ REQ client.list.get is not returning this plugin")
else:
示例#53
0
    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'])
    # set up the plugin name
    name = "nutserve"

    # set up the configuration of the plugin
    # configuration is done in test_0010_configure_the_plugin with the cfg content
    # notice that the old configuration is deleted before
    cfg = {'configured': True, 'host': '192.168.0.192', 'port': 3493, 'login': '', 'pwd': ''}

    ### start tests

    # load the test devices class
    td = TestDevice()

    # delete existing devices for this plugin on this host
    client_id = "{0}-{1}.{2}".format("plugin", name, get_sanitized_hostname())
    try:
        td.del_devices_by_client(client_id)
    except:
        print(u"Error while deleting all the test device for the client id '{0}' : {1}".format(client_id, traceback.format_exc()))
        sys.exit(1)

    # create a test device
    try:
        params = td.get_params(client_id, "ups.device")
            # fill in the params
        params["device_type"] = "ups.device"
        params["name"] = "test_UPS_Monitor"
        params["reference"] = "NUT Sockect client"
        params["description"] = "Monitor UPS"
        for idx, val in enumerate(params['global']):
示例#55
0
from domogik.tests.common.testdevice import TestDevice
from domogik.common.utils import get_sanitized_hostname

cid = "plugin-test.{0}".format(get_sanitized_hostname())
t = TestDevice()

# an xpl device
params = t.get_params(cid, "test.xpltest")
params['name'] = 'Test-xpl-device'
params['reference'] = 'Test-xpl-reference'
params['description'] = 'Test-xpl-description'
params['global'][0]['value'] = 'xpl-set-global'
params['xpl'][0]['value'] = 'xpl-set-devicetype'
params['xpl_stats']['test_xpl_stat'][0]['value'] = 'xpl-stat-set-device' 
params['xpl_commands']['test_xpl_command'][0]['value'] = 'xpl-cmd-set-device' 
dev = t.create_device(params)

# an mq device
params = t.get_params(cid, "test.mqtest")
params['name'] = 'Test-mq-device'
params['reference'] = 'Test-mq-reference'
params['description'] = 'Test-mq-description'
params['global'][0]['value'] = 'mq-set-global'
dev = t.create_device(params)
示例#56
0
#!/usr/bin/python

from domogik.tests.common.helpers import configure, delete_configuration, check_config
from domogik.common.utils import get_sanitized_hostname

print "==> Set the config"
delete_configuration("plugin", "test", get_sanitized_hostname())
configure("plugin", "test", get_sanitized_hostname(), "dummy", "dummyConfigParam")

print "==> Check the config"
check_config("plugin", "test", get_sanitized_hostname(), "configured", True)
check_config("plugin", "test", get_sanitized_hostname(), "dummy", "dummyConfigParam")
示例#57
0
    def assert_Xpl_Stat_Ack_Wait(self, *xplMsg,  **kwargs) :
        """Assert a xpltrig for waiting ack form command result
        """
        print(u"Check that a message about xpl stat ack is sent. The message must be received once time.")
#        print xplMsg,  args
        schema,  data, statResult = xplMsg
        self.managerTestCase.assertTrue(self.managerTestCase.wait_for_xpl(xpltype = "xpl-trig",
                                  xplschema = schema,
                                  xplsource = "domogik-{0}.{1}".format(self.managerTestCase.name, get_sanitized_hostname()),
                                  data = data,
                                  timeout = 60))
        self.assert_get_last_command_in_db(statResult)
示例#58
0
#!/usr/bin/python

from domogik.tests.common.helpers import configure, delete_configuration
from domogik.common.utils import get_sanitized_hostname


delete_configuration("plugin", "rfxcom", get_sanitized_hostname())
configure("plugin", "rfxcom", get_sanitized_hostname(), "configured", True)
configure("plugin", "rfxcom", get_sanitized_hostname(), "rfxcom_device", "/dev/rfxcom")
    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'])