当前位置: 首页>>代码示例>>Python>>正文


Python MasterSql.mysql_handler_personnal_query方法代码示例

本文整理汇总了Python中MasterSql.mysql_handler_personnal_query方法的典型用法代码示例。如果您正苦于以下问题:Python MasterSql.mysql_handler_personnal_query方法的具体用法?Python MasterSql.mysql_handler_personnal_query怎么用?Python MasterSql.mysql_handler_personnal_query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MasterSql的用法示例。


在下文中一共展示了MasterSql.mysql_handler_personnal_query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: remote_sql

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
 def remote_sql(self, json_obj, connection):
     """
     Execute sql command from configurator
     """
     db = MasterSql();
     req = json_obj['data'].split(';');
     for item in req:
         if item != '':
             db.mysql_handler_personnal_query(item);
     connection.close();
     return;
开发者ID:Fuere,项目名称:Domoleaf,代码行数:13,代码来源:MasterDaemon.py

示例2: __init__

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class EnOceanManager:

    ## The constructor.
    #
    # @param slave_keys The aes keys of the slaves.
    def __init__(self, slave_keys):
        ## Logger object for formatting and printing
        self.logger = Logger(DEBUG_MODE, LOG_FILE);
        ## SQL manager for the master daemon
        self.sql = MasterSql();
        self._parser = DaemonConfigParser('/etc/domoleaf/master.conf');
        ## Object containing the AES keys for encrypted communications
        self.aes_slave_keys = slave_keys;
        ## Array containing functions associated with IDs
        self.functions_transform = {
              0: utils.convert_none,
              4: utils.eno_onoff
        };

    ## Updates the table room_device_option with EnOcean values.
    #
    # @param daemon_id The ID of the daemon.
    # @param json_obj JSON object containing the source address of the EnOcean device.
    # @param db The database handler.
    #
    # @return The result of the query.
    def update_room_device_option(self, daemon_id, json_obj, db):
        query = ''.join(["SELECT room_device_option.option_id, room_device.room_device_id, addr_plus, function_answer, room_device_option.dpt_id ",
              "FROM room_device_option JOIN room_device ON room_device_option.room_device_id=room_device.room_device_id ",
              "JOIN dpt_optiondef ON dpt_optiondef.option_id=room_device_option.option_id AND ",
              "dpt_optiondef.protocol_id=room_device.protocol_id AND dpt_optiondef.dpt_id=room_device_option.dpt_id ",
              "WHERE daemon_id=", str(daemon_id), " AND room_device_option.addr=\"", str(json_obj['src_addr']), "\""]);
        res = self.sql.mysql_handler_personnal_query(query, db);
        result = []
        append = result.append
        if not res:
            query = ''.join(["SELECT room_device_option.option_id, room_device.room_device_id, addr_plus, function_answer, room_device_option.dpt_id ",
                  "FROM room_device_option JOIN room_device ON room_device_option.room_device_id=room_device.room_device_id ",
                  "JOIN dpt_optiondef ON dpt_optiondef.option_id=room_device_option.option_id AND ",
                  "dpt_optiondef.protocol_id=room_device.protocol_id AND dpt_optiondef.dpt_id=room_device_option.dpt_id ",
                  "WHERE daemon_id=", str(daemon_id), " AND  room_device_option.addr_plus=\"", str(json_obj['src_addr']), "\""]);
            res = self.sql.mysql_handler_personnal_query(query, db);
        for r in res:
            val = self.functions_transform[r[3]](int(json_obj['value']), r[4]);
            if val is not None:
                append(r)
                up = ''.join(["UPDATE room_device_option SET opt_value=\"", str(val),
                      "\" WHERE room_device_id=", str(r[1]), " AND option_id=\"", str(r[0]), "\""]);
                self.sql.mysql_handler_personnal_query(up, db);
        return result
开发者ID:V-Paranoiaque,项目名称:Domoleaf,代码行数:52,代码来源:EnOceanManager.py

示例3: SlaveReceiver

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class SlaveReceiver(Thread):
    def __init__(self, connection, hostname, daemon):
        """
        Threaded class for reading from a slave and send the data to the treatment function
        """
        Thread.__init__(self);
        self.connection = connection;
        self.daemon = daemon;
        self.connected_host = hostname;
        self.sql = MasterSql();

    def run(self):
        """
        Thread run function overload
        """
        res = self.sql.mysql_handler_personnal_query('SELECT serial, secretkey FROM daemon WHERE serial=\'' + self.connected_host + '\'');
        aes_key = '';
        for r in res:
            if r[0] == self.connected_host:
                aes_key = r[1];
                break;
        if aes_key == '':
            return None;
        data = self.connection.recv(MasterDaemon.MAX_DATA_LENGTH);
        decrypt_IV = data[:16].decode();
        decode_obj = AES.new(aes_key, AES.MODE_CBC, decrypt_IV);
        data2 = decode_obj.decrypt(data[16:]).decode();
        flag = False;
        obj = data2;
        self.daemon.parse_data(obj, self.connection);
开发者ID:AdrienCourtois,项目名称:Domoleaf,代码行数:32,代码来源:SlaveReceiver.py

示例4: __init__

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class Smartcommand:

    def __init__(self, daemon, smartcmd_id = 0):
        self.logger = Logger(False, LOG_FILE);
        self.logger.info('Started SMARTCMD');
        self.smartcmd_id = smartcmd_id;
        self.sql = MasterSql();
        self.daemon = daemon;

    def launch_smartcmd(self, json_obj, connection):
        if (self.smartcmd_id == 0):
            self.logger.error('Invalid Smartcommand');
            return;

        query = 'SELECT room_device_id, option_id, option_value, time_lapse FROM smartcommand_elems WHERE smartcommand_id ="'+ str(self.smartcmd_id) +'" ORDER BY exec_id';
        res = self.sql.mysql_handler_personnal_query(query);
        delay_color = 0;
        for r in res:
            obj = {};
            obj['sync'] = 0;
            data = {};
            data['room_device_id'] = r[0];
            data['option_id'] = r[1];
            data['value'] = r[2];
            obj['data'] = data;
            obj['packet_type'] = 'smartcmd_launch';
            delay = r[3];
            if (data['option_id'] ==  392 or data['option_id'] ==  393 or data['option_id'] ==  394):
                delay_color = delay_color + 1;
            if (delay > 0 and delay_color <= 1):
                time.sleep(delay);
            if (delay_color >= 3):
                delay_color = 0;
            self.daemon.send_to_device(obj, connection);
开发者ID:giorda-a,项目名称:Domoleaf,代码行数:36,代码来源:Smartcommand.py

示例5: __init__

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class Scenario:

    def __init__(self, daemon):
        self.logger = Logger(False, LOG_FILE);
        self.sql = MasterSql();
        self.daemon = daemon;
        self.scenarios_list = {};
        self.update_scenarios_list();

    def get_scenarios_tab(self, scenarios):
        scenarios_tab = {};
        self.logger.debug('\n\nGETTING SCENARIOS TAB\n');
        for d in scenarios:
            scHash = str(d[4])+'_'+str(d[5])
            if (scHash not in scenarios_tab):
                scenarios_tab[scHash] = [];
            scenarios_tab[scHash].append(d)
        return scenarios_tab;
    
    def update_scenarios_list(self):
        self.logger.debug('UPDATING SCENARIOS');

        query = ('SELECT id_scenario, trigger_events_conditions.id_trigger, id_schedule, '
                 'id_smartcmd, trigger_events_conditions.room_device_id, id_option '
                 'FROM trigger_events_conditions '
                 'JOIN scenarios_list '
                 'ON trigger_events_conditions.id_trigger=scenarios_list.id_trigger '
                 'WHERE activated = 1 && scenarios_list.id_trigger IS NOT NULL '
                 'ORDER BY id_scenario');
        scenarios_list = self.sql.mysql_handler_personnal_query(query);
        
        self.logger.debug('S LIST = ' + str(scenarios_list) + '\n');
        self.scenarios_list = self.get_scenarios_tab(scenarios_list);
        self.logger.debug('S TAB = ' + str(self.scenarios_list) + '\n\n\n');
        
    def check_all_scenarios(self, global_state, trigger, schedule, connection, doList):
        self.logger.debug('CHECKING ALL SCENARIOS');
        self.logger.debug('SCENARIOS LIST = ');
        self.logger.debug(self.scenarios_list);
        self.logger.debug('\n');
        for do in doList:
            slist = self.scenarios_list[str(do[1])+'_'+str(do[0])];
            self.logger.debug('SLIST = ');
            self.logger.debug(slist);
            for scenario in slist:
                self.logger.error(scenario);
                self.logger.debug('Scenario : ' + str(scenario) + '\n\n');
                if trigger.test_trigger(scenario[1], global_state) == 1:
                    self.logger.debug('Trigger OK');
                    if (scenario[2] is None or
                        scenario[2] is not None and schedule.test_schedule(scenario[2]) ==  1):
                        self.launch_scenario(scenario[3], connection);
    
    def launch_scenario(self, id_smartcmd, connection):
        self.logger.debug('LAUNCH !!!');
        jsonString = json.JSONEncoder().encode({
            "data": id_smartcmd
        });
        data = json.JSONDecoder().decode(jsonString);
        self.daemon.smartcmd_launch(data, connection);
开发者ID:couturg,项目名称:Domoleaf,代码行数:62,代码来源:Scenario.py

示例6: __init__

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class EnOceanManager:
    """
    KNX management class
    """
    def __init__(self, slave_keys):
        self.logger = Logger(DEBUG_MODE, LOG_FILE);
        self.sql = MasterSql();
        self._parser = DaemonConfigParser('/etc/domoleaf/master.conf');
        self.aes_slave_keys = slave_keys;
        self.functions_transform = {
              0: utils.convert_none,
              4: utils.eno_onoff
        };
    
    def update_room_device_option(self, daemon_id, json_obj):
        """
        Update of the table room_device_option with EnOcean value
        """
        query  = "SELECT room_device_option.option_id, room_device.room_device_id, addr_plus, function_answer, room_device_option.dpt_id ";
        query += "FROM room_device_option ";
        query += "JOIN room_device ON room_device_option.room_device_id=room_device.room_device_id ";
        query += "JOIN dpt_optiondef ON dpt_optiondef.option_id=room_device_option.option_id AND ";
        query += "dpt_optiondef.protocol_id=room_device.protocol_id AND dpt_optiondef.dpt_id=room_device_option.dpt_id ";
        query += "WHERE daemon_id=" + str(daemon_id) + " AND room_device_option.addr=\"";
        query += str(json_obj['src_addr']) + "\"";
        res = self.sql.mysql_handler_personnal_query(query);
        result = []
        
        if len(res) == 0:
            query  = "SELECT room_device_option.option_id, room_device.room_device_id, addr_plus, function_answer, room_device_option.dpt_id ";
            query += "FROM room_device_option ";
            query += "JOIN room_device ON room_device_option.room_device_id=room_device.room_device_id ";
            query += "JOIN dpt_optiondef ON dpt_optiondef.option_id=room_device_option.option_id AND ";
            query += "dpt_optiondef.protocol_id=room_device.protocol_id AND dpt_optiondef.dpt_id=room_device_option.dpt_id ";
            query += "WHERE daemon_id=" + str(daemon_id) + " AND  room_device_option.addr_plus=\"";
            query += str(json_obj['src_addr']) + "\"";
            res = self.sql.mysql_handler_personnal_query(query);
        
        for r in res:
            val = self.functions_transform[r[3]](int(json_obj['value']), r[4]);
            if val is not None:
                result.append(r)
                up = "UPDATE room_device_option SET opt_value=\"" + str(val)
                up += "\" WHERE room_device_id=" + str(r[1]) + " AND option_id=\"" + str(r[0]) + "\"";
                self.sql.mysql_handler_personnal_query(up);
        return result
开发者ID:couturg,项目名称:Domoleaf,代码行数:48,代码来源:EnOceanManager.py

示例7: SlaveReceiver

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class SlaveReceiver(Thread):

    ## The constructor.
    #
    # @param connection Connection object used to communicate.
    # @param hostname The hostname.
    # @param daemon The MasterDaemon with the adapted treatment functions.
    def __init__(self, connection, hostname, daemon):
        ## Logger object for formatting and printing logs
        self.logger = Logger(log_flag, LOG_FILE);
        Thread.__init__(self);
        ## Connection object for communications
        self.connection = connection;
        ## Instance of Master daemon
        self.daemon = daemon;
        ## The hostname of the system
        self.connected_host = hostname.upper();
        ## SQL object for managing master database
        self.sql = MasterSql();
        ## Username for login to the database
        self.db_username = daemon.db_username;
        ## Password for login to the database
        self.db_passwd = daemon.db_passwd;
        ## Database name for login to the database
        self.db_dbname = daemon.db_dbname;

    ## Thread run function overload.
    #
    # @return None
    def run(self):
        ## Database handler to query master database
        self.db = MysqlHandler(self.db_username, self.db_passwd, self.db_dbname);
        self.logger.error('SELECT serial, secretkey, daemon_id FROM daemon WHERE serial=\''+self.connected_host+'\'');
        res = self.sql.mysql_handler_personnal_query('SELECT serial, secretkey, daemon_id FROM daemon WHERE serial=\''+self.connected_host+'\'', self.db);
        aes_key = '';
        for r in res:
            if r[0] == self.connected_host:
                aes_key = r[1];
                daemon_id = r[2];
                break;
        if not aes_key:
            return None;
        try:
            data = self.connection.recv(MasterDaemon.MAX_DATA_LENGTH);
            decrypt_IV = data[:16].decode();
            decode_obj = AES.new(aes_key, AES.MODE_CBC, decrypt_IV);
            data2 = decode_obj.decrypt(data[16:]).decode();
            flag = False;
            obj = data2;
            self.daemon.parse_data(obj, self.connection, daemon_id, self.db);
        except Exception as e:
            self.logger.error(e);
        self.db.close();
开发者ID:V-Paranoiaque,项目名称:Domoleaf,代码行数:55,代码来源:SlaveReceiver.py

示例8: Scenario

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class Scenario(Thread):

    def __init__(self, daemon):
        Thread.__init__(self);
        self.logger = Logger(False, LOG_FILE);
        self.sql = MasterSql();
        self.daemon = daemon;
        self.scenarios_list = {};
        self.update_scenarios_list();

    def setValues(self, global_state, trigger, schedule, connection, doList):
        self.global_state = global_state;
        self.trigger = trigger;
        self.schedule = schedule;
        self.connection = connection;
        self.doList = doList;

    def run(self):
        check_all_scenarios(self);

    def get_scenarios_tab(self, scenarios):
        scenarios_tab = {};
        self.logger.debug('\n\nGETTING SCENARIOS TAB\n');
        for d in scenarios:
            scHash = ''.join([str(d[4]), '_', str(d[5])]);
            if scHash not in scenarios_tab:
                scenarios_tab[scHash] = [];
            scenarios_tab[scHash].append(d)
        return scenarios_tab;
    
    def update_scenarios_list(self, db=0):
        self.logger.debug('UPDATING SCENARIOS');
        query = ''.join(['SELECT id_scenario, trigger_events_conditions.id_trigger, id_schedule, ',
                 'id_smartcmd, trigger_events_conditions.room_device_id, id_option ',
                 'FROM trigger_events_conditions ',
                 'JOIN scenarios_list ',
                 'ON trigger_events_conditions.id_trigger=scenarios_list.id_trigger ',
                 'WHERE activated = 1 && scenarios_list.id_trigger IS NOT NULL ',
                 'ORDER BY id_scenario']);
        scenarios_list = self.sql.mysql_handler_personnal_query(query, db);
        self.logger.debug('S LIST = '+str(scenarios_list)+'\n');
        self.scenarios_list = self.get_scenarios_tab(scenarios_list);
        self.logger.debug('S TAB = '+str(self.scenarios_list)+'\n\n\n');
    
    def launch_scenario(self, id_smartcmd, connection):
        self.logger.debug('LAUNCH !!!');
        jsonString = json.JSONEncoder().encode({
            "data": id_smartcmd
        });
        data = json.JSONDecoder().decode(jsonString);
        self.daemon.smartcmd_launch(data, connection);
开发者ID:Fuere,项目名称:Domoleaf,代码行数:53,代码来源:Scenario.py

示例9: __init__

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class Smartcommand:

    def __init__(self, daemon, smartcmd_id = 0):
        self.logger = Logger(False, LOG_FILE);
        self.logger.debug('Started SMARTCMD');
        self.smartcmd_id = smartcmd_id;
        self.sql = MasterSql();
        self.daemon = daemon;

    def launch_smartcmd(self, json_obj, connection):
        if (self.smartcmd_id == 0):
            self.logger.error('Invalid Smartcommand');
            return;
        tab_except_http = [356, 357, 358, 359, 360, 361];
        query = ('SELECT smartcommand_elems.room_device_id, option_value, '
                 '       smartcommand_elems.option_id, time_lapse, opt_value, '
                 '       device_id '
                 'FROM smartcommand_elems '
                 'JOIN room_device_option ON room_device_option.room_device_id=smartcommand_elems.room_device_id AND room_device_option.option_id=smartcommand_elems.option_id '
                 'JOIN room_device ON room_device.room_device_id=smartcommand_elems.room_device_id '
                 'WHERE smartcommand_id ="'+ str(self.smartcmd_id) +'" '
                 'ORDER BY exec_id');
        res = self.sql.mysql_handler_personnal_query(query);
        delay_color = 0;
        for r in res:
            obj = {};
            obj['sync'] = 0;
            data = {};
            data['room_device_id'] = r[0];
            data['value'] = r[1];
            data['option_id'] = r[2];
            data['action'] = r[1];
            if r[5] == 86:
                data['value'] = r[4]
            elif data['option_id'] in tab_except_http:
                data['value'] = '';
            obj['data'] = data;
            obj['packet_type'] = 'smartcmd_launch';
            delay = r[3];
            if (data['option_id'] ==  392 or data['option_id'] ==  393 or data['option_id'] ==  394):
                delay_color = delay_color + 1;
            if (delay > 0 and delay_color <= 1):
                time.sleep(delay);
            if (delay_color >= 3):
                delay_color = 0;
            self.daemon.send_to_device(obj, connection);
开发者ID:couturg,项目名称:Domoleaf,代码行数:48,代码来源:Smartcommand.py

示例10: __init__

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class CalcLogs:

    def __init__(self, daemon):
        self.logger = Logger(False, LOG_FILE);
        self.logger.debug('Init CalcLogs');
        self.sql = MasterSql();
        self.daemon = daemon;
        self.devices_list = {};
        self.devices_list_update();

    def devices_list_update(self):
        self.logger.debug('Updating Logs');
        query = ('SELECT room_device.daemon_id, room_device_option.addr_plus, room_device_option.addr, '
                 'room_device.room_device_id, room_device_option.option_id, room_device.name '
                 'FROM room_device '
                 'JOIN room_device_option '
                 'ON room_device.room_device_id = room_device_option.room_device_id '
                 'WHERE daemon_id IS NOT NULL '
                 'ORDER BY room_device_id');
        res = self.sql.mysql_handler_personnal_query(query);
        self.devices_list = res;
        self.devices_list = self.get_tab_devices_list(res);

    def get_tab_devices_list(self, res):
        tab = {};
        for r in res:
            daemon_id = r[0];
            addr_plus = r[1];
            addr = r[2];
            if daemon_id not in tab:
                tab[daemon_id] = {};
            if addr_plus:
                if daemon_id in tab and addr_plus not in tab[daemon_id]:
                    tab[daemon_id][addr_plus] = [];
                    r = r[3:];
                    tab[daemon_id][addr_plus].append(r);
            else:
                if daemon_id in tab and addr not in tab[daemon_id]:
                    tab[daemon_id][addr] = [];
                    r = r[3:];
                    tab[daemon_id][addr].append(r);
        return tab;

    def get_only_good_logs(self, res):
        tab = [];
        tab_append = tab.append
        self.logger.debug(self.devices_list);
        for r in res:
            if (r[1] in self.devices_list[r[0]]):
                self.logger.debug(r);
                log = [];
                log_append = log.append;
                log_append(r[2]);
                log_append(r[3]);
                log_append(self.devices_list[r[0]][r[1]][0][0]);
                log_append(self.devices_list[r[0]][r[1]][0][1]);
                log_append(r[4]);
                log_append(r[5]);
                log_append(r[1]);
                log_append(r[0]);
                tab_append(log);
        return tab;

    def get_good_time_range(self, res):
        end_tr = time.time() - TIME_BEFORE_TIME_TO_CALC - 1;
        init_tr = end_tr - TIME_RANGE_TO_CALC + 1;
        #self.logger.debug('NOW = '+ time.strftime("%d %m %Y %H:%M:%S", time.localtime(now)));
        tab = [];
        append = tab.append;
        for r in res:
            if (r[0] <= end_tr):
                append(r);
        return (tab);

    def cut_tab(self, tab):
        cut_tab = {};
        cut_dict = {};

        for log in tab:
            device_id = log[2];
            option_id = log[3];
            if (device_id not in cut_tab):
                cut_tab[device_id] = {};
            if (option_id not in cut_tab[device_id]):
                cut_tab[device_id][option_id] = [];
            cut_tab[device_id][option_id].append(log);
        
        for device in cut_tab:
            cut_dict[device] = {};
            for option in cut_tab[device]:
                cut_dict[device][option] = [];
                for log in cut_tab[device][option]:
                    cut_dict[device][option].append(log);

        return cut_dict;

    def calc_average_values(self, dictlogs):
        dictaverage = {};
        for time_r in dictlogs:
            dictaverage[time_r] = {};
#.........这里部分代码省略.........
开发者ID:Fuere,项目名称:Domoleaf,代码行数:103,代码来源:CalcLogs.py

示例11: __init__

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class CalcLogs:

    def __init__(self, daemon):
        self.logger = Logger(False, LOG_FILE);
        self.logger.debug('Init CalcLogs');
        self.sql = MasterSql();
        self.daemon = daemon;
        self.devices_list = {};
        self.devices_list_update();

    def devices_list_update(self):
        self.logger.debug('Updating Logs');
        query = ('SELECT room_device.daemon_id, room_device_option.addr_plus, room_device_option.addr, '
                 'room_device.room_device_id, room_device_option.option_id, room_device.name '
                 'FROM room_device '
                 'JOIN room_device_option '
                 'ON room_device.room_device_id = room_device_option.room_device_id '
                 'WHERE daemon_id IS NOT NULL '
                 'ORDER BY room_device_id');
        res = self.sql.mysql_handler_personnal_query(query);
        self.devices_list = res;
        self.devices_list = self.get_tab_devices_list(res);

    def get_tab_devices_list(self, res):
        tab = {};
        for r in res:
            daemon_id = r[0];
            addr_plus = r[1];
            addr = r[2];
            if (daemon_id not in tab):
                tab[daemon_id] = {};
            if (addr_plus):
                if (daemon_id in tab and addr_plus not in tab[daemon_id]):
                    tab[daemon_id][addr_plus] = [];
                    r = r[3:];
                    tab[daemon_id][addr_plus].append(r);
            else:
                if (daemon_id in tab and addr not in tab[daemon_id]):
                    tab[daemon_id][addr] = [];
                    r = r[3:];
                    tab[daemon_id][addr].append(r);
        return tab;

    def get_only_good_logs(self, res):
        tab = [];
        self.logger.debug(self.devices_list);
        for r in res:
            if (r[1] in self.devices_list[r[0]]):
                self.logger.debug(r);
                log = [];
                log.append(r[2]);
                log.append(r[3]);
                log.append(self.devices_list[r[0]][r[1]][0][0]);
                log.append(self.devices_list[r[0]][r[1]][0][1]);
                log.append(r[4]);
                log.append(r[5]);
                log.append(r[1]);
                log.append(r[0]);
                tab.append(log);
        return tab;

    def get_good_time_range(self, res):
        now = time.time();
        #now = TEST_TIMESTAMP;
        end_tr = now - TIME_BEFORE_TIME_TO_CALC - 1;
        init_tr = end_tr - TIME_RANGE_TO_CALC + 1;

        #self.logger.debug('NOW = '+ time.strftime("%d %m %Y %H:%M:%S", time.localtime(now)));

        tab = [];
        for r in res:
            date = r[0];
            if (date <= end_tr):
                tab.append(r);
        return (tab);

    def cut_tab(self, tab):
        cut_tab = {};
        cut_dict = {};

        for log in tab:
            device_id = log[2];
            option_id = log[3];
            if (device_id not in cut_tab):
                cut_tab[device_id] = {};
            if (option_id not in cut_tab[device_id]):
                cut_tab[device_id][option_id] = [];
            cut_tab[device_id][option_id].append(log);
        
        for device in cut_tab:
            cut_dict[device] = {};
            for option in cut_tab[device]:
                cut_dict[device][option] = [];
                for log in cut_tab[device][option]:
                    cut_dict[device][option].append(log);

        return cut_dict;

    def calc_average_values(self, dictlogs):
        dictaverage = {};
#.........这里部分代码省略.........
开发者ID:couturg,项目名称:Domoleaf,代码行数:103,代码来源:CalcLogs.py

示例12: __init__

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class KNXManager:
    """
    KNX management class
    """
    def __init__(self, slave_keys):
        self.knx_function = {
            OPTION_ON_OFF       : self.send_knx_write_short_to_slave,
            OPTION_VAR          : self.send_knx_write_long_to_slave,
            OPTION_UP_DOWN      : self.send_knx_write_short_to_slave,
            OPTION_OPEN_CLOSE   : self.send_knx_write_short_to_slave,
            OPTION_STOP_UP_DOWN : self.send_knx_write_short_to_slave,
            OPTION_SPEED_FAN_0  : self.send_knx_write_speed_fan,
            OPTION_SPEED_FAN_1  : self.send_knx_write_speed_fan,
            OPTION_SPEED_FAN_2  : self.send_knx_write_speed_fan,
            OPTION_SPEED_FAN_3  : self.send_knx_write_speed_fan,
            OPTION_SPEED_FAN_4  : self.send_knx_write_speed_fan,
            OPTION_SPEED_FAN_5  : self.send_knx_write_speed_fan,
            OPTION_SPEED_FAN_6  : self.send_knx_write_speed_fan,
            OPTION_TEMPERATURE_W: self.send_knx_write_temp,
            OPTION_COLOR_R      : self.send_knx_write_long_to_slave,
            OPTION_COLOR_G      : self.send_knx_write_long_to_slave,
            OPTION_COLOR_B      : self.send_knx_write_long_to_slave,
            OPTION_COLOR_W      : self.send_knx_write_long_to_slave
        };
        self.logger = Logger(True, LOG_FILE);
        self.sql = MasterSql();
        self._parser = DaemonConfigParser('/etc/domoleaf/master.conf');
        self.aes_slave_keys = slave_keys;

    def update_room_device_option(self, daemon_id, json_obj):
        """
        Update room_device_option table in database to set new values of the device described by 'json_obj'
        """
        if int(json_obj['type']) == KNX_RESPONSE:
            self.sql.update_room_device_option_resp(json_obj, daemon_id);
        elif int(json_obj['type']) == KNX_WRITE_SHORT:
            self.sql.update_room_device_option_write_short(json_obj, daemon_id);
        elif int(json_obj['type']) == KNX_WRITE_LONG:
            self.sql.update_room_device_option_write_long(json_obj, daemon_id);

    def protocol_knx(self, json_obj, dev, hostname):
        """
        KNX protocol data treatment function
        """
        new_obj = {
            "data": {
                "addr": str(dev['addr_dst']),
                "value": str(json_obj['data']['value']),
                "option_id": str(json_obj['data']['option_id']),
                "room_device_id": str(dev['room_device_id']),
            }
        };
        self.knx_function[int(json_obj['data']['option_id'])](hostname, new_obj);

    def send_json_obj_to_slave(self, json_str, sock, hostname, aes_key, close_flag = True):
        """
        Send 'json_obj' to 'hostname' via 'sock'
        """
        hostname_key = '';
        if '.' in hostname:
            hostname_key = hostname.split('.')[0];
        else:
            hostname_key = hostname;
        AES.key_size = 32;
        aes_IV = AESManager.get_IV();
        encode_obj = AES.new(aes_key, AES.MODE_CBC, aes_IV);
        spaces = 16 - len(json_str) % 16;
        data2 = encode_obj.encrypt(json_str + (spaces * ' '));
        sock.send(bytes(aes_IV, 'utf-8') + data2);
        if close_flag == True:
            sock.close();

    def send_knx_write_speed_fan(self, hostname, json_obj):
        """
        Ask to close all the speed fan before open another
        """
        port = self._parser.getValueFromSection('connect', 'port');
        if not port:
            sys.exit(4);
        if json_obj['data']['value'] == '1':
            query =  'SELECT option_id, addr, dpt_id ';
            query += 'FROM room_device_option ';
            query += 'WHERE room_device_id=' + str(json_obj['data']['room_device_id']) + ' AND ';
            query += 'option_id IN(400, 401, 402, 403, 404, 405, 406) AND status=1';
            res = self.sql.mysql_handler_personnal_query(query);
            for line in res:
                if str(line[2]) == "51" and str(line[0]) == str(json_obj['data']['option_id']):
                    sock = socket.create_connection((hostname, port));
                    val = str(line[0]).split('40')[1];
                    json_str = json.JSONEncoder().encode(
                        {
                            "packet_type": "knx_write_long",
                            "addr_to_send": line[1],
                            "value": val
                        }
                    );
                    self.send_json_obj_to_slave(json_str, sock, hostname, self.aes_slave_keys[hostname]);
                    sock.close();
                    return;
                if str(line[2]) == "2" and str(line[0]) != str(json_obj['data']['option_id']):
#.........这里部分代码省略.........
开发者ID:giorda-a,项目名称:Domoleaf,代码行数:103,代码来源:KNXManager.py

示例13: __init__

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class CalcLogs:

    ## The constructor.
    #
    # @param daemon The slave daemon which initialized this class instance.
    def __init__(self, daemon):
        ## The logger used for formating and printing
        self.logger = Logger(False, LOG_FILE);
        self.logger.debug('Init CalcLogs');

        ## SQL manager
        self.sql = MasterSql();

        ## The instance of the slave daemon
        self.daemon = daemon;

        ## List of the devices
        self.devices_list = {};
        self.devices_list_update();

    ## Updates the device list.
    #
    # Queries the database to fetch room_device and room_device_option.
    # The result is stored in a class variable.
    #
    # @return none
    def devices_list_update(self):
        self.logger.debug('Updating Logs');
        query = ('SELECT room_device.daemon_id, room_device_option.addr_plus, room_device_option.addr, '
                 'room_device.room_device_id, room_device_option.option_id, room_device.name '
                 'FROM room_device '
                 'JOIN room_device_option '
                 'ON room_device.room_device_id = room_device_option.room_device_id '
                 'WHERE daemon_id IS NOT NULL '
                 'ORDER BY room_device_id');
        res = self.sql.mysql_handler_personnal_query(query);
        self.devices_list = self.get_tab_devices_list(res);

    ## Stores the device list in an array and returns it.
    #
    # @param res Array containing all informations about room_device and room_device_option.
    #
    # @return An array containing informations about the devices, with daemon_id as index.
    def get_tab_devices_list(self, res):
        tab = {};
        for r in res:
            daemon_id = r[0];
            addr_plus = r[1];
            addr = r[2];
            if daemon_id not in tab:
                tab[daemon_id] = {};
            if addr_plus:
                if daemon_id in tab and addr_plus not in tab[daemon_id]:
                    tab[daemon_id][addr_plus] = [];
                    r = r[3:];
                    tab[daemon_id][addr_plus].append(r);
            else:
                if daemon_id in tab and addr not in tab[daemon_id]:
                    tab[daemon_id][addr] = [];
                    r = r[3:];
                    tab[daemon_id][addr].append(r);
        return tab;

    ## Stores only the logs of specific devices.
    #
    # @return an array containing the logs.
    def get_only_good_logs(self, res):
        tab = [];
        tab_append = tab.append;
        self.logger.debug(self.devices_list);
        for r in res:
            if (r[1] in self.devices_list[r[0]]):
                self.logger.debug(r);
                log = [];
                log_append = log.append;
                log_append(r[2]);
                log_append(r[3]);
                log_append(self.devices_list[r[0]][r[1]][0][0]);
                log_append(self.devices_list[r[0]][r[1]][0][1]);
                log_append(r[4]);
                log_append(r[5]);
                log_append(r[1]);
                log_append(r[0]);
                tab_append(log);
        return tab;

    ## Gets the devices for which logs will be done.
    #
    # @param res Array containing all the room devices informations.
    #
    # @return An array containing the room devices for who the logs will be done.
    def get_good_time_range(self, res):
        end_tr = time.time() - TIME_BEFORE_TIME_TO_CALC - 1;
        init_tr = end_tr - TIME_RANGE_TO_CALC + 1;
        tab = [];
        append = tab.append;
        for r in res:
            if (r[0] <= end_tr):
                append(r);
        return (tab);
#.........这里部分代码省略.........
开发者ID:V-Paranoiaque,项目名称:Domoleaf,代码行数:103,代码来源:CalcLogs.py

示例14: __init__

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class KNXManager:
    """
    KNX management class
    """
    def __init__(self, slave_keys):
        self.logger = Logger(True, LOG_FILE);
        self.sql = MasterSql();
        self._parser = DaemonConfigParser('/etc/domoleaf/master.conf');
        self.aes_slave_keys = slave_keys;

    def update_room_device_option(self, daemon_id, json_obj):
        """
        Update room_device_option table in database to set new values of the device described by 'json_obj'
        """
        if int(json_obj['type']) == KNX_RESPONSE:
            return self.sql.update_room_device_option_resp(json_obj, daemon_id);
        elif int(json_obj['type']) == KNX_WRITE_SHORT:
            return self.sql.update_room_device_option_write_short(json_obj, daemon_id);
        elif int(json_obj['type']) == KNX_WRITE_LONG:
            return self.sql.update_room_device_option_write_long(json_obj, daemon_id);

    def send_json_obj_to_slave(self, json_str, sock, hostname, aes_key, close_flag = True):
        """
        Send 'json_obj' to 'hostname' via 'sock'
        """
        hostname_key = '';
        if '.' in hostname:
            hostname_key = hostname.split('.')[0];
        else:
            hostname_key = hostname;
        AES.key_size = 32;
        aes_IV = AESManager.get_IV();
        encode_obj = AES.new(aes_key, AES.MODE_CBC, aes_IV);
        spaces = 16 - len(json_str) % 16;
        data2 = encode_obj.encrypt(json_str + (spaces * ' '));
        sock.send(bytes(aes_IV, 'utf-8') + data2);
        if close_flag == True:
            sock.close();

    def send_knx_write_speed_fan(self, json_obj, dev, hostname):
        """
        Ask to close all the speed fan before open another
        """
        port = self._parser.getValueFromSection('connect', 'port');
        if not port:
            sys.exit(4);
        if json_obj['data']['value'] == '1':
            query =  'SELECT option_id, addr, dpt_id ';
            query += 'FROM room_device_option ';
            query += 'WHERE room_device_id=' + str(dev['room_device_id']) + ' AND ';
            query += 'option_id IN(400, 401, 402, 403, 404, 405, 406) AND status=1';
            res = self.sql.mysql_handler_personnal_query(query);
            for line in res:
                if str(line[2]) == "51" and str(line[0]) == str(json_obj['data']['option_id']):
                    sock = socket.create_connection((hostname, port));
                    val = str(line[0]).split('40')[1];
                    json_str = json.JSONEncoder().encode(
                        {
                            "packet_type": "knx_write_long",
                            "addr_to_send": line[1],
                            "value": val
                        }
                    );
                    self.send_json_obj_to_slave(json_str, sock, hostname, self.aes_slave_keys[hostname]);
                    sock.close();
                    return;
                if str(line[2]) == "2" and str(line[0]) != str(json_obj['data']['option_id']):
                    sock = socket.create_connection((hostname, port));
                    json_str = json.JSONEncoder().encode(
                        {
                            "packet_type": "knx_write_short",
                            "addr_to_send": line[1],
                            "value": "0"
                        }
                    );
                    self.send_json_obj_to_slave(json_str, sock, hostname, self.aes_slave_keys[hostname]);
                    sock.close();
        sock = socket.create_connection((hostname, port));
        json_str = json.JSONEncoder().encode(
            {
                "packet_type": "knx_write_short",
                "addr_to_send": str(dev['addr_dst']),
                "value": json_obj['data']['value']
            }
        );
        self.send_json_obj_to_slave(json_str, sock, hostname, self.aes_slave_keys[hostname]);

    def send_knx_write_temp(self, json_obj, dev, hostname):
        """
        Converts absolute value of temperature (Celsius) in 2 hexadecimal values for
        sending to KNX device
        """
        port = self._parser.getValueFromSection('connect', 'port');
        if not port:
            sys.exit(4);
        sock = socket.create_connection((hostname, port));
        val_str = json_obj['data']['value'];
        if ',' in val_str:
            val_str = val_str.replace(',', '.')
        value = utils.convert_temperature_reverse(float(val_str));
#.........这里部分代码省略.........
开发者ID:couturg,项目名称:Domoleaf,代码行数:103,代码来源:KNXManager.py

示例15: __init__

# 需要导入模块: import MasterSql [as 别名]
# 或者: from MasterSql import mysql_handler_personnal_query [as 别名]
class Schedule:

    def __init__(self, daemon):
        self.logger = Logger(False, LOG_FILE);
        self.sql = MasterSql();
        self.daemon = daemon;
        self.schedules_list = '';
        self.full_schedules_list = '';
        self.update_schedules_list();

    def update_schedules_list(self):
        self.logger.debug('Updating Schedules');
        query = ('SELECT trigger_schedules_list.id_schedule, id_smartcmd, '
                 'months, weekdays, days, hours, mins '
                 'FROM scenarios_list '
                 'JOIN trigger_schedules_list ON scenarios_list.id_schedule = trigger_schedules_list.id_schedule '
                 'WHERE scenarios_list.id_schedule IS NOT NULL && id_trigger IS NULL && activated = 1 '
                 'ORDER BY id_scenario ');
        res = self.sql.mysql_handler_personnal_query(query);
        self.schedules_list = res;
        
        query = ('SELECT trigger_schedules_list.id_schedule, id_smartcmd, '
                 'months, weekdays, days, hours, mins '
                 'FROM scenarios_list '
                 'JOIN trigger_schedules_list ON scenarios_list.id_schedule = trigger_schedules_list.id_schedule '
                 'WHERE scenarios_list.id_schedule IS NOT NULL && activated = 1 '
                 'ORDER BY id_scenario ');
        res = self.sql.mysql_handler_personnal_query(query);
        self.full_schedules_list = res;

    def get_schedule_infos(self, id_schedule):
        schedules_list = self.full_schedules_list;
        for schedule in schedules_list:
            if (schedule[0] == id_schedule):
                return (schedule[2], schedule[3], schedule[4],
                        schedule[5], schedule[6]);
        return 0;

    def check_all_schedules(self, connection):
        schedules_list = self.schedules_list;
        for schedule in schedules_list:
            if self.test_schedule(schedule[0]) == 1:
                self.launch_scenario(schedule[1], connection);

    def test_schedule(self, id_schedule):
        if not self.full_schedules_list:
            return 0;
        months, weekdays, days, hours, mins = self.get_schedule_infos(id_schedule);
        now = datetime.datetime.now();
        curr_month = int(now.month) - 1;
        curr_weekday = int(now.strftime('%w'));
        curr_day = int(now.day) - 1;
        curr_hour = int(now.hour);
        curr_min = int(now.minute);

        months = list("{0:b}".format(int(months)).zfill(12));
        weekdays = list("{0:b}".format(int(weekdays)).zfill(7));
        days = list("{0:b}".format(int(days)).zfill(31));
        hours = list("{0:b}".format(int(hours)).zfill(24));
        mins = list(mins);
        
        if (int(months[curr_month]) == 1 and int(weekdays[curr_weekday]) == 1
            and int(days[curr_day]) == 1 and int(hours[curr_hour]) == 1
            and int(mins[curr_min]) == 1):
            return 1;
        return 0;

    def launch_scenario(self, id_smartcmd, connection):
        jsonString = json.JSONEncoder().encode({
            "data": id_smartcmd
        });
        data = json.JSONDecoder().decode(jsonString);
        self.daemon.smartcmd_launch(data, connection);
开发者ID:couturg,项目名称:Domoleaf,代码行数:75,代码来源:Schedule.py


注:本文中的MasterSql.mysql_handler_personnal_query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。