50 lines
2.7 KiB
Markdown
50 lines
2.7 KiB
Markdown
# Process Unknown Devices Optimization Summary
|
|
|
|
## Issue Description
|
|
When using the `--process-unknown` flag, the script was unnecessarily getting detailed information for devices that don't match the unknown_device_patterns. This was inefficient because the script was processing all devices first, then filtering out the unknown ones, and then processing only the unknown ones.
|
|
|
|
## Root Cause
|
|
The issue was in the main function of TasmotaManager.py. The script was calling `get_device_details()` for all devices before calling `process_unknown_devices()`. The `get_device_details()` method filters out devices matching unknown_device_patterns, which means it was processing all devices except those that match the patterns. This is the opposite of what we want when processing unknown devices.
|
|
|
|
```python
|
|
# Original code
|
|
print("\nStep 2: Getting detailed version information...")
|
|
discovery.get_device_details(use_current_json=True)
|
|
|
|
if args.process_unknown:
|
|
print("\nStep 3: Processing unknown devices...")
|
|
discovery.process_unknown_devices()
|
|
```
|
|
|
|
## Fix Implemented
|
|
The fix was to modify the main function to skip the `get_device_details()` call when the `--process-unknown` flag is used. This ensures that we're not wasting time getting detailed information for devices that we don't need to process.
|
|
|
|
```python
|
|
# Modified code
|
|
if args.process_unknown:
|
|
print("\nStep 2: Processing unknown devices...")
|
|
discovery.process_unknown_devices()
|
|
else:
|
|
print("\nStep 2: Getting detailed version information...")
|
|
discovery.get_device_details(use_current_json=True)
|
|
```
|
|
|
|
## Testing
|
|
A test script `test_process_unknown_optimization.py` was created to verify the fix. The script:
|
|
1. Runs TasmotaManager with the `--process-unknown` flag and captures the output
|
|
2. Checks that the output contains "Processing unknown devices" but not "Getting detailed version information"
|
|
3. Counts how many unknown devices were processed
|
|
4. Loads the network_configuration.json to get the unknown_device_patterns
|
|
|
|
To run the test:
|
|
```
|
|
./test_process_unknown_optimization.py
|
|
```
|
|
|
|
## Expected Result
|
|
After this fix, when the `--process-unknown` flag is used, the script will only process devices that match the unknown_device_patterns, skipping the detailed information gathering for all other devices. This makes the script more efficient and focused on its task.
|
|
|
|
## Benefits
|
|
1. **Improved Performance**: The script no longer wastes time processing devices that it doesn't need to.
|
|
2. **Reduced Network Traffic**: Fewer HTTP requests are made to devices that don't need to be processed.
|
|
3. **Clearer Workflow**: The script now has a more logical flow, either processing all devices or only unknown devices, not both. |