Closed nugget closed 9 months ago
For the record, this is the traceback I receive without the patch above:
File "/Users/nugget/src/python-tesla/tesla_powerwall/tesla_powerwall/powerwall.py", line 128, in get_batteries
return [BatteryResponse.from_dict(battery) for battery in batteries]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nugget/src/python-tesla/tesla_powerwall/tesla_powerwall/powerwall.py", line 128, in <listcomp>
return [BatteryResponse.from_dict(battery) for battery in batteries]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nugget/src/python-tesla/tesla_powerwall/tesla_powerwall/responses.py", line 305, in from_dict
grid_state=GridState(src["pinv_grid_state"]),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.11/3.11.7/Frameworks/Python.framework/Versions/3.11/lib/python3.11/enum.py", line 712, in __call__
return cls.__new__(cls, value)
^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.11/3.11.7/Frameworks/Python.framework/Versions/3.11/lib/python3.11/enum.py", line 1135, in __new__
raise ve_exc
ValueError: '' is not a valid GridState
Hey @nugget,
thank you for your bug report!
As home-assistant is using the GridState
s string value in the interface, I think it makes more sense to include a more descriptive value for it and instead rely - as you suggested - on checking disabled_reasons
.
The fix is part of the v0.5.2 release and can be included in home-assistant to fix the bug there.
This is a followup from the Home Assistant core issue 110516
I have 4 Powerwall batteries in my install and one of the batteries is inoperative and disabled. This causes a traceback when attempting to call
power_wall.get_batteries()
(called from Home Assistant's _call_base_info function. The traceback causes my Home Assistant integration to fail to provision correctly and the Powerwall device is not registered in Home Assistant.Here's the raw output for my disabled battery from inside get_batteries in the module.
I can prevent the traceback by adding an empty key to the GridState enum in
const.py
like this:I'm happy to turn this +1 line change into a PR if that's helpful, but I have no opinions on if this is the correct solution or not. It definitely "fixes the glitch" on my end. It might make more sense to probe
disabled_reasons
instead to bypass any attempt to parse the empty valuedpinv_grid_state
as an alternative solution.