mandarons/ha-bouncie

[BUG] milOn KeyError

jeffml42 opened this issue · 1 comments

Logger: homeassistant
Source: custom_components/bouncie/sensor.py:117
integration: Bouncie ([documentation](https://github.com/mandarons/ha-bouncie), [issues](https://github.com/mandarons/ha-bouncie/issues))
First occurred: 5:28:20 PM (40 occurrences)
Last logged: 5:34:50 PM
Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 261, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 417, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 183, in async_update_listeners
    update_callback()
  File "/config/custom_components/bouncie/sensor.py", line 185, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 992, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1113, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1050, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 548, in state
    value = self.native_value
            ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/bouncie/sensor.py", line 191, in native_value
    return self.entity_description.value_fn(self._vehicle_info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/bouncie/sensor.py", line 117, in <lambda>
    value_fn=lambda vehicle_info: vehicle_info["stats"]["mil"]["milOn"],
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'milOn'

It looks like milOn is missing from server response. Per API, mil object is marked as required meaning server must return it as a response. But in your case, it is not returning.

You will need to contact Bouncie support to fix this problem on their end.