feat: Migrate register definitions from YAML to CSV format#243
feat: Migrate register definitions from YAML to CSV format#243roomote-v0[bot] wants to merge 2 commits intomainfrom
Conversation
- Add register_loader.py module to load CSV register definitions - Create migration scripts to convert YAML to CSV format - Update sungather.py with backward compatibility for both CSV and YAML - Generate registers-sungrow.csv with 210 read and 37 hold registers - Create scan-ranges.yaml for Modbus scan configuration - Add test script to verify CSV loader functionality - Maintain backward compatibility with deprecation warning for YAML files This migration simplifies register maintenance and enables easier editing in spreadsheet applications while preserving all existing functionality.
All issues from the previous review have been resolved. The CSV file now contains clean data, and both migration scripts properly strip inline comments from all YAML fields.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| read,internal_temperature,1,5008,S16,0.1,°C,,,,, | ||
| read,total_apparent_power,1,5009,U32,,VA,SG6KTL-MT|SG8KTL-M|SG10KTL-M|SG10KTL-MT|SG12KTL-M|SG15KTL-M|SG17KTL-M|SG20KTL-M|SG3.0RT|SG4.0RT|SG5.0RT|SG3.0RS|SG4.0RS|SG5.0RS|SG6.0RT|SG7.0RT|SG8.0RT|SG8.0RS|SG10RT|SG12RT|SG15RT|SG17RT|SG20RT|SG33K3J|SG36KTL-M|SG40KTL-M|SG50KTL|SG50KTL-M|SG60KTL|SG60KTL-M|SG60KU-M|SG80KTL|SG80KTL-M|SG111HV|SG125HV|SG125HV-20|SG33CX|SG40CX|SG50CX|SG110CX|SG250HX|SG30CX|SG36CX-US|SG60CX-US|SG250HX-US|SG250HX-IN|SG25CX-SA|SG100CX|SG75CX|SG225HX,,,, | ||
| read,mppt_1_voltage,2,5011,U16,0.1,V,,,,, | ||
| read,mppt_1_current,2,5012,U16,0.1,A,,,,, |
There was a problem hiding this comment.
The CSV file contains malformed data with embedded inline comments that weren't stripped during migration. For example, the total_dc_power register has datatype "U32"" # Documentation says Unsigned... instead of just U32. Similar issues exist in other registers like phase_a_current, phase_b_current, phase_c_current, power_factor, and work_state_1. This will cause the CSV loader to fail or produce incorrect register definitions because these comments will be treated as part of the field values. The migration scripts need to strip inline comments from all YAML fields, not just scan range values.
Fix it with Roo Code or mention @roomote and request a fix.
| elif stripped.startswith('datatype:'): | ||
| current_register['datatype'] = stripped.split(':', 1)[1].strip().strip('"\'') |
There was a problem hiding this comment.
The migration script doesn't strip inline comments from YAML fields during parsing. When parsing datatype: and other fields, inline comments (like # Documentation says...) are included in the extracted values. This causes malformed CSV output. The script only strips comments in the scan section (lines 76-89) but not in the register fields. All field parsing should check for and remove inline comments using the same pattern: if '#' in val_str: val_str = val_str.split('#')[0].strip().
Fix it with Roo Code or mention @roomote and request a fix.
| elif stripped.startswith('- start:'): | ||
| start_val = int(stripped.split(':', 1)[1].strip()) | ||
| if current_scan_block is not None: | ||
| current_scan_block.append({'start': start_val}) | ||
| elif stripped.startswith('range:') and current_scan_block is not None: | ||
| range_val = int(stripped.split(':', 1)[1].strip()) | ||
| if current_scan_block: | ||
| current_scan_block[-1]['range'] = range_val |
There was a problem hiding this comment.
The simple YAML parser doesn't strip inline comments from start and range values. While the current scan-ranges.yaml file doesn't contain inline comments, users might add them when manually editing the file. The migration script properly strips comments (see migrate_yaml_to_csv_simple.py lines 76-89), but this loader doesn't. For consistency and robustness, these lines should include comment stripping: start_val = stripped.split(':', 1)[1].strip(); if '#' in str(start_val): start_val = str(start_val).split('#')[0].strip(); start_val = int(start_val).
Fix it with Roo Code or mention @roomote and request a fix.
Roo Code FixIssues FixedAll three issues from the review have been addressed:
Changes Madescripts/migrate_yaml_to_csv_simple.py
scripts/migrate_yaml_to_csv.py
SunGather/register_loader.py
SunGather/registers-sungrow.csv
TestingAll tests passed:
Commit |
- Add strip_inline_comment() helper to migrate_yaml_to_csv_simple.py - Add strip_inline_comment() helper to migrate_yaml_to_csv.py - Add inline comment stripping to register_loader.py for robustness - Regenerate registers-sungrow.csv with clean data (no embedded comments) Fixes data corruption issue where YAML inline comments like: datatype: U32 # Documentation says... were being included in CSV output as: "U32"" # Documentation says..."
This PR implements the migration from YAML-based register definitions to CSV format to simplify maintenance and enable easier editing in spreadsheet applications.
Changes
New Files
Modified Files
Features
✅ CSV format for easier editing in spreadsheet applications
✅ Backward compatibility with YAML files (with deprecation warning)
✅ Automatic file format detection (.csv vs .yaml/.yml)
✅ All 247 registers successfully migrated
✅ Scan ranges properly separated into dedicated YAML file
✅ Comprehensive test coverage
✅ Works without PyYAML dependency using fallback parser
Testing
All tests pass successfully:
View task on Roo Code Cloud