Skip to content

Tasmota: fix currents - #3178

Closed
ndrsnhs wants to merge 3 commits into
openWB:masterfrom
ndrsnhs:tasmota-fix-currents
Closed

ndrsnhs wants to merge 3 commits into
openWB:masterfrom
ndrsnhs:tasmota-fix-currents

Conversation

@ndrsnhs

@ndrsnhs ndrsnhs commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 aims to fix current reporting in the Tasmota device integrations by ensuring the Current value from the Tasmota JSON response is parsed as a float before being stored in component state.

Changes:

  • Cast response['StatusSNS']['ENERGY']['Current'] to float in the Tasmota inverter update loop.
  • Cast response['StatusSNS']['ENERGY']['Current'] to float in the Tasmota battery update loop.

Reviewed changes

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

File Description
packages/modules/devices/tasmota/tasmota/inverter.py Adjusts current parsing in TasmotaInverter.update() for ENERGY responses.
packages/modules/devices/tasmota/tasmota/bat.py Adjusts current parsing in TasmotaBat.update() for ENERGY responses.

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


power = float(response['StatusSNS']['ENERGY']['Power']) * -1
currents[self.__phase-1] = (response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0
currents[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0

Copilot AI Mar 4, 2026

Copy link

Choose a reason for hiding this comment

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

currents[self.__phase-1] = float(...), 0.0, 0.0 assigns a 3-tuple into a single list element, producing a nested tuple inside currents. This will break InverterState's check_currents_power_sign() (it does sum(currents)) with a TypeError. Assign only the scalar current to the selected phase (the list is already initialized with zeros for the other phases).

Suggested change
currents[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0
currents[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Current'])

Copilot uses AI. Check for mistakes.

power = float(response['StatusSNS']['ENERGY']['Power'])
currents[self.__phase-1] = (response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0
currents[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0

Copilot AI Mar 4, 2026

Copy link

Choose a reason for hiding this comment

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

currents[self.__phase-1] = float(...), 0.0, 0.0 assigns a tuple into one entry of the currents list, so BatState ends up with something like [0.0, (I,0,0), 0.0]. Downstream code sums currents to validate the sign, which will raise a TypeError. Assign only the scalar current to the selected phase (the list already contains zeros for other phases).

Suggested change
currents[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0
currents[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Current'])

Copilot uses AI. Check for mistakes.
@ndrsnhs ndrsnhs closed this Mar 5, 2026
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