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


Python DbHelper.add_device_type方法代码示例

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


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

示例1: PackageData

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import add_device_type [as 别名]
class PackageData():
    """ Tool to insert necessary data in database
    """

    def __init__(self, json_path):
        """ Init tool
            @param plugin_name : plugin name
        """

        self._db = DbHelper()
        try:
            self.pkg = PackageJson(path = json_path).json
        except PackageException as exp:
            print("Error in json file:")
            print( exp.value )
            exit()
        except:
            print(str(traceback.format_exc()))
            return
        print("Json file OK")

        # check type == plugin
        if self.pkg["identity"]["type"] not in ["plugin", "external"]:
            print("Error : this package type is not recognized")
            exit()
        # check if json version is at least 2
        if self.pkg['json_version'] < 2:
            print("Error : this package is to old for this version of domogik")
            exit()

    def insert(self):
        """ Insert data for plugin
        """
        ### Plugin
        print("plugin %s" % self.pkg["identity"]["id"])
        if self._db.get_plugin(self.pkg["identity"]["id"]) == None:
            # add if not exists
            print("add...")
            self._db.add_plugin(self.pkg["identity"]["id"],
                                  self.pkg["identity"]["description"],
                                  self.pkg["identity"]["version"])
        else:
            # update if exists
            print("update...")
            self._db.update_plugin(self.pkg["identity"]["id"],
                                  self.pkg["identity"]["description"],
                                  self.pkg["identity"]["version"])
 
        ### Device types
        for device_type in self.pkg["device_types"].keys():
            print("Device type %s" % device_type)
            device_type = self.pkg["device_types"][device_type]
            if self._db.get_device_type_by_id(device_type["id"]) == None:
                # add if not exists
                print("add...")
                self._db.add_device_type(device_type["id"],
                                         device_type["name"],
                                         self.pkg["identity"]["id"],
                                         device_type["description"])
            else:
                # update if exists
                print("update...")
                self._db.update_device_type(device_type["id"],
                                         device_type["name"],
                                         self.pkg["identity"]["id"],
                                         device_type["description"])
开发者ID:capof,项目名称:domogik,代码行数:68,代码来源:packagedata.py

示例2: PackageData

# 需要导入模块: from domogik.common.database import DbHelper [as 别名]
# 或者: from domogik.common.database.DbHelper import add_device_type [as 别名]
class PackageData():
    """ Tool to insert necessary data in database
    """

    def __init__(self, json_path):
        """ Init tool
            @param plugin_name : plugin name
        """

        self._db = DbHelper()
        try:
            self.pkg = PackageJson(path = json_path).json
        except:
            print(str(traceback.format_exc()))
            return
        print("Json file OK")

        # check type == plugin
        if self.pkg["identity"]["type"] not in ["plugin", "external"]:
            print("Error : this package type is not recognized")
            exit()

    def insert(self):
        """ Insert data for plugin
        """
        ### Technology
        print("Technology %s" % self.pkg["technology"]["id"])
        if self._db.get_device_technology_by_id(self.pkg["technology"]["id"]) == None:
            # add if not exists
            print("add...")
            self._db.add_device_technology(self.pkg["technology"]["id"],
                                           self.pkg["technology"]["name"],
                                           self.pkg["technology"]["description"])
        else:
            # update if exists
            print("update...")
            self._db.update_device_technology(self.pkg["technology"]["id"],
                                           self.pkg["technology"]["name"],
                                           self.pkg["technology"]["description"])
 
        ### Device types
        for device_type in self.pkg["device_types"]:
            print("Device type %s" % device_type["id"])
            if self._db.get_device_type_by_id(device_type["id"]) == None:
                # add if not exists
                print("add...")
                self._db.add_device_type(device_type["id"],
                                         device_type["name"],
                                         self.pkg["technology"]["id"],
                                         device_type["description"])
            else:
                # update if exists
                print("update...")
                self._db.update_device_type(device_type["id"],
                                         device_type["name"],
                                         self.pkg["technology"]["id"],
                                         device_type["description"])
 
        ### Device feature model
        for device_feature_model in self.pkg["device_feature_models"]:
            print("Device feature model %s" % device_feature_model["id"])
            print("M.P=%s" % device_feature_model["parameters"])
            if self._db.get_device_feature_model_by_id(device_feature_model["id"]) == None:
                # add if not exists
                print("add...")
                if device_feature_model["feature_type"] == "sensor":
                    self._db.add_sensor_feature_model(device_feature_model["id"],
                                                      device_feature_model["name"],
                                                      device_feature_model["device_type_id"],
                                                      device_feature_model["value_type"],
                                                      device_feature_model["parameters"],
                                                      device_feature_model["stat_key"])
                elif device_feature_model["feature_type"] == "actuator":
                    self._db.add_actuator_feature_model(device_feature_model["id"],
                                                        device_feature_model["name"],
                                                        device_feature_model["device_type_id"],
                                                        device_feature_model["value_type"],
                                                        device_feature_model["return_confirmation"],
                                                        device_feature_model["parameters"],
                                                        device_feature_model["stat_key"])
            else:
                # update if exists
                print("update...")
                if device_feature_model["feature_type"] == "sensor":
                    self._db.update_sensor_feature_model(device_feature_model["id"],
                                                      device_feature_model["name"],
                                                      device_feature_model["parameters"],
                                                      device_feature_model["value_type"],
                                                      device_feature_model["stat_key"])
                elif device_feature_model["feature_type"] == "actuator":
                    self._db.update_actuator_feature_model(device_feature_model["id"],
                                                        device_feature_model["name"],
                                                        device_feature_model["parameters"],
                                                        device_feature_model["value_type"],
                                                        device_feature_model["return_confirmation"],
                                                        device_feature_model["stat_key"])
开发者ID:zaraki673,项目名称:Docker-Domogik,代码行数:98,代码来源:packagedata.py


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