Skip to content

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

@YouCanCallMeAl

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

codecov Bot commented Sep 3, 2026 •

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.

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

1 participant