FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix P410M energy updates during reverse solar power flow by YouCanCallMeAl · Pull Request #1751 · python-kasa/python-kasa · GitHub

Repository navigation

Fix P410M energy updates during reverse solar power flow - #1751

Open
YouCanCallMeAl wants to merge 1 commit into
python-kasa:masterfrom
YouCanCallMeAl:fix/p410m-solar-energy
Open

YouCanCallMeAl wants to merge 1 commit into
python-kasa:masterfrom
YouCanCallMeAl:fix/p410m-solar-energy

Conversation

Copy link
Copy Markdown

Summary

Fixes P410M energy updates when the plug measures reverse power flow from a solar/microinverter source.

The P410M returns malformed JSON for the legacy get_emeter_data request while reporting negative power. This causes the Smart Energy module update to fail and Home Assistant to mark all energy entities unavailable.

The P410M provides valid signed power through get_energy_usage.current_power, so avoid requesting get_emeter_data for this model.

Changes

  • Skip get_emeter_data for P410M Smart energy-monitoring devices.
  • Continue using get_energy_usage and get_current_power.
  • Add an anonymized P410M(EU) fixture captured during reverse power flow.
  • Add a regression test that verifies P410M does not request the broken legacy endpoint and preserves signed power.

Device tested

  • Model: Tapo P410M(EU)
  • Hardware: 1.0
  • Firmware: 1.4.4 Build 251203 Rel.090729
  • Protocol: SMART / KLAP v2
  • Tested during reverse solar flow; a captured fixture contains current_power = -19231 mW, and the patched CLI reported signed negative power (-21.116 W) without disabling the Energy module.

Tests

  • uv run pytest tests/smart/modules/test_energy.py -q
  • uv run pytest -q
  • Tested live against the P410M during negative solar export.

Fixes #1709

codecov Bot commented Sep 3, 2026 •
edited
Loading

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.29%. Comparing base (a29d061) to head (86a7bb1).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1751   +/-   ##
=======================================
  Coverage   93.29%   93.29%           
=======================================
  Files         157      157           
  Lines        9932     9933    +1     
  Branches     1022     1023    +1     
=======================================
+ Hits         9266     9267    +1     
  Misses        471      471           
  Partials      195      195           

☔ View full report in Codecov by Harness.
📢 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.

rytilahti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for the PR, @YouCanCallMeAl! Please take a look at my comment about hardcoding the model, and please feel free to create a separate PR to add the fixture as that is something we could commit immediately.

Comment on lines +76 to +80
# P410M returns malformed JSON from get_emeter_data while
# reporting reverse/solar-export power. get_energy_usage
# provides signed milliwatt current_power instead.
if self._device.model != "P410M":
req["get_emeter_data"] = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Where does the invalid data break the handling? Instead of hardcoding a model (whose firmware might be updated later on to fix this), I would rather try to catch the error case in a generic way.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

Tapo P410m energy works only on positive values

2 participants


Back | FazBrowse Home | New Git URL