diff --git a/unilabos/app/register.py b/unilabos/app/register.py index 40e4107..7a78cf9 100644 --- a/unilabos/app/register.py +++ b/unilabos/app/register.py @@ -18,10 +18,22 @@ def register_devices_and_resources(mqtt_client, lab_registry): mqtt_client.publish_registry(device_info["id"], device_info, False) logger.debug(f"[UniLab Register] 注册设备: {device_info['id']}") - # 注册资源信息 + # 注册资源信息 - 使用HTTP方式 + from unilabos.app.web.client import http_client + + resources_to_register = {} for resource_info in lab_registry.obtain_registry_resource_info(): - mqtt_client.publish_registry(resource_info["id"], resource_info, False) - logger.debug(f"[UniLab Register] 注册资源: {resource_info['id']}") + resources_to_register[resource_info["id"]] = resource_info + logger.debug(f"[UniLab Register] 准备注册资源: {resource_info['id']}") + + if resources_to_register: + start_time = time.time() + response = http_client.resource_registry(resources_to_register) + cost_time = time.time() - start_time + if response.status_code in [200, 201]: + logger.info(f"[UniLab Register] 成功通过HTTP注册 {len(resources_to_register)} 个资源 {cost_time}ms") + else: + logger.error(f"[UniLab Register] HTTP注册资源失败: {response.status_code}, {response.text} {cost_time}ms") time.sleep(10) @@ -53,11 +65,9 @@ def main(): help="是否补全注册表", ) args = parser.parse_args() - + load_config_from_file(args.config) # 构建注册表 build_registry(args.registry, args.complete_registry) - load_config_from_file(args.config) - from unilabos.app.mq import mqtt_client # 连接mqtt @@ -70,4 +80,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/unilabos/app/web/client.py b/unilabos/app/web/client.py index 09b6ede..923e904 100644 --- a/unilabos/app/web/client.py +++ b/unilabos/app/web/client.py @@ -40,8 +40,9 @@ class HTTPClient: Returns: Response: API响应对象 """ + database_param = 1 if database_process_later else 0 response = requests.post( - f"{self.remote_addr}/lab/resource/edge/batch_create/?database_process_later={1 if database_process_later else 0}", + f"{self.remote_addr}/lab/resource/edge/batch_create/?database_process_later={database_param}", json=resources, headers={"Authorization": f"lab {self.auth}"}, timeout=100, @@ -149,6 +150,26 @@ class HTTPClient: ) return response + def resource_registry(self, registry_data: Dict[str, Any]) -> requests.Response: + """ + 注册资源到服务器 + + Args: + registry_data: 注册表数据,格式为 {resource_id: resource_info} + + Returns: + Response: API响应对象 + """ + response = requests.post( + f"{self.remote_addr}/lab/registry/", + json=registry_data, + headers={"Authorization": f"lab {self.auth}"}, + timeout=30, + ) + if response.status_code not in [200, 201]: + logger.error(f"注册资源失败: {response.status_code}, {response.text}") + return response + # 创建默认客户端实例 http_client = HTTPClient() diff --git a/unilabos/registry/devices/virtual_device.yaml b/unilabos/registry/devices/virtual_device.yaml index dca2dad..572456a 100644 --- a/unilabos/registry/devices/virtual_device.yaml +++ b/unilabos/registry/devices/virtual_device.yaml @@ -4580,6 +4580,7 @@ virtual_solid_dispenser: feedback: {} goal: properties: {} + required: [] type: object result: {} required: @@ -4587,6 +4588,30 @@ virtual_solid_dispenser: title: cleanup参数 type: object type: UniLabJsonCommandAsync + auto-find_solid_reagent_bottle: + feedback: {} + goal: {} + goal_default: + reagent_name: null + handles: [] + result: {} + schema: + description: '' + properties: + feedback: {} + goal: + properties: + reagent_name: + type: string + required: + - reagent_name + type: object + result: {} + required: + - goal + title: find_solid_reagent_bottle参数 + type: object + type: UniLabJsonCommand auto-initialize: feedback: {} goal: {} @@ -4599,6 +4624,7 @@ virtual_solid_dispenser: feedback: {} goal: properties: {} + required: [] type: object result: {} required: @@ -4606,9 +4632,58 @@ virtual_solid_dispenser: title: initialize参数 type: object type: UniLabJsonCommandAsync + auto-parse_mass_string: + feedback: {} + goal: {} + goal_default: + mass_str: null + handles: [] + result: {} + schema: + description: '' + properties: + feedback: {} + goal: + properties: + mass_str: + type: string + required: + - mass_str + type: object + result: {} + required: + - goal + title: parse_mass_string参数 + type: object + type: UniLabJsonCommand + auto-parse_mol_string: + feedback: {} + goal: {} + goal_default: + mol_str: null + handles: [] + result: {} + schema: + description: '' + properties: + feedback: {} + goal: + properties: + mol_str: + type: string + required: + - mol_str + type: object + result: {} + required: + - goal + title: parse_mol_string参数 + type: object + type: UniLabJsonCommand module: unilabos.devices.virtual.virtual_solid_dispenser:VirtualSolidDispenser status_types: current_reagent: str + device_info: dict dispensed_amount: float status: str total_operations: int @@ -4641,18 +4716,14 @@ virtual_solid_dispenser: type: object device_id: type: string - max_capacity: - default: 100.0 - type: number - precision: - default: 0.001 - type: number required: [] type: object data: properties: current_reagent: type: string + device_info: + type: object dispensed_amount: type: number status: @@ -4664,6 +4735,7 @@ virtual_solid_dispenser: - current_reagent - dispensed_amount - total_operations + - device_info type: object version: 1.0.0 virtual_stirrer: diff --git a/unilabos/registry/devices/work_station.yaml b/unilabos/registry/devices/work_station.yaml index 3d906dc..c1cc5aa 100644 --- a/unilabos/registry/devices/work_station.yaml +++ b/unilabos/registry/devices/work_station.yaml @@ -474,12 +474,12 @@ workstation: goal: ph_value: ph_value reagent: reagent - vessel: vessel - volume: volume + settling_time: settling_time stir: stir stir_speed: stir_speed stir_time: stir_time - settling_time: settling_time + vessel: vessel + volume: volume goal_default: ph_value: 0.0 reagent: '' @@ -503,11 +503,6 @@ workstation: z: 0.0 sample_id: '' type: '' - volume: 0.0 - stir: false - stir_speed: 300.0 - stir_time: 60.0 - settling_time: 30.0 handles: input: - data_key: vessel @@ -622,21 +617,6 @@ workstation: - data title: Resource type: object - volume: - type: number - description: 'Volume of the solution to adjust pH' - stir: - type: boolean - description: "是否启用搅拌" - stir_speed: - type: number - description: "搅拌速度(RPM)" - stir_time: - type: number - description: "搅拌时间(秒)" - settling_time: - type: number - description: "pH平衡时间(秒)" required: - vessel - ph_value @@ -2248,7 +2228,7 @@ workstation: type: number required: - vessel - - #filtrate_vessel + - filtrate_vessel - stir - stir_speed - temp diff --git a/unilabos/registry/registry.py b/unilabos/registry/registry.py index a7583e3..780ba90 100644 --- a/unilabos/registry/registry.py +++ b/unilabos/registry/registry.py @@ -127,6 +127,8 @@ class Registry: }, }, "version": "1.0.0", + "category": [], + "config_info": [], "icon": "icon_device.webp", "registry_type": "device", "handles": [],