Stop flooding the logs with stack traces when an energy component is unavailable.
- Ngôn ngữ chính
- Python
- Star
- 780
- Fork
- 127
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
**Is your feature request related to a problem? Please describe.**
I have two Tesla vehicles and Tesla solar panels. All of them are recognized by this integration. I'm currently having work done on the solar panels, so they are shut off. This has caused the integration to flood the logs with stack traces every several seconds. The vehicles are still updating their data correctly.
The stack trace looks like:
```
2026-05-18 11:43:17.495 ERROR (MainThread) [custom_components.tesla_custom] Unexpected error updating listener 547204593984 for tesla_custom
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 203, in async_update_listeners
update_callback()
~~~~~~~~~~~~~~~^^
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 662, in _handle_coordinator_update
self.async_write_ha_state()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1054, in async_write_ha_state
self._async_write_ha_state()
~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1203, in _async_write_ha_state
) = self.__async_calculate_state()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1110, in __async_calculate_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1060, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 588, in state
value = self.native_value
^^^^^^^^^^^^^^^^^
File "/config/custom_components/tesla_custom/sensor.py", line 396, in native_value
return round(self._energysite.solar_power)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/site-packages/teslajsonpy/energy.py", line 106, in solar_power
return self._site_data.get("solar_power")
^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'
```
There are some open and closed issues (1152, 494) which mention this "AttributeError: 'str' object has no attribute 'get'" error, and workarounds have been made to have various energy devices properly report "unavailable" or whatnot, but I believe the underlying issue is that `self._energysite` is sometimes a string and not a dictionary, and sensor.py or energy.py is not checking for that case.
**Describe the solution you'd like**
Have energy.py or something upstream in the call stack test for when the expected-to-be-a-dictionary data is a string, and submit a _single_ warning to the logs about the query about that energy device failing (and maybe include the string that was returned instead of a dictionary)
**Describe alternatives you've considered**
When trying to track logs for particular things, it's possible to use the keyword filtering at the top of the logs, but this doesn't seem to work for scrolling backward (i.e. if you try to scroll back through the logs, getting to the top of the list with an _empty_ filter will cause older logs to be retrieved, but having something in the filter seems to prevent loading of earlier logs).
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.