Skip to content

Add comprehensive error handling to update_energy_sensors#1

Open
nvmassen wants to merge 1 commit intomainfrom
feature/add-error-handling
Open

Add comprehensive error handling to update_energy_sensors#1
nvmassen wants to merge 1 commit intomainfrom
feature/add-error-handling

Conversation

@nvmassen
Copy link
Copy Markdown
Owner

Changes

This PR adds comprehensive error handling to to improve robustness and reliability.

Error Handling Improvements

  • Sensor state validation: Check for , , and states before processing
  • Safe type conversions: Wrap all float conversions in try/except blocks
  • HTTP error handling: Add timeout (10s) and exception handling for gas price scraping
  • Web scraping validation: Validate BeautifulSoup results before accessing
  • Improved logging: Use WARNING and ERROR log levels with specific error messages

Functions Updated

  • ✅ - Validate daily price sensor state
  • ✅ - Validate all 4 tariff sensors with detailed error messages
  • ✅ - Wrap entire monthly rollover logic
  • ✅ - Validate P1 meter sensor state
  • ✅ - Validate electricity delivery sensor
  • ✅ - Add HTTP timeout + request exception handling + parsing validation
  • ✅ - Wrap MQTT telegram parsing
  • ✅ - Add error handling for manual sensor updates

Benefits

  • Prevents crashes when sensors are unavailable
  • Provides clear error messages in logs for debugging
  • Continues operation when individual sensors fail
  • Better resilience during HA restarts or sensor outages

- Add try/except blocks to all major functions
- Validate sensor states before conversion to float
- Handle unavailable/unknown sensor states gracefully
- Add timeout and error handling to HTTP requests (gas price scraping)
- Improve logging with WARNING and ERROR levels
- Validate web scraping results before processing
- Add specific error messages for easier debugging
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.

2 participants