zabuldon / teslajsonpy

Apache License 2.0
57 stars 62 forks source link

fix: missing defaults in energysite #417

Closed bdraco closed 1 year ago

bdraco commented 1 year ago

These were implemented as .get() but there was no default so it would fail anyways

fixes


2023-07-24 12:56:40.749 ERROR (MainThread) [homeassistant.components.number] Error while setting up tesla_custom platform for number
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 370, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 510, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 670, in _async_add_entity
    original_icon=entity.icon,
                  ^^^^^^^^^^^
  File "/config/custom_components/tesla_custom/number.py", line 142, in icon
    return icon_for_battery_level(battery_level=self.native_value)
                                                ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tesla_custom/number.py", line 122, in native_value
    return self._energysite.backup_reserve_percent
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/teslajsonpy/energy.py", line 137, in backup_reserve_percent
    return self._battery_data.get("backup").get("backup_reserve_percent")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: NoneType object has no attribute get```