Conversation
There was a problem hiding this comment.
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']tofloatin the Tasmota inverter update loop. - Cast
response['StatusSNS']['ENERGY']['Current']tofloatin 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 |
There was a problem hiding this comment.
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).
| currents[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0 | |
| currents[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Current']) |
|
|
||
| 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 |
There was a problem hiding this comment.
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).
| currents[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0 | |
| currents[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Current']) |
No description provided.