Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't assume climate_state exists #404

Merged
merged 3 commits into from
Apr 25, 2023

Conversation

Megabytemb
Copy link
Contributor

Home Assistant sometimes throws the following error on startup

Traceback (most recent call last):
  File "/config/custom_components/tesla_custom/teslamate.py", line 208, in msg_recieved
    ).result()
  File "/usr/local/python/lib/python3.10/concurrent/futures/_base.py", line 446, in result
    return self.__get_result()
  File "/usr/local/python/lib/python3.10/concurrent/futures/_base.py", line 391, in __get_result
    raise self._exception
  File "/config/custom_components/tesla_custom/teslamate.py", line 237, in async_handle_new_data
    coordinator.async_update_listeners()
  File "/usr/local/python/lib/python3.10/site-packages/homeassistant/helpers/update_coordinator.py", line 135, in async_update_listeners
    update_callback()
  File "/config/custom_components/tesla_custom/base.py", line 40, in refresh
    self.async_write_ha_state()
  File "/usr/local/python/lib/python3.10/site-packages/homeassistant/helpers/entity.py", line 559, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/local/python/lib/python3.10/site-packages/homeassistant/helpers/entity.py", line 600, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/local/python/lib/python3.10/site-packages/homeassistant/helpers/entity.py", line 565, in _stringify_state
    if (state := self.state) is None:
  File "/usr/local/python/lib/python3.10/site-packages/homeassistant/components/select/__init__.py", line 147, in state
    if self.current_option is None or self.current_option not in self.options:
  File "/config/custom_components/tesla_custom/select.py", line 156, in current_option
    current_value = self._car.get_seat_heater_status(
  File "/usr/local/python/lib/python3.10/site-packages/teslajsonpy/car.py", line 879, in get_seat_heater_status
    return self._vehicle_data.get("climate_state").get(seat_id)
AttributeError: 'NoneType' object has no attribute 'get'

This is because get_seat_heater_status doesn't return an empty dict if climate_state doesn't exist.

This fixes that error. All other calls in car.py return an empty dict instead of None

@alandtse
Copy link
Collaborator

Thanks. Can we add a test to avoid a regression?

@Megabytemb
Copy link
Contributor Author

Done

@alandtse
Copy link
Collaborator

Thanks. I meant testing for the exception when climate state is None. Just do we don't accidentally revert this fix somehow.

@Megabytemb
Copy link
Contributor Author

incoming :)

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