def updateGroupTrigger(helper, group_inst_old, group_inst_new):
    group_to_inst_cid = {
        EnumConfigObjects["C_DEVICE_CHANNEL_GROUP"] : EnumConfigObjects["C_DEVICE_CHANNEL"],
        EnumConfigObjects["C_DEVICE_LINK_GROUP"] : EnumConfigObjects["C_DEVICE_LINK"],
    }

#    update_map = {}
#    for i in range(0, group_inst_new["quantity"]):
#        update_map[getGroupItemName(group_inst_old["name"], i, group_inst_new["quantity"])] = getGroupItemName(group_inst_new["name"], i, group_inst_new["quantity"])

    items_names_old = []
    for i in range(0, group_inst_old["quantity"]):
        items_names_old += [getGroupItemName(group_inst_old["name"], i, group_inst_old["quantity"])]
    items_names_new = []
    for i in range(0, group_inst_new["quantity"]):
        items_names_new += [getGroupItemName(group_inst_new["name"], i, group_inst_new["quantity"])]


    group_instances = helper.NavigateMultiple("M_TYPES", {"Type" : group_inst_new}, "Subject")
    for ginst in group_instances:
        if (ginst.GetControllerId() not in [EnumConfigObjects["C_DEVICE_CHANNEL"], EnumConfigObjects["C_DEVICE_LINK"]]): continue
        if (ginst["name"] not in items_names_old):
            print "Error: Couldn't assign group instance: %s" % ginst.GetInstanceId()
            continue
        old_name_index = items_names_old.index(ginst["name"])
        if (len(items_names_new) > old_name_index):
            ginst["name"] = items_names_new[old_name_index]
        else:
            helper.DeleteEntity(ginst)
        helper.SaveEntity(ginst)
    if (len(items_names_new) > len(items_names_old)):
        device_type = helper.Navigate("M_COMPONENTS", {"Part" : group_inst_new}, "Unit")
        devices = helper.NavigateMultiple("M_TYPES", {"Type" : device_type}, "Subject")
        for device in devices:
            for i in range(len(items_names_old), len(items_names_new)):
                createGroupItem(helper, device, group_inst_new, i, len(items_names_new))
예제 #2
0
def createGroupItem(helper, parent_device, parent_group, index, quantity):
    group_to_inst_cid = {
        EnumConfigObjects["C_DEVICE_CHANNEL_GROUP"] : EnumConfigObjects["C_DEVICE_CHANNEL"],
        EnumConfigObjects["C_DEVICE_LINK_GROUP"] : EnumConfigObjects["C_DEVICE_LINK"],
    }

    new_item = helper.CreateEntity(group_to_inst_cid[parent_group.GetControllerId()])
    new_item["name"] = getGroupItemName(parent_group["name"], index, quantity)
    if (parent_group.GetControllerId() == EnumConfigObjects["C_DEVICE_CHANNEL_GROUP"]):
        new_item["default_value"] = parent_group["default_value"]
    helper.SaveEntity(new_item)

    new_link_components = helper.CreateEntity("M_COMPONENTS")
    new_link_components["Unit"] = parent_device.GetInstanceId()
    new_link_components["Part"] = new_item.GetInstanceId()
    helper.SaveEntity(new_link_components)

    new_link_types = helper.CreateEntity("M_TYPES")
    new_link_types["Type"] = parent_group.GetInstanceId()
    new_link_types["Subject"] = new_item.GetInstanceId()
    helper.SaveEntity(new_link_types)
    return True