CN-121979552-A - Patch logic execution method and device, storage medium and electronic device
Abstract
The application discloses a patch logic executing method and device, a storage medium and an electronic device, and relates to the technical field of smart families, wherein the method comprises the steps of determining whether a target interceptor example matched with target equipment exists in an interceptor array based on a preset matching rule under the condition that the target equipment receives a control command, wherein the interceptor array comprises a plurality of interceptor examples, and a script for executing the patch logic of the target equipment is packaged in the target interceptor examples; and calling the target interceptor instance and indicating the target interceptor instance to add patch logic for the target equipment based on the execution result so as to enable the target equipment to execute the patch logic. The application can solve the problem that patch logic cannot be added under the condition of not affecting original service logic when a callback method is required to be added in equipment management class in the related technology.
Inventors
- ZHANG YANG
Assignees
- 青岛海尔科技有限公司
- 海尔优家智能科技(北京)有限公司
- 海尔智家股份有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20251229
Claims (10)
- 1. A method of performing patch logic, comprising: under the condition that the target equipment receives a control command, determining whether a target interceptor instance matched with the target equipment exists in an interceptor array or not based on a preset matching rule, wherein the interceptor array comprises a plurality of interceptor instances, and a script for executing patch logic of the target equipment is packaged in the target interceptor instances; Determining an execution result of the control command executed by the target device under the condition that the target interceptor instance exists in the interceptor array; And calling the target interceptor instance, and indicating the target interceptor instance to add the patch logic to the target equipment based on the execution result so as to enable the target equipment to execute the patch logic.
- 2. The method of claim 1, wherein prior to determining whether there is a target interceptor instance in the interceptor array that matches the target device based on a preset matching rule, the method comprises: Traversing a preset device list based on a preset time period to determine whether a first device exists in the preset device list, wherein the preset device list comprises the target device, and the first device is a device newly added into the preset device list in the last time period before the current time; under the condition that the first equipment exists in the preset equipment list, calling a preset interceptor protocol, and generating a first interceptor instance corresponding to the first equipment based on the preset interceptor protocol and the first equipment; the first interceptor instance is added to the interceptor array.
- 3. The method of claim 2, wherein generating a first interceptor instance corresponding to the first device based on the preset interceptor protocol and the first device, comprises: creating an interceptor object corresponding to the first device based on a first method declaration in the preset interceptor protocol, wherein the first method declaration is used for declaring a method for creating the interceptor object matched with the first device and the preset interceptor protocol; Modifying the interceptor object based on a second method declaration and a third method declaration of the preset interceptor protocol to generate the first interceptor instance, wherein the second method declaration is used for declaring a method for matching the first device with the interceptor object, and the third method declaration is used for declaring at least one of a first callback method of the first device before executing the first control command, a second callback method of the first device after executing the first control command successfully, and a third callback method of the first device after the first control command fails to execute.
- 4. The method of claim 1, wherein prior to determining whether there is a target interceptor instance in the interceptor array that matches the target device based on a preset matching rule, the method comprises: Traversing a preset equipment list based on a preset time period, and comparing a first traversing result obtained by traversing the preset equipment list at the current time with a second traversing result obtained by traversing the preset equipment list for the last time before the current time, wherein the preset equipment list comprises the target equipment; Determining whether a second interceptor instance matching the second equipment exists in the interceptor array when determining that the second traversal result indicates that the second equipment exists in the preset equipment list and the first traversal result indicates that the second equipment does not exist in the preset equipment list; Deleting the second interceptor instance if it is determined that the second interceptor instance exists in the interceptor array.
- 5. The method of claim 1, wherein invoking the target interceptor instance and directing the target interceptor instance to add the patch logic to the target device based on the execution result to cause the target device to execute the patch logic comprises: when the execution result is the execution failure, calling the target interceptor instance and indicating the target interceptor instance to generate failure information corresponding to the execution result; And displaying the failure information in a display screen corresponding to the target equipment.
- 6. The method of claim 1, wherein invoking the target interceptor instance and directing the target interceptor instance to add the patch logic to the target device based on the execution result to cause the target device to execute the patch logic comprises: and calling the target interceptor instance and indicating the target interceptor instance to execute a post-processing task corresponding to the target device when the execution result is that the execution is successful, wherein the post-processing task at least comprises one of a real-time interaction task between a target object and the target device, a task for updating the device state of the target device and a task for displaying the execution progress of the target device for executing the control command.
- 7. The method of claim 1, wherein determining whether there is a target interceptor instance in the interceptor array that matches the target device based on a preset matching rule comprises: under the condition that the preset matching rule is used for indicating the corresponding relation between the equipment type and the interceptor instance, determining the target equipment type corresponding to the target equipment; And determining whether the target interceptor instance corresponding to the equipment of the target equipment type exists in the interceptor array.
- 8. An apparatus for performing patch logic, comprising: The first determining module is used for determining whether a target interceptor example matched with the target equipment exists in an interceptor array or not based on a preset matching rule under the condition that the target equipment receives a control command, wherein the interceptor array comprises a plurality of interceptor examples, and a script for executing patch logic of the target equipment is packaged in the target interceptor examples; the second determining module is used for determining an execution result of the control command executed by the target device under the condition that the target interceptor instance exists in the interceptor array; And the calling module is used for calling the target interceptor instance and indicating the target interceptor instance to add the patch logic to the target equipment based on the execution result so as to enable the target equipment to execute the patch logic.
- 9. A computer-readable storage medium, characterized in that the computer-readable storage medium comprises a stored program, wherein the program, when run, performs the method of any one of claims 1 to 7.
- 10. An electronic device comprising a memory and a processor, characterized in that the memory has stored therein a computer program, the processor being arranged to execute the method according to any of the claims 1 to 7 by means of the computer program.
Description
Patch logic execution method and device, storage medium and electronic device Technical Field The application relates to the technical field of smart families, in particular to a patch logic execution method and device, a storage medium and an electronic device. Background In the field of smart home and the like, in a device management code of a home appliance application, a device management class comprises a device list and a plurality of device objects, and along with function iteration, the functions of the device objects become more complex. An Application (APP) needs to manage various devices, and a device management class (e.g., a device manager (UpDeviceManager)) is responsible for maintaining a device list and a device object (e.g., a device object (UpDevice)). The user can trigger the operation of the device in a plurality of scenes (such as a smart Tab card, a device detail page and the like), and the device needs to execute corresponding commands and feed back results. To implement a specific function (e.g., a real-time interactive function), callback processing needs to be added after the device executes the command, but it needs to be ensured that the original device management logic is not disturbed. When a callback method needs to be added in the equipment management class, the following technical problems are that patch logic cannot be easily added in complex logic, original logic can be influenced, and business irrelevant to equipment management is difficult to isolate. Therefore, in the related art, when a callback method needs to be added in the device management class, the patch logic cannot be added under the condition that the original business logic is not affected. Aiming at the problem that in the related art, when a callback method needs to be added in a device management class, patch logic cannot be added under the condition that original business logic is not influenced, an effective solution is not proposed. Disclosure of Invention The embodiment of the application provides a patch logic executing method and device, a storage medium and an electronic device, which at least solve the problem that the patch logic cannot be added under the condition of not affecting the original service logic when a callback method is required to be added in an equipment management class in the related art. According to one embodiment of the application, a patch logic execution method is provided, and the method comprises the steps of determining whether a target interceptor instance matched with target equipment exists in an interceptor array or not based on a preset matching rule when the target equipment receives a control command, wherein the interceptor array comprises a plurality of interceptor instances, a script used for executing the patch logic of the target equipment is packaged in the target interceptor instance, determining an execution result of the control command by the target equipment when the interceptor instance exists in the interceptor array, calling the target interceptor instance, and indicating the target interceptor instance to add the patch logic to the target equipment based on the execution result so as to enable the target equipment to execute the patch logic. In one exemplary embodiment, before determining whether a target interceptor instance matched with the target device exists in an interceptor array based on a preset matching rule, the method comprises traversing a preset device list based on a preset time period to determine whether a first device exists in the preset device list, wherein the preset device list comprises the target device, the first device is a device newly added to the preset device list in a last time period before the current time, calling a preset interceptor protocol when the first device exists in the preset device list, generating a first interceptor instance corresponding to the first device based on the preset interceptor protocol and the first device, and adding the first interceptor instance to the interceptor array. In one exemplary embodiment, generating a first interceptor instance corresponding to the first device based on the preset interceptor protocol and the first device includes creating an interceptor object corresponding to the first device based on a first method declaration in the preset interceptor protocol, wherein the first method declaration is used for declaring a method for creating the interceptor object matching the first device and the preset interceptor protocol, modifying the interceptor object based on a second method declaration and a third method declaration of the preset interceptor protocol to generate the first interceptor instance, wherein the second method declaration is used for declaring a method for matching the first device and the interceptor object, and the third method declaration is used for declaring at least one of a first callback method of the first device before executing a first control c