Skip to content

Fix API endpoint URL and improve error handling, logging and type checking#109

Open
AndrewTapp wants to merge 139 commits intoProudElm:mainfrom
AndrewTapp:main
Open

Fix API endpoint URL and improve error handling, logging and type checking#109
AndrewTapp wants to merge 139 commits intoProudElm:mainfrom
AndrewTapp:main

Conversation

@AndrewTapp
Copy link

@AndrewTapp AndrewTapp commented Jan 10, 2026

10-Jan-2026 Summary of Changes - SolarEdge Optimizers Integration

solaredgeoptimizers.py (Main API Module)

  1. Logger setup: Added logging module setup to replace print statements.
  2. Endpoint URL fix: Updated requestSystemData() URL from monitoringpublic.solaredge.com/publicSystemData to monitoring.solaredge.com/systemData, changed isPublic=true to false, and added locale and v (timestamp) parameters.
  3. List/dict handling: Added handling for decodeResult() returning a list instead of a dict; extract the first element if it's a list.
  4. Type checking: Added validation to ensure the result is a dict before accessing keys.
  5. Safer dictionary access: Changed from direct key access to .get() for safer access.
  6. Error handling: Added specific KeyError handling with improved logging.
  7. Logging conversion: Replaced all print() statements with proper _LOGGER calls.
  8. CSRF token handling: Added check for None CSRF token to prevent errors when missing.
  9. Return value fix: Added explicit return None in GetThecsrfToken() if token not found.
  10. Typo fixes: Fixed "concent" → "consent" in cookie string, and "paneel_desciption" → "paneel_description" (2 locations).

sensor.py (Sensor Platform)

  1. Import fix: Changed from absolute to relative import to use local solaredgeoptimizers.py instead of site-packages version.
  2. Typo fixes: Fixed "measerument" → "measurement" in log message, and "paneel_desciption" → "paneel_description" in attribute reference.
  3. Code cleanup: Removed redundant else clause that did nothing.
  4. Syntax fix: Changed comparison from not self._sensor_type is to self._sensor_type is not.

init_.py (Integration Setup)

  1. Import fix: Changed from absolute to relative import to use local solaredgeoptimizers.py instead of site-packages version.

config_flow.py (Configuration Flow)

  1. Import fix: Changed from absolute to relative import to use local solaredgeoptimizers.py instead of site-packages version.

Overall Impact

  • Fixed API endpoint URL and parameters
  • Improved error handling and logging
  • Fixed import path issues to use local code
  • Corrected typos and syntax issues
  • Added proper type checking for API responses
  • All changes documented with "AJT: 10-Jan-2025:" comments

These changes ensure the integration uses the local code files, handles API response variations, and provides better error reporting and logging.

11-Jan-2026 Summary of Changes - SolarEdge Optimizers Integration

Critical fixes (3)

  1. File descriptor leak — Fixed in _doRequest() by using a context manager for Session() to ensure proper cleanup
  2. Unsafe dictionary access — Replaced direct key access with .get() in SolarEdgeOptimizerData for measurements
  3. Error handling — Added validation and error handling for getLifeTimeEnergy() and requestAllData() to prevent KeyErrors

Medium priority (4)

  1. Resource management — All requests.get() calls now use context managers
  2. Exception logging — Coordinator uses _LOGGER.exception() for full tracebacks
  3. Cleanup — Added coordinator cleanup in async_unload_entry()
  4. Date parsing — Added error handling with fallback for date parsing

Low priority (5)

  1. Float conversion — Added try/except for string-to-float conversion in sensor updates
  2. Code quality — Replaced % formatting with f-strings, improved docstrings, removed commented code, added status check for login response

Files modified

  • init.py — 1 fix (cleanup)
  • coordinator.py — 1 fix (exception logging)
  • config_flow.py — 2 fixes (docstrings, removed commented code)
  • sensor.py — 1 fix (float conversion)
  • solaredgeoptimizers.py — 10 fixes (file descriptor leak, error handling, resource management)

Updated validate_input function to accept translated_title for dynamic title generation. Added translation retrieval for config entry title based on user's language.
Added language support for API locale and updated related methods.
Added localization information and supported languages to the README.
Added link to technical documentation in README.
Added instructions for enabling debug logging and common troubleshooting issues.
Added instructions for editing configuration.yaml directly using various methods.
Updated device names to use placeholders for translation and expanded the list of supported languages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant