Skip to content

fix: promote connection diagnostics from debug to error/warning level#307

Merged
jasonacox merged 3 commits into
jasonacox:mainfrom
jasonacox-sam:fix/improve-connection-diagnostics
May 26, 2026
Merged

fix: promote connection diagnostics from debug to error/warning level#307
jasonacox merged 3 commits into
jasonacox:mainfrom
jasonacox-sam:fix/improve-connection-diagnostics

Conversation

@jasonacox-sam
Copy link
Copy Markdown
Collaborator

Summary

Fixes #160 — pypowerwall silently fails when it can't connect to the gateway, providing no diagnostic information at default logging levels.

Problem

When the Powerwall gateway becomes unreachable (network issue, password change, firmware reset), users see only generic errors like:

[pypowerwall] [ERROR] Failed to get /api/system_status/grid_status

This gives no indication of why the connection is failing — is it a network issue? Wrong password? Token expired? Gateway powered off?

All the meaningful diagnostic messages were logged at DEBUG level, invisible to users running at the default ERROR level.

Changes

pypowerwall/local/pypowerwall_local.py:

  • poll(): Timeout, ConnectionError, and unexpected exceptions now log at error level with actionable messages
    • Timeout → "Timeout waiting for Powerwall API /api/... - check network connectivity to <host>"
    • ConnectionError → "Unable to connect to Powerwall at <host> - check that the gateway is reachable and powered on"
    • Unexpected → "Unexpected error connecting to Powerwall at <url>: <exception>"
  • _get_session(): Connection and login failures now log at error/warning level
    • Connection failure → "Unable to connect to Powerwall at https://<host>: <exc> - check that the gateway is reachable on the network"
    • Login failure → "Invalid Powerwall Login - check password for <host>"

pypowerwall/__init__.py:

  • connect(): Mode fallback messages promoted from debug to warning level
  • Init error message now includes actionable guidance: "Verify host, credentials, and network connectivity. Enable debug logging for detailed diagnostics."

Before (default logging)

[ERROR] Unable to connect to Powerwall.
[ERROR] Failed to get /api/system_status/grid_status
[ERROR] Failed to get /api/system_status/grid_status
[ERROR] Failed to get /api/system_status/grid_status

After (default logging)

[WARNING] Failed to connect using Local mode: [errno 111] Connection refused - trying fleetapi mode.
[ERROR] Unable to connect to Powerwall. Verify host, credentials, and network connectivity. Enable debug logging for detailed diagnostics.
[ERROR] Unable to connect to Powerwall at 192.168.1.1 - check that the gateway is reachable and powered on
[ERROR] Timeout waiting for Powerwall API /api/system_status/grid_status - check network connectivity to 192.168.1.1

Testing

  • No functional changes — only log level and message text changes
  • All existing behavior preserved (returns None on errors, same retry logic, same caching)

— Sam 🌊

Users running at default ERROR logging never saw why connections failed.
Connection errors, timeouts, and login failures were all logged at debug
level, making it impossible to diagnose issues without enabling debug mode.

Changes:
- poll(): Timeout, ConnectionError, and unexpected exceptions now log at
  error level with actionable messages (check network, check gateway)
- _get_session(): Connection and login failures now log at error/warning
  level with specific guidance (check network, check password)
- connect(): Mode fallback messages promoted from debug to warning level
- Main init: More descriptive error message with debugging guidance

Fixes jasonacox#160
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 25, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 35.71429% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.40%. Comparing base (1d1ec9c) to head (42cb214).

Files with missing lines Patch % Lines
pypowerwall/local/pypowerwall_local.py 22.22% 7 Missing ⚠️
pypowerwall/__init__.py 60.00% 2 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #307      +/-   ##
==========================================
- Coverage   26.40%   26.40%   -0.01%     
==========================================
  Files          42       42              
  Lines        7660     7662       +2     
  Branches     1101     1102       +1     
==========================================
  Hits         2023     2023              
- Misses       5493     5495       +2     
  Partials      144      144              
Flag Coverage Δ
py3.10 26.40% <35.71%> (-0.01%) ⬇️
py3.11 26.40% <35.71%> (-0.01%) ⬇️
py3.12 26.40% <35.71%> (-0.01%) ⬇️
py3.13 26.40% <35.71%> (-0.01%) ⬇️
py3.9 26.39% <35.71%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves default logging for connection failures so users get actionable diagnostics when the Powerwall gateway (or Tesla APIs) can’t be reached, addressing issue #160 where meaningful details were only visible at DEBUG level.

Changes:

  • Promotes several local-mode connection diagnostics in poll() and _get_session() from DEBUG to ERROR/WARNING.
  • Enhances the top-level “unable to connect” message with guidance, and promotes mode-fallback messages in connect() from DEBUG to WARNING.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pypowerwall/local/pypowerwall_local.py Raises visibility of login/connection failures during session creation and polling by logging at warning/error with more actionable text.
pypowerwall/__init__.py Improves user-facing connection failure guidance and makes mode fallback attempts visible at warning level.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pypowerwall/local/pypowerwall_local.py Outdated
Comment on lines +116 to +118
except Exception as e:
log.debug(f'login failed: {e}')
raise LoginError("Invalid Powerwall Login")
log.warning(f'Login failed: {e}')
raise LoginError(f"Invalid Powerwall Login - check password for {self.host}")
Comment thread pypowerwall/local/pypowerwall_local.py Outdated
Comment on lines 167 to 169
except requests.exceptions.ConnectionError:
log.debug('ERROR Unable to connect to Powerwall at %s' % url)
log.error('Unable to connect to Powerwall at %s - check that the gateway is reachable and powered on' % self.host)
return None
@jasonacox
Copy link
Copy Markdown
Owner

@jasonacox-sam This looks good. Address the Copilot reviews and let's start testing.

@jasonacox-sam
Copy link
Copy Markdown
Collaborator Author

@jasonacox Copilot feedback addressed in 83cfcf5:

  1. Login error differentiation_get_session() now checks r.status_code before raising LoginError. 401/403 → "check password" hint; other codes → "check gateway reachability" hint (covers captive portals, firmware changes, malformed responses).

  2. ConnectionError detailspoll() now captures the exception as exc and includes it in the log message, so users can distinguish DNS failure vs connection refused vs reset.

Ready for testing.


— Sam ⚡ (pypowerwall agent)

@jasonacox
Copy link
Copy Markdown
Owner

@jasonacox-sam This looks good.

Increment the version number and create a new entry in RELEASE.md for the new version and examine the changes from last tag v0.15.8 to include, in prep for new release.

@jasonacox-sam
Copy link
Copy Markdown
Collaborator Author

Version bumped to 0.15.9 and RELEASE.md updated with full changelog for this release.

Summary of changes since v0.15.8:

Ready for merge when you approve.

@jasonacox jasonacox merged commit c28f4d5 into jasonacox:main May 26, 2026
16 checks passed
@jasonacox
Copy link
Copy Markdown
Owner

jasonacox commented May 26, 2026

View at:
https://pypi.org/project/pypowerwall/0.15.9/

jasonacox/pypowerwall:0.15.9t89

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.

pypowerwall doesn't give error if it can't connect

4 participants